-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_lambda.sh
executable file
·72 lines (59 loc) · 1.96 KB
/
deploy_lambda.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Deploy the lambda function
# Usage: ./deploy_lambda.sh <path_to_requirements.txt> <layer_name> <function_name>
# Note: The zip file should be in the same directory as this script
# Note: The function name should be the name of the lambda function
set -e
# Check if the function name and zip file are provided
if [ $# -ne 3 ]; then
echo "Usage: ./deploy_lambda.sh <path_to_requirements.txt> <layer_name> <function_name>"
exit 1
fi
# Set the path to the requirements file
requirements_file=$1
layer_name=$2
# Package the lambda layer
echo "Packaging the lambda layer..."
mkdir -p python
pip3 install \
--platform manylinux2014_x86_64 \
--target="./python" \
--implementation cp \
--python-version 3.12 \
--only-binary=:all: \
-r $requirements_file
# Zip the lambda layer
zip -r $layer_name.zip ./python
# Deploy the lambda layer
echo "Deploying the lambda layer..."
LAYER_VERSION_ARN=$(aws lambda publish-layer-version \
--layer-name $layer_name \
--description "Lambda layer for $layer_name" \
--license-info "MIT" \
--zip-file fileb://$layer_name.zip \
--compatible-runtimes python3.12 \
--output text --query LayerVersionArn)
echo "Lambda layer $layer_name deployed with ARN: $LAYER_VERSION_ARN"
# Package FastAPI
echo "Packaging the lambda function..."
cd app
zip -r ../lambda_function.zip *
cd ..
DIR=$(pwd)
echo "Current directory: $DIR"
# Set the function name
function_name=$3
function_zip="lambda_function.zip"
# Deploy the lambda function
echo "Deploying the lambda function..."
FUNCTION_ARN=$(aws lambda create-function \
--function-name $function_name \
--runtime python3.12 \
--package-type "Zip" \
--handler main.handler --publish \
--zip-file fileb://$function_zip \
--layers $LAYER_VERSION_ARN \
--role arn:aws:iam::815752282021:role/LambdaToDynamoRole \
--output text --query FunctionArn)
echo "Lambda function $function_name deployed with ARN: $FUNCTION_ARN"
echo "Done."