DEV Community

Cover image for Pulumi and AWS SAM - How to convert Cloud Formation IAC to Pulumi
Fernando Silva
Fernando Silva

Posted on

Pulumi and AWS SAM - How to convert Cloud Formation IAC to Pulumi

SAM stands for AWS Serverless Application Model. It's a framework for building serverless applications on AWS.

IAC is a way to manage and provision infrastructure using code.

Pulumi is a multi-cloud development platform for provisioning infrastructure as code (IAC).

While SAM is specific to AWS and its services, Pulumi supports multiple cloud providers (AWS, Azure, Google Cloud and more). When used together, these tools can provide a number of advantages for developing, deploying, and maintaining serverless applications.

SAM and Pulumi can be beneficial for organizations that want to use a common toolset across different teams and projects. In this post I'll show some key points of this combination.

One of the main advantages of combining SAM and Pulumi is that it allows for better collaboration between development and operations teams. SAM uses a familiar and simplified syntax to define serverless resources, making it simple for developers to manage and deploy their code, whilst Pulumi uses a common language and framework to allow developers and operations teams to collaborate.

Another advantage of using SAM and Pulumi together is the ability to easily manage both serverless and non-serverless resources with a single toolset.

SAM generated IAC is specifically designed for serverless applications and provides a simplified way to define and deploy serverless resources, such as Lambda functions, API Gateway endpoints, and DynamoDB tables. However, it does not cover all the possible resources and scenarios that can be defined on AWS.

Pulumi can be used to manage the non-serverless resources required by your application, such as an S3 bucket, RDS instance, or even a k8s cluster. This can be beneficial for applications that have a complex infrastructure and need to manage resources across different cloud providers.

Furthermore, using Pulumi with SAM allows for better reusability and composition of the code. Pulumi supports code reuse and composition through Pulumi Components, which are building blocks of reusable code that can be shared across different teams and projects. This can save time and effort by reducing the need to write and maintain similar code in multiple projects.

It's also worth mentioning that the AWS SAM templates code generated can be converted to Pulumi using open-source libraries maintained by the Pulumi Authors, which allow to take an existing CloudFormation template and convert it to be used to manage both resources.

This saves a significant amount of time and effort by eliminating the need to manually convert CloudFormation syntax to the appropriate language syntax. You can convert Cloud Formation IAC code directly from Pulumi website clicking here or using this official library.

In conclusion, using AWS SAM and Pulumi together can provide a number of advantages for developing, deploying, and maintaining serverless applications on AWS. These include the ability to easily manage both serverless and non-serverless resources, better collaboration between developers and operations teams, and better reusability and composition of the code. And with the open-source libraries that are available for converting SAM templates to Pulumi, it makes the process even more streamlined.

Give it a try!

References:

AWS Serverless Application Model (SAM):
https://aws.amazon.com/serverless/sam/

AWS CloudFormation - https:
https://aws.amazon.com/cloudformation/

Pulumi vs Cloud Formation:
https://www.pulumi.com/docs/intro/vs/cloud-templates/cloudformation/

Migrating From AWS Cloud Formation:
https://www.pulumi.com/docs/guides/adopting/from_aws/#migrate-resources-into-code

Comparison of AWS CloudFormation and AWS SAM:
https://aws.amazon.com/serverless/sam/comparison/

Converting Cloud Formation to Pulumi:
https://www.pulumi.com/cf2pulumi/
https://github.com/pulumi/pulumi-aws-native

㋡ Happy Coding []s

Top comments (0)