forked from alestic/aws-git-backed-static-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-upload-aws-lambda-function
More file actions
executable file
·39 lines (32 loc) · 1.03 KB
/
build-upload-aws-lambda-function
File metadata and controls
executable file
·39 lines (32 loc) · 1.03 KB
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
#!/bin/bash -ex
#
# Build AWS Lambda function ZIP file and upload to S3
#
# Usage: ./build-upload-aws-lambda-function S3BUCKET S3KEY
#
# ./build-upload-aws-lambda-function run.alestic.com lambda/aws-lambda-git-backed-static-website.zip
#
s3bucket=${1:?Specify target S3 bucket name}
s3key=${2:?Specify target S3 key}
target=s3://$s3bucket/$s3key
tmpdir=$(mktemp -d /tmp/lambda-XXXXXX)
zipfile=$tmpdir/lambda.zip
virtualenv=$tmpdir/virtual-env
(
virtualenv $virtualenv
source $virtualenv/bin/activate
pip install awscli boto3
)
# "aws" command (fixing shabang line)
rsync -va $virtualenv/bin/aws $tmpdir/aws
perl -pi -e '$_ ="#!/usr/bin/python\n" if $. == 1' $tmpdir/aws
(cd $tmpdir; zip -r9 $zipfile aws)
# aws-cli package requirements
(cd $virtualenv/lib/python2.7/site-packages && zip -r9 $zipfile *)
# AWS Lambda function (with the right name)
rsync -va aws-git-backed-static-website-lambda.py $tmpdir/index.py
(cd $tmpdir; zip -r9 $zipfile index.py)
# Upload to S3
aws s3 cp --acl=public-read $zipfile $target
# Clean up
rm -rf $tmpdir