DEV Community

Rak
Rak

Posted on

Using abstraction to eliminate the burden of config and infrastructure

Pulumi and Terraform are incredibly powerful, but does anyone else sometimes feel exhausted by the amount of time you still spend writing infrastructure? In situations where you don't need or want as much control over your environment, abstraction can help you move fast and not worry about config or infrastructure.

Here's a simple example to show how easy it is to write serverless applications with the Nitric framework's abstraction layer.
Coupled with a powerful interpretation layer this code utilizes an abstraction layer to self-describe the infrastructure, resources, and policies required to create a scheduled service that periodically deletes all files in a bucket.

import { schedule } from '@nitric/sdk';
import { bucket } from '@nitric/sdk';

// A schedule that cleans up files in a bucket every 3 days
const reportSchedule = schedule('cleaning-day').every(
  '3 days',
  async (ctx) => {
    const assets = bucket('assets').for('deleting');
    const files = await assets.files();
    await Promise.all(files.forEach(async (file) => 
        await file.delete()
    ));
  }
);
Enter fullscreen mode Exit fullscreen mode

That's all you'd need to write. And automatically, all of the following resources are provisioned from the same code base with zero-config (almost … we need a few lines of config to tell the Nitric CLI where to deploy).

Let me illustrate what this means for whichever cloud you choose.

AWS

Type Resource Name
nitric:schedule:AwsSchedule cleaning-day
nitric:Image tidy
nitric:func:AWSLambda tidy
docker:image:Image tidy-image
aws:cloudwatch:EventRule cleaning-daySchedule
aws:ecr:Repository tidy-tidy
aws:resourcegroups:Group tidy-aws
aws:sns:Topic cleaning-day
aws:iam:Role tidyLambdaRole
aws:sns:TopicPolicy cleaning-dayTarget{0xc0004c16c0}Policy
aws:cloudwatch:EventTarget cleaning-dayTarget
aws:iam:RolePolicy tidyListAccess
aws:iam:RolePolicyAttachment tidyLambdaBasicExecution
aws:lambda:Function tidy
aws:lambda:Permission tidycleaning-dayPermission
aws:sns:TopicSubscription tidycleaning-daySubscription

GCP

Type Resource Name
nitric:project:GcpProject project
random:index:RandomString gcp-base-role
gcp:serviceAccount:Account tidy-acct
gcp:projects:IAMCustomRole base-role
gcp:projects:Service run.googleapis.com-enabled
gcp:projects:Service storage.googleapis.com-enabled
gcp:projects:Service cloudscheduler.googleapis.com-enabled
gcp:projects:Service iam.googleapis.com-enabled
gcp:projects:Service firestore.googleapis.com-enabled
gcp:projects:Service compute.googleapis.com-enabled
gcp:projects:Service pubsub.googleapis.com-enabled
gcp:projects:Service apigateway.googleapis.com-enabled
gcp:projects:Service containerregistry.googleapis.com-enabled
gcp:projects:IAMMember pubsub-token-creator
gcp:projects:IAMMember tidy-project-member
nitric:func:GCPCloudRunner tidy
nitric:Image tidyImage
docker:image:Image tidyImage-image
gcp:serviceAccount:Account tidysubacct
gcp:pubsub:Topic cleaning-day
gcp:cloudscheduler:Job cleaning-day
gcp:cloudrun:Service tidy
gcp:pubsub:Subscription tidy-cleaning-day-sub
gcp:cloudrun:IamMember tidy-subrole

Azure

Type Resource Name
nitric:func:ContainerApps containerApps
nitric:api:AzureApiManagement subscriptions
nitric:func:ContainerApp tidy
nitric:Image tidyImage
nitric:principal:AzureAD tidy
docker:image:Image tidyImage-image

Curious to hear what you think of this use of abstraction. Check out more about how it works here.

Top comments (0)