Skip to content

Instantly share code, notes, and snippets.

@itsmemattchung
Last active December 16, 2019 09:30
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsmemattchung/45493a6b005bca467808 to your computer and use it in GitHub Desktop.
Save itsmemattchung/45493a6b005bca467808 to your computer and use it in GitHub Desktop.
Makefile example for aws lambda
PROJECT = sample-python-app
FUNCTION = $(PROJECT)
REGION = us-east-1
.phony: clean
clean:
rm -f -r $(FUNCTION)*
rm -f -r site-packages
build-dev: clean
aws s3 cp s3://$(FUNCTION)/settings-dev.yml settings.yml
zip -r $(FUNCTION)-dev.zip . -x "*.git*" "tests/*"
mkdir -p site-packages
virtualenv $(FUNCTION)-dev
. $(FUNCTION)-dev/bin/activate
pip install -r requirements.txt
cd site-packages; cp -r $$VIRTUAL_ENV/lib/python2.7/site-packages/ ./
cd site-packages; zip -g -r ../$(FUNCTION)-dev.zip .
create-dev:
aws lambda create-function \
--handler main.lambda_handler \
--function-name $(FUNCTION)-dev \
--region $(REGION) \
--zip-file fileb://$(FUNCTION)-dev.zip \
--role arn:aws:iam::XXXX:role/$(FUNCTION)-dev \
--runtime python2.7 \
--timeout 120 \
--memory-size 512 \
update-dev:
aws lambda update-function-code \
--function-name $(FUNCTION)-dev \
--zip-file fileb://$(FUNCTION)-dev.zip \
--publish \
delete-dev:
aws lambda delete-function --function-name $(FUNCTION)-dev
@ruffyleaf
Copy link

Thanks for this mate. I found it very helpful and useful.

@ruffyleaf
Copy link

ruffyleaf commented Oct 12, 2017

One thing is the virutalenv though, had to maintain the virtualenv like this

. $(FUNCTION)/bin/activate; pip install -r requirements.txt;\
cd site-packages; cp -r $$VIRTUAL_ENV/lib/python2.7/site-packages/ ./;\
cp -r $$VIRTUAL_ENV/lib64/python2.7/site-packages/ ./;\
cd site-packages; zip -r9 ../../$(FUNCTION).zip .

Because in the Makefile, each line is considered new and the Virtualenv does not hold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment