How do I import an AWS CloudFormation stack with AWS SAM in Pulumi?
This example demonstrates how to import existing AWS CloudFormation stacks that use AWS SAM into a Pulumi program. You will learn how to define the appropriate resources and configure their import properties.
First, we’ll create an aws.s3.Bucket
to store the deployment artifacts. Then, we’ll define an aws.cloudformation.Stack
resource to specify the stack we want to import.
Here’s the code:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an S3 bucket for deployment artifacts
const samArtifacts = new aws.s3.BucketV2("sam_artifacts", {
bucket: "sam-artifacts-bucket",
acl: "private",
tags: {
Name: "sam-artifacts-bucket",
Environment: "dev",
},
});
// Import existing CloudFormation stack with AWS SAM
const mySamStack = new aws.cloudformation.Stack("my_sam_stack", {
name: "my-sam-stack",
templateUrl: "https://<s3-bucket>/my-sam-app.yaml",
capabilities: ["CAPABILITY_IAM"],
tags: {
Environment: "dev",
},
});
export const bucketName = samArtifacts.bucket;
export const stackId = mySamStack.id;
Key Points:
- Provider Configuration: Configures the AWS provider with the region.
- S3 Bucket Resource: Creates an S3 bucket to store SAM deployment artifacts.
- CloudFormation Stack Resource: Imports an existing CloudFormation stack that uses AWS SAM using the template stored in S3.
- Outputs: Exports the bucket name and stack ID for easy reference.
Summary:
In this example, we imported an AWS CloudFormation stack that uses AWS SAM by creating an appropriate S3 bucket for the SAM artifacts and defining the necessary CloudFormation stack resource in Pulumi. This setup helps manage and deploy AWS SAM applications with Pulumi seamlessly.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.