-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush-to-lambda.sh
More file actions
executable file
·32 lines (25 loc) · 859 Bytes
/
push-to-lambda.sh
File metadata and controls
executable file
·32 lines (25 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash -ex
#
# Build AWS Lambda function ZIP file and upload to S3
# you need pip installed, and python, and awscli
#
# Usage: ./push-to-lambda S3BUCKET S3KEY
#
# ./push-to-lambda run.bitflight.io lambda/project.zip
s3bucket=${1:?Specify target S3 bucket name}
s3key=${2:?Specify target S3 key}
target=s3://$s3bucket/$s3key
if ! type aws > /dev/null; then
pip install awscli
fi
tmpdir=$(mktemp -d /tmp/lambda-XXXXXX)
zipfile=$tmpdir/lambda.zip
(cd $tmpdir; npm install aws-sdk; zip -r9 $zipfile node_modules)
# AWS Lambda function (with the right name)
rsync -va modify-volume-event.js $tmpdir/index.js
(cd $tmpdir; zip -r9 $zipfile index.js)
# Upload to S3
aws s3 cp --acl=public-read $zipfile $target
aws lambda update-function-code --region us-west-2 --function-name increaseIOPS --s3-bucket $s3bucket --s3-key $s3key
# Clean up
rm -rf $tmpdir