-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpublish.sh
executable file
·69 lines (57 loc) · 1.72 KB
/
publish.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
#!/bin/bash
#
# variables
#
# AWS variables
AWS_REGION=eu-west-3
# project name
PROJECT_NAME=lambda-terraform-github-actions
# the directory containing the script file
dir="$(cd "$(dirname "$0")"; pwd)"
cd "$dir"
[[ $1 != 'prod' && $1 != 'dev' ]] && { echo 'usage: publish.sh <prod | dev>'; exit 1; } ;
# root account id
ACCOUNT_ID=$(aws sts get-caller-identity \
--query Account \
--output text)
API_GATEWAY_ID=$(aws apigateway get-rest-apis \
--query "items[?name=='$PROJECT_NAME'].id" \
--region $AWS_REGION \
--output text)
echo apigateway id: $API_GATEWAY_ID
echo aws lambda delete-alias $1
aws lambda delete-alias \
--function-name $PROJECT_NAME \
--name $1 \
--region $AWS_REGION \
2>/dev/null
echo zip hello.js
cd lambda/
rm --force hello.zip
zip hello.zip hello.js
echo aws lambda update-function-code $PROJECT_NAME
aws lambda update-function-code \
--function-name $PROJECT_NAME \
--zip-file fileb://hello.zip \
--region $AWS_REGION
echo aws lambda update-function-code $PROJECT_NAME
VERSION=$(aws lambda publish-version \
--function-name $PROJECT_NAME \
--description $1 \
--region $AWS_REGION \
--query Version \
--output text)
echo published version: $VERSION
echo aws lambda create-alias $1
aws lambda create-alias \
--function-name $PROJECT_NAME \
--name $1 \
--function-version $VERSION \
--region $AWS_REGION
echo aws lambda add-permission
aws lambda add-permission \
--function-name "arn:aws:lambda:$AWS_REGION:$ACCOUNT_ID:function:$PROJECT_NAME:$1" \
--source-arn "arn:aws:execute-api:$AWS_REGION:$ACCOUNT_ID:$API_GATEWAY_ID/*/GET/hello" \
--principal apigateway.amazonaws.com \
--statement-id $1 \
--action lambda:InvokeFunction