-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·76 lines (63 loc) · 2.65 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·76 lines (63 loc) · 2.65 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -euo pipefail
AWS_ACCOUNT_ID="${AWS_ACCOUNT_ID:-669728696264}"
AWS_REGION="${AWS_REGION:-us-east-1}"
ECR_REPO_NAME="${ECR_REPO_NAME:-ivr_pro_api_all}"
IMAGE_URI="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO_NAME}:latest"
LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME:-ivr_pro_api_all}"
DOCKER_PLATFORM="${DOCKER_PLATFORM:-linux/amd64}"
LAMBDA_TIMEOUT_SECONDS="${LAMBDA_TIMEOUT_SECONDS:-15}"
UPDATE_LAMBDA_TIMEOUT="${UPDATE_LAMBDA_TIMEOUT:-1}"
SKIP_ENV_CHECK="${SKIP_ENV_CHECK:-0}"
if [[ "${SKIP_ENV_CHECK}" != "1" ]]; then
echo "=== Verifying required Lambda environment ==="
if ! aws lambda get-function-configuration \
--region "${AWS_REGION}" \
--function-name "${LAMBDA_FUNCTION_NAME}" \
--query 'contains(keys(Environment.Variables || `{}`), `DGA_IMPORT_API_KEY`)' \
--output text | grep -q '^True$'; then
echo "ERROR: ${LAMBDA_FUNCTION_NAME} is missing required env var DGA_IMPORT_API_KEY."
echo "Set it on the Lambda configuration before deploying, or set SKIP_ENV_CHECK=1 for a new/manual setup."
exit 1
fi
fi
echo "=== Building Docker Image (${DOCKER_PLATFORM}) ==="
docker buildx build \
--platform="${DOCKER_PLATFORM}" \
--load \
-t "${ECR_REPO_NAME}:latest" \
.
echo "=== Verifying architecture ==="
ARCH="$(docker inspect "${ECR_REPO_NAME}:latest" --format '{{.Architecture}}')"
EXPECTED_ARCH="${DOCKER_PLATFORM##*/}"
if [[ "${ARCH}" != "${EXPECTED_ARCH}" ]]; then
echo "ERROR: Image is ${ARCH}, Lambda requires ${EXPECTED_ARCH}. Is docker buildx working?"
exit 1
fi
echo "Architecture: ${ARCH}"
echo "=== Authenticating to ECR ==="
aws ecr get-login-password --region "${AWS_REGION}" | \
docker login --username AWS --password-stdin "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
echo "=== Tagging Docker Image ==="
docker tag "${ECR_REPO_NAME}:latest" "${IMAGE_URI}"
echo "=== Pushing Docker Image to ECR ==="
docker push "${IMAGE_URI}"
echo "=== Updating Lambda to use the new Container Image ==="
aws lambda update-function-code \
--region "${AWS_REGION}" \
--function-name "${LAMBDA_FUNCTION_NAME}" \
--image-uri "${IMAGE_URI}"
aws lambda wait function-updated \
--region "${AWS_REGION}" \
--function-name "${LAMBDA_FUNCTION_NAME}"
if [[ "${UPDATE_LAMBDA_TIMEOUT}" == "1" ]]; then
echo "=== Updating Lambda timeout to ${LAMBDA_TIMEOUT_SECONDS}s ==="
aws lambda update-function-configuration \
--region "${AWS_REGION}" \
--function-name "${LAMBDA_FUNCTION_NAME}" \
--timeout "${LAMBDA_TIMEOUT_SECONDS}"
aws lambda wait function-updated \
--region "${AWS_REGION}" \
--function-name "${LAMBDA_FUNCTION_NAME}"
fi
echo "=== Deployment Complete! ==="