Bin Scripts (Build & Deploy)

Our Quick Start cookiecutter includes a single bin/deploy script that wraps three SAM commands needed to deploy your application.

Think of our provided bin scripts as starting points! You should add to or adjust each to meet your needs. Well maintained deploy scripts are critical to good CI/CD practices no matter if they are used from your personal machine or automated via GitHub Actions. From a Lamby perspective, here are a few helpful topics about our deploy process.

Overview of Deploy Process

Remember, our Docker usage plays a major role here. Especially with shared git/aws credentials & environment variables.

Using Private Gems on GitHub

Even though we do share your git/ssh setup with the Docker container, you may have auth issues accessing them. This may be more so true on CI/CD systems. One solution we like helps with GitHub Actions. Other options include switching out your Gemfile and process to use HTTPS with token.

bundle config --local GITHUB__COM "$(git config github.token):x-oauth-basic"

It sets a Bundler config to use your personal GitHub OAuth token. Make sure to set that up using this GitHub help article. Lastly, make sure your Gemfile uses this git source format. Most newer Rails apps do this already.

git_source(:github) { |repo| "{repo}.git" }

ECR Repository & CloudFormation Bucket

The default package type is to use a container image and deploy that image to Amazon Elastic Container Registry. During the cookiecutter's bootstrap process we create a placeholder ECR repository for you. Please customize this as needed.

The S3 bucket is only needed for the ZIP deployment package. However, there might be a bug in AWS SAM that requires it to be there.

If the deployment package type is ZIP, your code needs to be packaged and uploaded to an S3 bucket prior to being deployed. We dynamically create a bucket name during the cookiecutter bootstrap script. This bucket name is saved in a .bucket-name file in your project. It is a great idea for you to change this to something that makes sense for you! If you have the AWS CLI installed, creating a bucket is a simple command like so.

$ aws s3 mb

Multiple Environments

Feel free to make more per-environment deploy scripts. For example bin/deploy-staging may look like this. The AWS_PROFILE is an useful environment variable that helps you manage different AWS accounts via all CLI tools. We pass AWS_PROFILE and RAILS_ENV via our docker compose scripts. Learn more about AWS Environment Variables.

set -e
export AWS_PROFILE="staging"
export RAILS_ENV="staging"