Recently, I’ve been excited by serverless technology. I began using the serverless framework for code boilerplate and deployment. After some time using the framework, I began feeling pain. Serverless is an excellent project, but it’s moving very fast. For example, The framework uses cloudformation for resource dependencies such as dynamoDb, ApiGateway, roles and permissions (to name a few). Cloudformation is also moving very fast. Support for ApiGateway was added to cloudformation on April 18th, 2016. As new features are added to cloudformation, you’ll be stuck waiting for serverless to implement features for feature parity. I’ve started using cloudformation direclty and relying on bash scripts for deployment. I’m quite happy with the results.
Once we have a cloudformation template, the AWS cli provides us with everthing we need. Using the AWS CLI we can create the stack like so.
1 2 3 4 5 6
The first command fires off an async create request to AWS. The second command tells our shell to wait for stack creation to complete.
After that’s complete, we’ll have created a few resources in AWS. =) Next, we’ll need a way to deploy.
We have a few tasks for a complete deployment. We should seperate out the lambda depoyment and the ApiGateway deployment, but in this case I did not.
- Update Lambda Code - Install any dependencies, zip our code, and upload it.
- Publish a Version - From the latest version, It will tag a copy.
- Update the alias - Our lambda is pointed to an alias. This will point the lambda to our new version.
- deploy ApiGateway - Any changes we make to ApiGateway requires a deploy.
The script takes two args. The
api-gateway-id and the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49