Balihoo Lambda deploy tools
pip install git+https://github.com/balihoo-gens/blambda.git
First, make sure your AWS credentials are set up Then configure at least these two variables:
blambda config region us-east-1
blambda config role 'arn:aws:iam::etcetera'
you can also set the variables 'application' and 'environment' which will automatically be prepended and appended to your function name. my_function
would turn into myapp_my_function_myenv
for example.
blambda new new_thing
will get you a directory called 'new_thing' containing new_thing.py and new_thing.json
you can provide--runtime coffee
to create a new coffee script function.
The json file is your manifest, which can look like:
{
"blambda": "manifest",
"dependencies": {
"tldextract": "2.0.1"
},
"options": {
"Description": "test_thing",
"Runtime": "python2.7",
"Timeout": 300
},
"permissions": [
{
"Effect": "Allow",
"Action": "route53:ChangeResourceRecordSets",
"Resource": "arn:aws:route53:::hostedzone/SAKJHAUHIS"
}
],
"schedule": {
"input": { "things": "stuff" },
"rate": "1 minute"
},
"source files": [
"test_thing.py",
"my_other_file.py"
]
}
you can add dependencies with an explicit version, and permissions as IAM statements source files can be relative paths, and can be a tuple with (local, remote) name, so you can pull in shared files
before deploying, your dependencies need to be installed. This is a separate step because you do not need to do this as often.
blambda deps new_thing
For Python, you can choose to have them installed in/with whatever python environment you are in, or to set up an AWS Lambda equivalent 2.7 environment specifically for your function. The latter is convenient for local testing to avoid missing dependencies
blambda deps new_thing --ve
Deploy sets up your lambda function as well as any IAM roles, CloudWatch Events schedules etc.
blambda deploy test_thing
You can run your function right from the commandline
blambda exec test_thing
will take a json payload from stdin, so
cat payload.json | blambda exec test_thing
will send the contents of payload.json
to the deployed test_thing lambda function
blambda exec test_thing --payload '{ "my": "payload"}'
will do the same as:
echo '{ "my": "payload"}' | blambda exec test_thing --payload
blambda logs new_thing
will get you the cloudwatch log messages (== function stdout) from your function for recent executions. logs has many options, that you can see with blambda logs --help
. In short, you can specify different output formattings, summary and date/time range
Sometimes, you forget what is deployed in lambda and how far out of date it is with your current repo. Blambda can help you with this by asking it to check for 'stale' functions:
blambda stale
will tell you which functions are out of date compared to the current repo HEAD. Supplying the -v (verbose) option will also tell you which files are out of date.