lambda-deploy
v2.1.0
Published
Deploy lambda functions
Readme
Lambda deploy
Workflow
- 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.
Conventions to follow
Source code compilation
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.
Build configuration
The following environment variables are needed to deploy the function:
AWS_SECRET_ACCESS_KEYAWS_ACCESS_KEY_IDAWS_DEFAULT_REGIONS3_BUCKETLAMBDA_NAMELAMBDA_ROLE_ARNGIT_BRANCH, equivalentlyTRAVIS_BRANCHGIT_COMMIT, equivalentlyTRAVIS_COMMITGIT_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).
Runtime configuration
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=s1mpl3then the following .env file is generated:
DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3which can be loaded by the lambda function with:
import {load} from "dotenv";
load();
export function handler (event, context) {
context.succeed(JSON.stringify(process.env));
}Output
The script bundles the current repository and uploads it to AWS S3. The name of the bundle is derived from the following parameters:
LAMBDA_NAMEGIT_BRANCHGIT_COMMITGIT_TAGGIT_PULL_REQUEST
The name of the lambda function is derived from the following parameters:
LAMBDA_NAMEGIT_BRANCH
