DEV Community

Cover image for Infrastructure from code.
Rak
Rak

Posted on • Updated on

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)