-
Notifications
You must be signed in to change notification settings - Fork 0
/
apigw.yaml
201 lines (180 loc) · 6.11 KB
/
apigw.yaml
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
###############################################################################
#
# Generic Service
#
###############################################################################
Parameters:
NLBEndpoint:
Type: String
VPCEndpoint:
Type: String
NLBID:
Type: String
Resources:
###############################################################################
#
# Log Groups
#
###############################################################################
APILogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: service-consumer-api
RetentionInDays: 1
###############################################################################
#
# Log Groups
#
###############################################################################
VPCLink:
Type: AWS::ApiGateway::VpcLink
Properties:
Description: Created to allow the API Gateway to communicate with the backend services.
Name: servicemesh-demo-vpclink
TargetArns:
- !Ref NLBID
###############################################################################
#
# API
#
###############################################################################
APIGWCloudWatchRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action: 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- >-
arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs
Account:
Type: 'AWS::ApiGateway::Account'
Properties:
CloudWatchRoleArn: !GetAtt APIGWCloudWatchRole.Arn
API:
Type: AWS::ApiGateway::RestApi
DependsOn:
- Account
- VPCLink
Properties:
Name: servicemesh-demo-api
Description: Demo api, exposing both nodejs and crystal services
EndpointConfiguration:
Types:
- PRIVATE
VpcEndpointIds:
- !Ref VPCEndpoint
Policy: !Sub |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:*/*"
},
{
"Effect": "Deny",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:*/*",
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": "${VPCEndpoint}"
}
}
}
]
}
NodeJS:
Type: AWS::ApiGateway::Resource
DependsOn: API
Properties:
ParentId: !GetAtt API.RootResourceId
PathPart: nodejs
RestApiId: !Ref API
Crystal:
Type: AWS::ApiGateway::Resource
DependsOn: API
Properties:
ParentId: !GetAtt API.RootResourceId
PathPart: crystal
RestApiId: !Ref API
GETNodeJS:
Type: AWS::ApiGateway::Method
DependsOn: NodeJS
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
ConnectionId: !Ref VPCLink
ConnectionType: VPC_LINK
IntegrationHttpMethod: GET
IntegrationResponses:
- StatusCode: 200
TimeoutInMillis: 29000
Type: HTTP
Uri: !Sub http://${NLBEndpoint}:3001/
MethodResponses:
- StatusCode: 200
OperationName: nodejs
ResourceId: !Ref NodeJS
RestApiId: !Ref API
GETCrystal:
Type: AWS::ApiGateway::Method
DependsOn: Crystal
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
ConnectionId: !Ref VPCLink
ConnectionType: VPC_LINK
IntegrationHttpMethod: GET
IntegrationResponses:
- StatusCode: 200
TimeoutInMillis: 29000
Type: HTTP
Uri: !Sub http://${NLBEndpoint}:3002/crystal/
MethodResponses:
- StatusCode: 200
OperationName: crystal
ResourceId: !Ref Crystal
RestApiId: !Ref API
Stage:
Type: AWS::ApiGateway::Stage
DependsOn: API
Properties:
AccessLogSetting:
DestinationArn: !GetAtt APILogGroup.Arn
CacheClusterEnabled: false
DeploymentId: !Ref Deployment
Description: default stage for running the api
MethodSettings:
- ResourcePath: /*
HttpMethod: GET
CachingEnabled: false
DataTraceEnabled: true
LoggingLevel: INFO
MetricsEnabled: true
RestApiId: !Ref API
StageName: default
TracingEnabled: true
Deployment:
Type: AWS::ApiGateway::Deployment
DependsOn:
- GETCrystal
- GETNodeJS
Properties:
Description: default deployment
RestApiId: !Ref API
Outputs:
API:
Description: ID of the REST API created by this stack
Value: !Ref API