DEV Community

Cover image for Infrastructure from code.
Rak
Rak

Posted on • Edited on

1 1 1 1

Infrastructure from code.

How much infrastructure can you infer from your code?

The answer is everything required to run it in the cloud. Anything more would likely be insecure and/or costly!

Let's take a look at the code example in the heading, included below for readability.

import { api, bucket } from "@nitric/sdk";

const photoApi = api('photos'); // API
const photos = bucket('myPhotos').for('reading'); // BUCKET

// API Method + Handler Function
photoApi.get("/photo/:path", async (ctx) => { 
  const { path } = ctx.req.params;
  ctx.res.body = await photos.file(path).getDownloadUrl();
});
Enter fullscreen mode Exit fullscreen mode

From a quick glance, we can infer that this code snippet requires an API Gateway, a Bucket (with only write access), and a Service Handler that will be invoked via the gateway as a get method on the "/photo/" path.

This approach introduces a fresh perspective on infrastructure provisioning. The Nitric framework leverages your code to automatically infer the required infrastructure, create a specification, and implement concrete infrastructure that fulfills the specification using popular Infrastructure as Code (IaC) tools like Terraform or Pulumi.

Visit Nitric.io to explore the Nitric framework and experience firsthand how to seamlessly transform your code into a provisioned and secure infrastructure.

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay