Integrating with the Serverless FrameworkΒ»
In order to use the Serverless Framework in an AWS CloudFormation Stack you'll need to do a few things: create a Docker image with the Serverless Framework included, invoke the serverless CLI in before_init
hook, sync your artifacts with Amazon S3, and make sure the serverless config has your template bucket configured as the artifact location.
The first one can be done using a Dockerfile akin to this one:
1 2 3 4 5 6 7 |
|
You should build it, push it to a repository and set it as the Runner Image of your Stack.
You'll also have to invoke the serverless CLI in order to generate raw CloudFormation files. You can do this by adding the following to your before initialization hooks:
serverless package --region ${CF_METADATA_REGION}
You can add the following script as a mounted file:
1 2 3 4 5 6 7 8 9 10 |
|
and invoke it in your before initialization hooks: sh sync.sh
Finally, specify the S3 bucket for artifacts in your serverless.yml configuration file:
1 2 |
|
When creating the CloudFormation Stack, make sure that you set the entry template file to .serverless/cloudformation-template-update-stack.json
, which is the file generated by the serverless package
command.