AWS CodeStar and Cloud Formation Parameterization

I’m in the process of getting familiar with AWS and Serverless architecture and thought I’ll share some basics with you.

I have created a sample project using AWS CodeStar that utilizes Python and AWS Lambda. When analyzing the buildpsec.yml and template.yml I found that in template.yml you don’t have any CodeUri location that would point to the artifact used by Lambda. At the same time in buildspec.yml you can find following command:

- aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template template-export.yml

Ah, so it looks like we’re using Cloud Formation package option which (in the above form) will wrap whole current directory, create a ZIP and upload it to S3 bucket named $S3_BUCKET. It will then save the name of the S3 resource it just uploaded and use it as CodeUri in generated template-export.yml.

It’s pretty neat functionality. If you’d wonder where does this $S3_BUCKET comes from, I’ll save you some time. It’s coming from the CloudFormation template:

CloudFormation - S3 variable mapping

It is then referring a resource configured in the same template where its name is being constructed as depicted below:

CloudFormation - S3 variable mapping

I find CodeStar a great way to immediately start with your development. It preconfigures all steps of a build for you, i.e. CodeCommit, CodeBuild, CodePipeline, CloudFormation, Lambdas, IAM roles, CloudWatch, S3 Bucket. You can just jump in and give it a spin without time consuming resource configuration.