Deploy utility for AWS Serverless Application Model (AWS-SAM) based projects that significantly speeds up time to deploy updates when the only change is the code of Lambda function and the rest of the stack is the same.
It builds upon
aws cloudformation package but will figure out if simply updating code of Lambda functions or updating stack parameters is enough or whether a full
aws cloudformation deploy is required.
I prefer running my development work directly on AWS; you don't need to attempt to replicate all those AWS services locally, dev runs on exactly the same constraint as prod will, and switching between different computers is a breeze (I can even code from my iPad Pro while on the go!). That being said, while I love how AWS-SAM extends some aspects of CloudFormation, pushing tiny changes to a Lambda function with the recommended aws cli commands still needs to go through the whole change set routine is often waaaay too slow.
That's why I built sampic: make deploying updates to my dev environment as fast as possible and eventually get some sort of continuous deployment system that is fast enough to be used for dev environments, not just for staging and production.
The name sampic actually refers to scratching your own itch. In French, it reads as ça me pique which means I have an itch.
Install this package globally.
npm install -g sampic
Generate a sample config file for your current git working branch:
cd <project_directory>sampic init
Make sure you have AWS CLI (version >= 1.11) and git installed and available in the shell environment when running sampic.
Make sure your current working branch is the branch to deploy and simply run the
sampic command from your project base directory. Note that changes saved but not yet committed will be bundled in the deployment.
sampic [<options>] [<command>] [<command-options>]
The utility supports the following set of commands:
||Packages your CloudFormation template using the
Manage npm dependencies
||Lists outdated npm packages for all NodeJS Lambda functions found in your CloudFormation template.|
||Lists all commands with available options.|
||Prints out config option as defined in
||Creates a sample
What happens when you run
Sampic goes through the following steps:
- Get current git branch and look for corresponding settings in
- Fetch the currently deployed template for the CloudFormation stack specified in your config
- Package your template by running
aws cloudformation package. The output template file is saved as
- If the stack doesn't currently exist on CloudFormation, deploy the packaged template to create it. Otherwise, compare the new packaged template and the current stack template to find differences:
- If the only differences are code updates for Lambda functions, simply update function code of those Lambdas.
- If the packaged template is identical to the deployed stack template but stack parameters in your config have changed, run
aws cloudformation update-stackon the current template with the new stack parameter values.
- If there are more changes, run
aws cloudformation deployto do a full stack update through change sets.
- If all updates requests sent to AWS succeed, rename
.sampic/<STACK_NAME>-deployed-template.yamland we're done.
.sampic directory at the base of your project and add a
config.json file under it. CloudFormation templates packaged by the
aws cloudformation package will also go under this directory. It is a good idea to add it to your
The configuration file declares deployment parameters for git branches you want to deploy. For example, the config file defines deployment instructions when your working branch is
profile(optional) refers to a named profile under
~/.aws/credentials. No need to define this if you'll use the default AWS profile
regionis the AWS region your CloudFormation stack is deployed in
templateis your SAM template file
stackNameis the name of the CloudFormation stack this branch should be deployed to
stackParameters(optional) passed as template parameters when deploying the template to CloudFormation
s3Bucketis the bucket where artifacts (lambda function code, external swagger files, ...) are uploaded to
capabilitiesis used when running to the
aws cloudformation deploycommand. See AWS docs for more but usually, deploying SAM templates need at least
CAPABILITY_IAMlisted in there.
Application with multiple templates/stacks
If your application has more than one template deployed to different stacks, sampic supports that but the configuration is a bit different.
Once you're config is set up with a
<branch>.stacks option, commands parsing your CloudFormation template will list stack names and ask you which template you want to work with:
$ sampic deploy Using config for current git branch: master Which stack? (1) stackA-template.yaml => stack-A (2) stackB-template.yaml => stack-B Specify stack number:
Alternatively, you can use the stack key (
<branch>.stacks.<key>) from CLI to skip the prompt:
$ sampic deploy --stack myStackA