Photo by Émile Perron on Unsplash

Member-only story

All AWS Serverless developers should know (Fn::Transform + AWS::Include)

George Mao

--

Developers often ask “What’s the best way to define and deploy APIs to API Gateway?

For the most part, API developers should use Swagger or OpenAPI. These are popular specifications that describe how an API should be deployed. If you’re automating these deployments, chances are you are using SAM or CloudFormation to deploy these API definitions.

Swagger and OpenAPI specs are static. So how do you instruct your CloudFormation script (or SAM) to import a static file AND allow dynamic values to pass into your Swagger/OpenAPI specs to resolve at runtime?

For example you probably want a dynamic value for the AWS Region, AWS account number, or pass a logical ID from the CloudFormation template into the API spec.

Fn::Transform + AWS::Include to the rescue!

Let’s say you created a Lambda function using SAM. The logical name you choose is ${LambdaFunction}. CloudFormation will create the function with a name in this format: [StackName]-[$LambdaFunction]-[some unique id]. You need to pass this dynamically generated value into your API spec so you can build a Lambda integration for your backend.

--

--

No responses yet