-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_layer.sh
executable file
·54 lines (40 loc) · 1.39 KB
/
make_layer.sh
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
#!/bin/bash
PYTHON_VERSION="python3.10"
APP=main.zip
FUNC_NAME=mangun-demo
zip $APP main.py
pip3 install -r requirements.txt -t tmp/python
cd tmp/ && zip -r ../myLayer.zip .
ROLE=$(aws iam create-role \
--role-name myrole \
--assume-role-policy-document file://../trust-policy.json --query "Role.Arn" --output text)
aws iam attach-role-policy \
--role-name myrole \
--policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
LAYER=$(aws lambda publish-layer-version \
--compatible-architectures x86_64 \
--layer-name $FUNC_NAME \
--description "fastapi+mangum" \
--zip-file fileb://../myLayer.zip \
--compatible-runtimes $PYTHON_VERSION \
--license-info "egal" --query "LayerVersionArn" --output text)
FUNCTION=$(aws lambda create-function \
--function-name $FUNC_NAME \
--runtime $PYTHON_VERSION \
--role $ROLE \
--handler main.handler \
--layers $LAYER \
--zip-file fileb://../$APP)
aws lambda add-permission \
--function-name $FUNC_NAME \
--statement-id AllowPublic \
--action lambda:InvokeFunctionUrl \
--principal "*" \
--function-url-auth-type NONE
URL=$(aws lambda create-function-url-config \
--function-name $FUNC_NAME \
--auth-type NONE \
--query 'FunctionUrlConfig.FunctionUrl' \
--output text)
# aws lambda get-function-url-config --function-name mangun-demo --output text --query FunctionUrl
echo "Endpoint: $URL"