Last active
December 16, 2019 09:30
-
-
Save itsmemattchung/45493a6b005bca467808 to your computer and use it in GitHub Desktop.
Makefile example for aws lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Thanks for this mate. I found it very helpful and useful.