We MUST use the node-lambda (github/npm) tool to deploy lambdas.
node-lambda's README is a good primer on its commands & configuration files.
Because of a wonky interaction between the aws-sdk and dotenv node modules.
Developers MUST NOT have a [default] environment in their files located in ./.aws/.
See this PR-38 for a full discussion.
-
Lambdas SHOULD get their description from the
'description'attribute ofpackage.json, not from theDESCRIPTIONvariable in.env. -
Each app MUST bring in its own version of node-lambda as a
devDependency. It MUST NOT rely on a globally installed node-lambda. -
Deployments MUST be done through pre-baked commands in the
'scripts'block ofpackage.jsonthat follow the following rules:-
The command will be named
'deploy-[ENVIRONMENT-NAME]' -
The command will pass environment-specific info as flags to the
node-lambda deploycommand. -
The command uses the locally packaged
node-lambda -
The command knows which AWS account / credentials to use via the
--profileflag -
Because we don't put secrets in
.env(IAM credentials get read via the--profileflag), we MUST keep.envin source control. -
Use the
-eflag for environment, which appends the environment name to the name of the function created.
-
-
That is to say,
.envMUST NOT contain tier / environment specific configuration. Those must be passed in via flags tonode-lambda deploy.
A package.json that looks like:
{ //...snip!
'scripts': {
'deploy-production': './node_modules/.bin/node-lambda deploy -e production -f ./config/prod.env -S config/event_sources_prod.json -b subnet-id1,subnet-id2 -g sg-id --role arn:aws:iam::[some-id]:role/[rolename] --profile our-profile-name'
},
// ...snip!
}Allows you to have a .env, in source control that looks like:
AWS_REGION=us-east-1
AWS_FUNCTION_NAME=MyFunctionName
AWS_HANDLER=index.handler
AWS_MEMORY_SIZE=768
AWS_TIMEOUT=30
AWS_RUNTIME=nodejs6.10
EXCLUDE_GLOBS="event.json"
PACKAGE_DIRECTORY=build
The above is much slimmer than the boilerplate .env generated by node-lambda setup and allows:
-
.envto define stage/environment independent variables. -
pass environment specific variables as flags to the
node-lambda deploycalls in scripts. -
Finally - since the only secrets are IAM key/secret & those are brought in via the
--profileflag,.envcan be in source control.
An example of what config/event_sources_prod.json might look like:
{
"EventSourceMappings": [
{
"EventSourceArn": "arn:aws:kinesis:us-east-1:[alongid]:stream/[streamname]",
"StartingPosition": "LATEST",
"BatchSize": 50,
"Enabled": true
}
]
}Finally, each repo MUST contain an example environment-name.env file (-f flag)
that contains names of the RUN TIME env vars and explanatory text as its values.
The README MUST include instructions on putting those config files in their
appropriate place (e.g. running cp or some other command to move the example into
a git ignored place)