forked from intoli/intoli-article-materials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-app.sh
115 lines (89 loc) · 3.25 KB
/
deploy-app.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /bin/bash
# Create the initial role.
response="$(aws iam create-role \
--role-name CircleciArtifactsRole \
--assume-role-policy-document file://circleci-artifacts-role-policy-document.json)"
# Echo the response in the terminal.
echo "${response}"
# Store the role ARN for future usage.
role_arn="$(jq -r .Role.Arn <<< "${response}")"
# Attach the policy.
aws iam put-role-policy \
--role-name CircleciArtifactsRole \
--policy-name CircleciArtifactsPolicy \
--policy-document file://circleci-artifacts-policy.json
# Create the lambda function.
response="$(aws lambda create-function \
--function-name CircleciArtifactsFunction \
--zip-file fileb://circleci-artifacts.zip \
--handler lambda.handler \
--runtime nodejs6.10 \
--role "${role_arn}")"
# Echo the response in the terminal.
echo "${response}"
# Store the function ARN for future usage.
function_arn="$(jq -r .FunctionArn <<< "${response}")"
# Create a new API.
response="$(aws apigateway create-rest-api \
--name CircleciArtifactsApi \
--endpoint-configuration types=REGIONAL)"
# Echo the response in the terminal.
echo "${response}"
# Store the API ID for future usage.
api_id="$(jq -r .id <<< "${response}")"
# Fetch the API resources.
response="$(aws apigateway get-resources \
--rest-api-id "${api_id}")"
# Echo the response in the terminal.
echo "${response}"
# Store the root resource ID for future usage.
root_resource_id="$(jq -r .items[0].id <<< "${response}")"
# Create a new API resource.
response="$(aws apigateway create-resource \
--rest-api-id "${api_id}" \
--parent-id "${root_resource_id}" \
--path-part '{proxy+}')"
# Echo the response in the terminal.
echo "${response}"
# Store the proxy resource ID for future usage.
proxy_resource_id="$(jq -r .id <<< "${response}")"
# Allow GET methods on the resource.
aws apigateway put-method \
--rest-api-id "${api_id}" \
--resource-id "${proxy_resource_id}" \
--http-method GET \
--authorization-type NONE
# Integrate the endpoint with the Lambda function.
aws apigateway put-integration \
--rest-api-id "${api_id}" \
--resource-id "${proxy_resource_id}" \
--http-method GET \
--integration-http-method POST \
--type AWS_PROXY \
--uri "arn:aws:apigateway:us-east-2:lambda:path/2015-03-31/functions/${function_arn}/invocations" \
--credentials "${role_arn}"
# Deploy the API.
aws apigateway create-deployment \
--rest-api-id "${api_id}" \
--stage-name v1
# Request a certificate.
response="$(aws acm request-certificate \
--domain-name circleci.example.com \
--validation-method DNS \
--idempotency-token 1111)"
# Echo the response in the terminal.
echo "${response}"
# Store the certificate ID for future usage.
certificate_arn="$(jq -r .CertificateArn <<< "${response}")"
echo NOTE: You must actually verify your domain ownership before doing the next steps, exiting...
exit 0
# Create an API Gateway domain name.
aws apigateway create-domain-name \
--domain-name circleci.example.com \
--endpoint-configuration types=REGIONAL \
--regional-certificate-arn "${certificate_arn}"
# Map the domain to the API.
aws apigateway create-base-path-mapping \
--domain-name circleci.example.com \
--rest-api-id "${api_id}" \
--stage v1