Skip to content

Instantly share code, notes, and snippets.

@RichardBronosky
Last active March 24, 2017 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBronosky/e682c46bb5c63c3eae04b7a78870c77b to your computer and use it in GitHub Desktop.
Save RichardBronosky/e682c46bb5c63c3eae04b7a78870c77b to your computer and use it in GitHub Desktop.
Makefile for python2.7 AWS Lambda functions
.PHONY: all update upload s3 clean purge virtualenv
# Usage:
# make clean && make && make s3
# make update && make upload
# make purge && git add *
# make purge && make virtualenv && make clean && make
zipfile = lambda.zip
pyfile = lambda_function.py
sitepackages = lib/python2.7/site-packages # this assumes that lib64 is a link to lib as is the case with Amazon Linux 2016.09.1
s3uri = s3://ies-devops/bots/lambda
pwd = $(shell pwd)
all: $(zipfile)
$(zipfile): $(pyfile)
zip -9 $(zipfile) $(pyfile)
cd $(sitepackages) && \
zip -r9 $(pwd)/$(zipfile) .
update:
zip -9 $(zipfile) $(pyfile)
upload:
aws lambda update-function-code --function-name $(shell basename $(pwd)) --zip-file fileb://$(zipfile)
s3:
aws s3 cp $(zipfile) $(s3uri)/$(zipfile)
clean:
rm $(zipfile)
purge:
rm -rf bin include lib{64,} local .Python
virtualenv: bin/python2.7
bin/python2.7:
python2.7 -m virtualenv .
. bin/activate && python -m pip install -r requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment