Database Prerequisite

To deploy to AWS Lambda, you’ll need to create a database that AWS Lambda can access. I suggest creating an RDS database for testing. Creating a database is outside of the scope of this guide, but here are some links that can help:

Once you have an RDS database, let’s review the jets/config/env/.env. There’s a comment about how how SSM Parameters can be conventional loaded. The DATABASE_URL and SECRET_KEY_BASE ones are of interest.

jets/config/env/.env

# DATABASE_URL=SSM # => SSM:/rails/dev/DATABASE_URL

The SSM value conventionally maps to SSM:/rails/dev/DATABASE_URL for JETS_ENV=dev

To create a SSM parameter with the aws cli.

aws ssm put-parameter --name /rails/dev/DATABASE_URL --type SecureString --value "mysql2://user:pass@db.endpoint.us-west-2.rds.amazonaws.com/rails_dev?pool=5"

If you want to confirm that correct value

aws ssm get-parameters --names /rails/dev/DATABASE_URL --with-decryption | jq -r '.Parameters[].Value'

You can also create the parameter with the AWS console if you prefer. Here’s a useful SSM Cheatsheet.

Jets Dotenv

Tip: You can also use jets dotenv commands to set SSM values. Jets Dotenv supports SSM.

jets dotenv:set DATABASE_URL="mysql2://user:pass@db.endpoint.us-west-2.rds.amazonaws.com/rails?pool=5"
jets dotenv:set SECRET_KEY_BASE=$(rails secret)
jets dotenv:list --reveal

It will properly prefix the SSM Parameter names with /rails/dev/.

Seeding Data

You’ll need to also create the database and seed the RDS database with data. You can point the DATABASE_URL to the RDS db and run:

rails db:create db:migrate db:seed

Next, we’ll deploy to AWS Lambda.