-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
71 lines (62 loc) · 1.69 KB
/
Makefile
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
LAMBDA_FUNCTION_NAME=monzo-webhook
LAMBDA_HANDLER=lambda_handler
LAMBDA_FILE=$(LAMBDA_FUNCTION_NAME).py
ZIP_FILE=$(LAMBDA_FUNCTION_NAME).zip
PACKAGE_ZIP=dist/$(ZIP_FILE)
VIRT_ENV=env
LAMBDA_ENV=config/lambda.env
LAMBDA_ROLE=arn:aws:iam::CHANGEME:role/..
install: venv
build: mkdist clean_dist zip
update: build lambda_upload lambda_setenv
venv:
if test ! -d "$(VIRT_ENV)"; then \
pip3 install virtualenv; \
virtualenv $(VIRT_ENV); \
fi
( \
. $(VIRT_ENV)/bin/activate; \
pip3 install -r config/requirements.txt; \
)
clean_dist:
rm -f dist/${ZIP_FILE}
rm -fr dist/*.dist-info
rm -fr dist/*.egg-info
rm -fr dist/*virtualenv*
cd dist; \
rm -fr __pycache__; \
rm -fr easy_install.py; \
rm -fr pip; \
rm -fr pkg_resources; \
rm -fr setuptools; \
rm -fr wheel; \
mkdist:
mkdir -p dist
cp -r $(VIRT_ENV)/lib/python3*/site-packages/* dist/
cp -r src/* dist/
zip:
cd dist; \
chmod 644 $(LAMBDA_FILE); \
zip -r $(ZIP_FILE) *; \
chmod 644 $(ZIP_FILE); \
lambda_upload:
aws lambda update-function-code \
--function-name $(LAMBDA_FUNCTION_NAME) \
--zip-file fileb://$(PACKAGE_ZIP)
lambda_setenv:
aws lambda update-function-configuration \
--function-name $(LAMBDA_FUNCTION_NAME) \
--environment Variables="{"$(shell cat $(LAMBDA_ENV) | paste -sd',' -)"}"
lambda_create:
aws lambda create-function \
--function-name $(LAMBDA_FUNCTION_NAME) \
--runtime python3.6 \
--role $(LAMBDA_ROLE) \
--handler $(LAMBDA_FUNCTION_NAME).$(LAMBDA_HANDLER) \
--zip-file fileb://$(PACKAGE_ZIP) \
--environment Variables="{"$(shell cat $(LAMBDA_ENV) | paste -sd',' -)"}" \
--timeout 8 \
--memory-size 128 \
lambda_delete:
aws lambda delete-function \
--function-name $(LAMBDA_FUNCTION_NAME)