-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathupdate-lambda.sh
More file actions
executable file
·71 lines (57 loc) · 1.89 KB
/
update-lambda.sh
File metadata and controls
executable file
·71 lines (57 loc) · 1.89 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
#!/bin/sh
# This script will build the provided project, copy the zip file to S3 and then call
# `update-function-code` with the AWS Cli to update the lambda.
# Usage: ./update-lambda.sh [project name] [--quick] [function names...]
# eg. ./update-lambda.sh discount-api
# eg. ./update-lambda.sh --quick mparticle-api mparticle-api-http- mparticle-api-baton-
# Exit if any of these commands fail
set -e
cd "$(dirname "$0")"
if [ $# -lt 1 ]; then
echo "please provide the project name as an argument, eg. ./update-lambda.sh [--quick] discount-api [function names...]"
exit 2
fi
QUICK_MODE=""
PROJECT_NAME=""
FUNCTION_NAMES=""
while [ $# -gt 0 ]; do
if [ "$1" = "--quick" ]; then
QUICK_MODE="true"
elif [ -z "$PROJECT_NAME" ]; then
PROJECT_NAME="$1"
else
FUNCTION_NAMES="$FUNCTION_NAMES $1"
fi
shift
done
if [ -z "$PROJECT_NAME" ]; then
echo "please provide the project name as an argument, eg. ./update-lambda.sh discount-api [--quick] [function names...]"
exit 2
fi
if [ -z "$FUNCTION_NAMES" ]; then
FUNCTION_NAMES="$PROJECT_NAME-"
fi
echo "Updating handler $PROJECT_NAME"
if [ -n "$QUICK_MODE" ]; then
pushd "handlers/$PROJECT_NAME"
pnpm build
cd target && zip -qr "$PROJECT_NAME.zip" ./*.js.map ./*.js
popd
else
pnpm --filter "$PROJECT_NAME" package
fi
s3Bucket=`aws ssm get-parameter --name /account/services/artifact.bucket --query "Parameter.Value" --output text --profile membership --region eu-west-1`
s3Path="support/CODE/$PROJECT_NAME/$PROJECT_NAME.zip"
zipFile="./handlers/$PROJECT_NAME/target/$PROJECT_NAME.zip"
aws s3 cp $zipFile s3://$s3Bucket/$s3Path --profile membership --region eu-west-1
for fn in $FUNCTION_NAMES; do
echo "Updating lambda $fn"
aws lambda update-function-code \
--function-name "${fn}CODE" \
--s3-bucket $s3Bucket \
--s3-key $s3Path \
--profile membership \
--region eu-west-1 \
> /dev/null
done
echo "Update complete"