-
Notifications
You must be signed in to change notification settings - Fork 30
/
deploy-lambda.sh
executable file
·76 lines (64 loc) · 1.43 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
72
73
74
75
76
#!/bin/bash
#
# deploy-lambda.sh
# Zip and deploy lambda function
#
set -o errexit
region=${REGION:-eu-west-1}
if [ $# -lt 2 ]
then
echo 'Missing required parameters'
echo "Usage $0 <function> <role_stack_name> [zip] [timeout]"
exit 1
fi
func="$1"
role_stack_name="$2"
zip=${3:-"./${func}.zip"}
timeout=${4:-"10"}
file="./${func}.js"
description="Cloud Formation Custom Resource: $func"
role_arn() {
aws cloudformation describe-stacks \
--region $region \
--stack-name $role_stack_name \
| jq '.Stacks[0].Outputs[]| select(.OutputKey=="RoleArn")|.OutputValue' \
| tr -d \"
}
zip_package() {
zip -qr $zip $file
}
function_exists() {
echo "Checking for function $func"
aws lambda get-function \
--region $region \
--function-name $func > /dev/null 2>&1
}
create_function() {
echo "Getting ARN for role $role_stack_name"
local role_arn=$(role_arn)
echo "CREATE function $func"
aws lambda create-function \
--region $region \
--role $role_arn \
--runtime nodejs6.10 \
--function-name $func \
--description "$description" \
--handler ${func}.handler \
--timeout $timeout \
--memory-size 512 \
--zip-file fileb://$zip
}
update_function() {
echo "UPDATING function $func"
aws lambda update-function-code \
--region $region \
--function-name $func \
--zip-file fileb://$zip
}
# main
zip_package
if function_exists; then
update_function
else
create_function
fi