-
Notifications
You must be signed in to change notification settings - Fork 1
/
lambda-echo-install
executable file
·57 lines (43 loc) · 1.58 KB
/
lambda-echo-install
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
#!/bin/bash -ex
#
# Install AWS Lambda function: lambda-echo
#
## Setup
lambda_function_name=lambda-echo
lambda_description="Echo AWS Lambda event JSON to CloudWatch Logs"
lambda_handler=lambda-echo.handler
lambda_memory=128
lambda_timeout=2
lambda_function_file=$lambda_function_name.js
lambda_assume_role_policy_file=$lambda_function_name-assume-role-policy.json
lambda_execution_policy_file=$lambda_function_name-execution-policy.json
## Create ZIP file
lambda_zip_dir=$(mktemp -d /tmp/$lambda_function_name.XXXXXX)
lambda_zip_file=$lambda_zip_dir/$lambda_function_name.zip
zip -q -r $lambda_zip_file $lambda_function_file
## Create Role and attach policies
lambda_role_arn=$(aws iam create-role \
--role-name "$lambda_function_name-role" \
--assume-role-policy-document "file://$lambda_assume_role_policy_file"\
--output text \
--query 'Role.Arn'
)
aws iam put-role-policy \
--role-name "$lambda_function_name-role" \
--policy-name "$lambda_function_name-policy" \
--policy-document "file://$lambda_execution_policy_file"
# Seems to be some timing issue here
sleep 10
## Create the function and upload the ZIP file
aws lambda create-function \
--function-name "$lambda_function_name" \
--runtime nodejs \
--memory-size "$lambda_memory" \
--timeout "$lambda_timeout" \
--role "$lambda_role_arn" \
--handler "$lambda_handler" \
--description "$lambda_description" \
--zip-file "fileb://$lambda_zip_file"
## Cleanup
rm -r $lambda_zip_dir
exit 0