- build project into zip bundle
- upload bundle to S3
- create/update the lambda function
If the lambda function does not exist, the script creates it. However, it does not configure event sources and other parameters. Manual intervention is therefore required.
Source code goes into src/
.
Source code is compiled by babel.
The function entry point is the handler
function exported in src/index.js
.
Dependencies must be listed in package.json
.
The following environment variables are needed to deploy the function:
AWS_SECRET_ACCESS_KEY
AWS_ACCESS_KEY_ID
AWS_DEFAULT_REGION
S3_BUCKET
LAMBDA_NAME
LAMBDA_ROLE_ARN
GIT_BRANCH
, equivalentlyTRAVIS_BRANCH
GIT_COMMIT
, equivalentlyTRAVIS_COMMIT
GIT_PULL_REQUEST
, equivalentlyTRAVIS_PULL_REQUEST
(optional)GIT_TAG
, equivalentlyTRAVIS_TAG
(optional)
WARNING: the value of those variables must be kept secret. If using Travis, do
not set them in the .travis.yml
config file, only in the Travis project's
settings (where they are kept secret).
To pass runtime configurations to the function, set environment variables
prefixed by __FUNC_CONFIG__
. Those will be collected and written to the .env
file from where they can be loaded using dotenv.
For example, if we define the following environment variables in the build environment:
env DB_HOST=localhost
env DB_USER=root
env DB_PASS=s1mpl3
then the following .env
file is generated:
DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3
which can be loaded by the lambda function with:
import dotenv from "dotenv";
dotenv.load();
export function handler (event, context) {
context.succeed(JSON.stringify(process.env));
}
The script bundles the current repository and uploads it to AWS S3. The name of the bundle is derived from the following parameters:
LAMBDA_NAME
GIT_BRANCH
GIT_COMMIT
GIT_TAG
GIT_PULL_REQUEST
The name of the lambda function is derived from the following parameters:
LAMBDA_NAME
GIT_BRANCH