-
Notifications
You must be signed in to change notification settings - Fork 40
/
lambdash-upload-s3
executable file
·43 lines (32 loc) · 1.1 KB
/
lambdash-upload-s3
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
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash -e
#
# lambdash-upload-s3 - Upload to S3: Lambda ZIP and CloudFormation template
#
# Settings
function=lambdash
s3_bucket=run.alestic.com
s3_zipfile=s3://$s3_bucket/lambda/$function.zip
s3_template_file=s3://$s3_bucket/cloudformation/$function.template
tmpdir=$(mktemp -d /tmp/lambda-XXXXXX)
virtualenv=$tmpdir/virtual-env
zipfile=$tmpdir/lambda.zip
on_exit()
{
rm -r $tmpdir
}
trap 'on_exit' EXIT
# Build aws-cli package in a virtualenv subshell
(
virtualenv -q $virtualenv
source $virtualenv/bin/activate
pip -q install awscli
)
# Create ZIP file with AWS Lambda function and aws-cli
zip -qr9 $zipfile index.js
rsync -a $virtualenv/bin/aws $tmpdir/aws
perl -pi -e '$_ ="#!/usr/bin/python\n" if $. == 1' $tmpdir/aws
(cd $tmpdir; zip -qr9 $zipfile aws)
(cd $virtualenv/lib/python2.7/site-packages; zip -qr9 $zipfile *)
# Upload Lambda function ZIP file and CloudFormation template to S3
aws s3 cp --acl public-read $zipfile $s3_zipfile
aws s3 cp --acl public-read $function.template $s3_template_file