-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
92 lines (76 loc) · 2.35 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
PYTHON_VERSION=python3.9
APP=main.zip
FUNC_NAME=mangun-demo
ROLE_NAME=myrole
LAYER_NAME=$(FUNC_NAME)
POLICY_ARN=arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
LAYER=$(FUNC_NAME)
all: echo_url
#ROLE_ARN := $(shell aws iam get-role --role-name myrole --query 'Role.Arn' --output text)
ROLE_ARN=arn:aws:sts::871751837375:assumed-role/myManGumBuilder/AWSCodeBuild-370d18ed-4228-4fd3-a869-7967fe9cb58d
.PHONY: echo_url
echo_url: create_function_url_config
aws lambda create-function-url-config \
--function-name $(FUNC_NAME) \
--auth-type NONE \
--query 'FunctionUrlConfig.FunctionUrl' \
--output text
.PHONY: create_function_url_config
create_function_url_config: create_function #add_permission
.PHONY: add_permission
add_permission: create_function
aws lambda add-permission \
--function-name $(FUNC_NAME) \
--statement-id AllowPublic \
--action lambda:InvokeFunctionUrl \
--principal "*" \
--function-url-auth-type NONE
.PHONY: create_role
create_role: #FIXME
$(eval ROLE := $(shell aws iam create-role \
--role-name $(ROLE_NAME) \
--assume-role-policy-document file://trust-policy.json \
--query "Role.Arn" --output text))
.PHONY: attach_policy
attach_policy: create_role
aws iam attach-role-policy \
--role-name $(ROLE_NAME) \
--policy-arn $(POLICY_ARN)
.PHONY: create_function
create_function: publish_layer #create_role attach_policy publish_layer
aws lambda create-function \
--function-name $(FUNC_NAME) \
--runtime $(PYTHON_VERSION) \
--role $(ROLE_ARN) \
--handler main.handler \
--layers $(LAYER) \
--zip-file fileb://$(APP)
.PHONY: publish_layer
publish_layer: myLayer.zip
aws lambda publish-layer-version \
--compatible-architectures x86_64 \
--layer-name $(LAYER_NAME) \
--description "fastapi+mangum" \
--zip-file fileb://myLayer.zip \
--compatible-runtimes $(PYTHON_VERSION) \
--license-info "egal" --query "LayerVersionArn" --output text
myLayer.zip: tmp
cd tmp/ && zip -r ../myLayer.zip .
.PHONY: tmp
tmp: $(APP)
pip3 install -r requirements.txt -t tmp/python
$(APP):
zip $(APP) main.py
.PHONY: detach_policy
detach_policy:
aws iam detach-role-policy \
--role-name $(ROLE_NAME) \
--policy-arn $(POLICY_ARN)
.PHONY: delete_role
delete_role: detach_policy
aws iam delete-role \
--role-name $(ROLE_NAME)
.PHONY: clean
clean: detach_policy delete_role
rm -f $(APP) myLayer.zip
rm -rf tmp