-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·53 lines (45 loc) · 1.39 KB
/
deploy.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.39 KB
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
#!/usr/bin/env bash
set -euo pipefail
FUNCTION_NAME="ai-latencies"
REGION="${AWS_REGION:-us-east-1}"
ROLE_ARN="arn:aws:iam::717589162638:role/ai-latencies-lambda"
S3_BUCKET="ai-latencies-deploy"
echo "Building..."
npm run build --silent
echo "Packaging..."
mkdir -p dist
cp dist/index.mjs /tmp/index.mjs
cd /tmp && zip -j /tmp/ai-latencies.zip index.mjs && cd -
ZIP_SIZE=$(du -h /tmp/ai-latencies.zip | cut -f1)
echo "Zip size: $ZIP_SIZE"
# Check if function exists
if aws lambda get-function --function-name "$FUNCTION_NAME" --region "$REGION" &>/dev/null; then
echo "Updating function code..."
aws lambda update-function-code \
--function-name "$FUNCTION_NAME" \
--zip-file fileb:///tmp/ai-latencies.zip \
--region "$REGION" \
--no-cli-pager
echo "Waiting for update..."
aws lambda wait function-updated-v2 \
--function-name "$FUNCTION_NAME" \
--region "$REGION"
else
echo "Creating function..."
aws lambda create-function \
--function-name "$FUNCTION_NAME" \
--runtime nodejs20.x \
--handler index.handler \
--role "$ROLE_ARN" \
--zip-file fileb:///tmp/ai-latencies.zip \
--timeout 300 \
--memory-size 3072 \
--region "$REGION" \
--no-cli-pager
echo "Waiting for creation..."
aws lambda wait function-active-v2 \
--function-name "$FUNCTION_NAME" \
--region "$REGION"
fi
echo "Deployed."
rm -f /tmp/ai-latencies.zip /tmp/index.mjs