Jets Env Deploy

When you run jets deploy, Jets packages up your code and uploads it to s3 for deployment.

Gitignore Files

Jets uses git archive to create the code.zip. This is nice because keeps the zip small and it also respects .gitignore rules. Typically .env files are gitignored. So, the deployed Lambda Function will not have these env vars.

jets/config/env

If you want to use env files for the Lambda Function, you can use config/jets/env files. Example:

config/jets/env/.env

Jets Dotenv support adds additional features like referencing SSM Parameters. Example:

config/jets/env/.env

DATABASE_URL=SSM:/demo/dev/DATABASE_URL

This allows you to safely commit config/jets/env files to version control.

Convention Path Loading

For the most part, you do not need config/jets/env files to explicitly declare the values. Jets can conventionally load env vars by conventional SSM path, IE: /demo/dev or /demo/prod. Here’s an example.

❯ aws ssm describe-parameters | jq -r '.Parameters[].Name' | grep '/demo/dev/' | sort
/demo/dev/DATABASE_URL
/demo/dev/SECRET_KEY_BASE

Since the DATABASE_URL and SECRET_KEY_BASE parameters are underneath the /demo/dev/ SSM Parameter path, they will be load automatically. Here’s what the file would look like

config/jets/env/.env

DATABASE_URL=SSM
SECRET_KEY_BASE=SSM

Thanks to conventions, .env file above is optional. You only need a .env file if you have non-conventional parameters paths. To see what SSM values config/jets/env files will resolve to you can use.

> jets dotenv:list
DATABASE_URL=mysql2://user:pass@host.com/dbname?pool=5

If you want to learn more about the SSM conventions including how to control the behavior see: Jets Dotenv SSM Conventions.

always_keep config

When jets deploy runs, the config/jets/env files are always copied to the code.zip. This is thanks to the copy.always_keep default.

config/jets/bootstrap.rb

Jets.bootstrap.configure do
  config.code.copy.always_keep = ["config/jets/env"] # default
end

Note: The config/jets/env files must exist to be copied. IE: They may not for CI.

Jets CI .gitignore

If you are using Jets CI, then config/jets/env may not be in the git repo for the CI run. IE: Even always_keep won’t work. When using CI, you have to make sure config/jets/env files are in version control. IE: Check GitHub and confirm it’s there.

If the config/jets/env is not in version control, it’s probably due to a gitignore rule.

Here is an example that allows config/jets/env files while ignoring .env at the top level.

.gitignore

# Ignore all environment files except templates
/.env*
!/.env*.erb

Here’s another example of ignoring all .env files and explicitly allowing /config/jets/env/.env

.gitignore

# Ignore all environment files except /config/jets/env/.env
.env*
!/config/jets/env/*

Make sure the !/config/jets/env/* line is below any .env ignores. Otherwise, the .env ignore will take higher precedence.

Important: Ensure you do not have secret info in config/jets/env and only have SSM references or safe-to-commit plain text values. Another option is to store all env values in SSM parameters and not use config/jets/env files. CI will be able to look up the SSM parameters.