@gradientedge/cdk-utils 5.14.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/lib/construct/api-to-eventbridge-target/index.d.ts +0 -3
- package/dist/src/lib/construct/api-to-eventbridge-target/index.js +0 -3
- package/dist/src/lib/construct/api-to-eventbridge-target/main.d.ts +23 -68
- package/dist/src/lib/construct/api-to-eventbridge-target/main.js +120 -241
- package/dist/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.d.ts +1 -1
- package/dist/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.js +1 -1
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/index.d.ts +2 -0
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/index.js +18 -0
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.d.ts +193 -0
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.js +631 -0
- package/dist/src/lib/construct/index.d.ts +1 -0
- package/dist/src/lib/construct/index.js +1 -0
- package/dist/src/lib/{construct/api-to-eventbridge-target/api-destination-event.d.ts → helper/api-to-eventbridge-target-event.d.ts} +5 -3
- package/dist/src/lib/{construct/api-to-eventbridge-target/api-destination-event.js → helper/api-to-eventbridge-target-event.js} +6 -4
- package/dist/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.d.ts → helper/api-to-eventbridge-target-rest-api.d.ts} +4 -4
- package/dist/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.js → helper/api-to-eventbridge-target-rest-api.js} +5 -5
- package/dist/src/lib/helper/index.d.ts +2 -0
- package/dist/src/lib/helper/index.js +18 -0
- package/dist/src/lib/types/aws/index.d.ts +10 -5
- package/package.json +1 -1
- package/src/lib/construct/api-to-eventbridge-target/index.ts +0 -3
- package/src/lib/construct/api-to-eventbridge-target/main.ts +127 -278
- package/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.ts +1 -1
- package/src/lib/construct/api-to-eventbridge-target-with-sns/index.ts +2 -0
- package/src/lib/construct/api-to-eventbridge-target-with-sns/main.ts +703 -0
- package/src/lib/construct/index.ts +1 -0
- package/src/lib/{construct/api-to-eventbridge-target/api-destination-event.ts → helper/api-to-eventbridge-target-event.ts} +5 -3
- package/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.ts → helper/api-to-eventbridge-target-rest-api.ts} +4 -4
- package/src/lib/helper/index.ts +2 -0
- package/src/lib/types/aws/index.ts +10 -5
|
@@ -3,15 +3,11 @@ import * as apig from 'aws-cdk-lib/aws-apigateway'
|
|
|
3
3
|
import * as events from 'aws-cdk-lib/aws-events'
|
|
4
4
|
import * as eventstargets from 'aws-cdk-lib/aws-events-targets'
|
|
5
5
|
import * as iam from 'aws-cdk-lib/aws-iam'
|
|
6
|
-
import * as lambda from 'aws-cdk-lib/aws-lambda'
|
|
7
|
-
import * as destinations from 'aws-cdk-lib/aws-lambda-destinations'
|
|
8
6
|
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
|
|
9
7
|
import { Construct } from 'constructs'
|
|
10
8
|
import { CommonConstruct } from '../../common'
|
|
11
|
-
import * as
|
|
12
|
-
import
|
|
13
|
-
import { ApiDestinedLambda } from './api-destined-lambda'
|
|
14
|
-
import { ApiDestinedRestApi } from './api-destined-rest-api'
|
|
9
|
+
import * as helper from '../../helper'
|
|
10
|
+
import * as types from '../../types/aws'
|
|
15
11
|
|
|
16
12
|
/**
|
|
17
13
|
* @stability stable
|
|
@@ -42,14 +38,11 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
42
38
|
/* application related resources */
|
|
43
39
|
applicationSecrets: secretsmanager.ISecret[]
|
|
44
40
|
|
|
45
|
-
/* destined lambda related resources */
|
|
46
|
-
apiDestinedLambda: types.ApiDestinedLambdaType
|
|
47
|
-
|
|
48
41
|
/* event related resources */
|
|
49
|
-
apiEvent: types.
|
|
42
|
+
apiEvent: types.ApiToEventBridgeTargetEventType
|
|
50
43
|
|
|
51
44
|
/* rest restApi related resources */
|
|
52
|
-
|
|
45
|
+
apiToEventBridgeTargetRestApi: types.ApiToEventBridgeTargetRestApiType
|
|
53
46
|
apiResource: string
|
|
54
47
|
|
|
55
48
|
constructor(parent: Construct, id: string, props: types.ApiToEventBridgeTargetProps) {
|
|
@@ -58,9 +51,8 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
58
51
|
this.props = props
|
|
59
52
|
this.id = id
|
|
60
53
|
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this.apiDestinedRestApi = new ApiDestinedRestApi()
|
|
54
|
+
this.apiEvent = new helper.ApiToEventbridgeTargetEvent()
|
|
55
|
+
this.apiToEventBridgeTargetRestApi = new helper.ApiToEventbridgeTargetRestApi()
|
|
64
56
|
this.apiResource = 'notify'
|
|
65
57
|
}
|
|
66
58
|
|
|
@@ -73,37 +65,27 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
73
65
|
this.resolveCertificate()
|
|
74
66
|
|
|
75
67
|
/* optional custom event bus */
|
|
76
|
-
this.
|
|
77
|
-
|
|
78
|
-
/* destined lambda related resources */
|
|
79
|
-
this.createApiDestinedLambdaPolicy()
|
|
80
|
-
this.createApiDestinedLambdaRole()
|
|
81
|
-
this.createApiDestinedLambdaEnvironment()
|
|
82
|
-
this.createApiDestinedLambdaLayers()
|
|
83
|
-
this.createApiDestinedLambdaDestinations()
|
|
84
|
-
this.createApiDestinedLambdaFunction()
|
|
68
|
+
this.createApiToEventBridgeTargetEventBus()
|
|
85
69
|
|
|
86
70
|
/* event related resources */
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
71
|
+
this.createApiToEventBridgeTargetLogGroup()
|
|
72
|
+
this.createApiToEventBridgeTargetRule()
|
|
73
|
+
this.createApiToEventBridgeTargetPolicy()
|
|
74
|
+
this.createApiToEventBridgeTargetRole()
|
|
91
75
|
|
|
92
76
|
/* restApi related resources */
|
|
93
|
-
this.
|
|
94
|
-
this.
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
104
|
-
this.
|
|
105
|
-
this.createApiDestinedMethodErrorResponse()
|
|
106
|
-
this.createApiDestinedResourceMethod()
|
|
77
|
+
this.createApiToEventBridgeTargetIntegrationRequestParameters()
|
|
78
|
+
this.createApiToEventBridgeTargetIntegrationRequestTemplates()
|
|
79
|
+
this.createApiToEventBridgeTargetIntegrationResponse()
|
|
80
|
+
this.createApiToEventBridgeTargetIntegrationErrorResponse()
|
|
81
|
+
this.createApiToEventBridgeTargetIntegration()
|
|
82
|
+
this.createApiToEventBridgeTargetRestApi()
|
|
83
|
+
this.createApiToEventBridgeTargetResource()
|
|
84
|
+
this.createApiToEventBridgeTargetResponseModel()
|
|
85
|
+
this.createApiToEventBridgeTargetErrorResponseModel()
|
|
86
|
+
this.createApiToEventBridgeTargetMethodResponse()
|
|
87
|
+
this.createApiToEventBridgeTargetMethodErrorResponse()
|
|
88
|
+
this.createApiToEventBridgeTargetResourceMethod()
|
|
107
89
|
this.createApiDomain()
|
|
108
90
|
this.createApiBasePathMapping()
|
|
109
91
|
this.createApiRouteAssets()
|
|
@@ -123,7 +105,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
123
105
|
* @protected
|
|
124
106
|
*/
|
|
125
107
|
protected resolveHostedZone() {
|
|
126
|
-
this.
|
|
108
|
+
this.apiToEventBridgeTargetRestApi.hostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(
|
|
127
109
|
`${this.id}-hosted-zone`,
|
|
128
110
|
this,
|
|
129
111
|
this.props.useExistingHostedZone
|
|
@@ -149,7 +131,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
149
131
|
)
|
|
150
132
|
}
|
|
151
133
|
|
|
152
|
-
this.
|
|
134
|
+
this.apiToEventBridgeTargetRestApi.certificate = this.acmManager.resolveCertificate(
|
|
153
135
|
`${this.id}-certificate`,
|
|
154
136
|
this,
|
|
155
137
|
this.props.api.certificate
|
|
@@ -157,124 +139,34 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
157
139
|
}
|
|
158
140
|
|
|
159
141
|
/**
|
|
160
|
-
* @summary Method to create
|
|
161
|
-
* @protected
|
|
162
|
-
*/
|
|
163
|
-
protected createApiDestinedLambdaPolicy() {
|
|
164
|
-
if (this.props.api.useExisting) return
|
|
165
|
-
this.apiDestinedLambda.policy = new iam.PolicyDocument({
|
|
166
|
-
statements: [this.iamManager.statementForReadSecrets(this), this.iamManager.statementForPutEvents()],
|
|
167
|
-
})
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @summary Method to create iam role for Api Destined Lambda function
|
|
172
|
-
* @protected
|
|
173
|
-
*/
|
|
174
|
-
protected createApiDestinedLambdaRole() {
|
|
175
|
-
if (this.props.api.useExisting) return
|
|
176
|
-
this.apiDestinedLambda.role = this.iamManager.createRoleForLambda(
|
|
177
|
-
`${this.id}-lambda-destined-role`,
|
|
178
|
-
this,
|
|
179
|
-
this.apiDestinedLambda.policy
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @summary Method to create environment variables for Api Destined Lambda function
|
|
142
|
+
* @summary Method to create or use an existing eventbus for api payload deliveries
|
|
185
143
|
* @protected
|
|
186
144
|
*/
|
|
187
|
-
protected
|
|
188
|
-
if (this.props.api.useExisting) return
|
|
189
|
-
this.apiDestinedLambda.environment = {
|
|
190
|
-
NODE_ENV: this.props.nodeEnv,
|
|
191
|
-
LOG_LEVEL: this.props.logLevel,
|
|
192
|
-
TZ: this.props.timezone,
|
|
193
|
-
SOURCE_ID: this.id,
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* @summary Method to create layers for Api Destined Lambda function
|
|
199
|
-
* @protected
|
|
200
|
-
*/
|
|
201
|
-
protected createApiDestinedLambdaLayers() {
|
|
202
|
-
if (this.props.api.useExisting) return
|
|
203
|
-
const layers: lambda.LayerVersion[] = []
|
|
204
|
-
if (this.props.lambda.layerSource) {
|
|
205
|
-
layers.push(
|
|
206
|
-
this.lambdaManager.createLambdaLayer(`${this.id}-lambda-destined-layer`, this, this.props.lambda.layerSource)
|
|
207
|
-
)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
this.apiDestinedLambda.layers = layers
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* @summary Method to create destination for Api Destined function
|
|
215
|
-
* @protected
|
|
216
|
-
*/
|
|
217
|
-
protected createApiDestinedLambdaDestinations() {
|
|
218
|
-
if (this.props.api.useExisting) return
|
|
219
|
-
this.apiDestinedLambda.destinationSuccess = new destinations.EventBridgeDestination(this.apiEvent.eventBus)
|
|
220
|
-
this.apiDestinedLambda.destinationFailure = new destinations.EventBridgeDestination(this.apiEvent.eventBus)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* @summary Method to create lambda function for Api Destined
|
|
225
|
-
* @protected
|
|
226
|
-
*/
|
|
227
|
-
protected createApiDestinedLambdaFunction() {
|
|
228
|
-
if (this.props.api.useExisting) return
|
|
229
|
-
if (!this.props.lambda.source) throw 'Api Destined Lambda props undefined'
|
|
230
|
-
|
|
231
|
-
this.apiDestinedLambda.function = this.lambdaManager.createLambdaFunction(
|
|
232
|
-
`${this.id}-lambda-destined`,
|
|
233
|
-
this,
|
|
234
|
-
{
|
|
235
|
-
...this.props.lambda.function,
|
|
236
|
-
...{
|
|
237
|
-
onSuccess: this.apiDestinedLambda.destinationSuccess,
|
|
238
|
-
onFailure: this.apiDestinedLambda.destinationFailure,
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
this.apiDestinedLambda.role,
|
|
242
|
-
this.apiDestinedLambda.layers,
|
|
243
|
-
this.props.lambda.source,
|
|
244
|
-
this.props.lambda.handler ?? 'lambda.handler',
|
|
245
|
-
this.apiDestinedLambda.environment
|
|
246
|
-
)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* @summary Method to create or use an existing eventbus for api destined payload deliveries
|
|
251
|
-
* @protected
|
|
252
|
-
*/
|
|
253
|
-
protected createApiDestinedEventBus() {
|
|
145
|
+
protected createApiToEventBridgeTargetEventBus() {
|
|
254
146
|
if (this.props.api.useExisting) {
|
|
255
147
|
this.apiEvent.eventBus = events.EventBus.fromEventBusName(
|
|
256
148
|
this,
|
|
257
|
-
`${this.id}-
|
|
149
|
+
`${this.id}-event-bus`,
|
|
258
150
|
`${this.props.event.eventBusName}-${this.props.stage}`
|
|
259
151
|
)
|
|
260
152
|
return
|
|
261
153
|
}
|
|
262
|
-
this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-
|
|
154
|
+
this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-event-bus`, this, {
|
|
263
155
|
eventBusName: `${this.props.event.eventBusName}`,
|
|
264
156
|
})
|
|
265
157
|
}
|
|
266
158
|
|
|
267
159
|
/**
|
|
268
|
-
* @summary Method to create a log group for successful api
|
|
160
|
+
* @summary Method to create a log group for successful api payload deliveries
|
|
269
161
|
* @protected
|
|
270
162
|
*/
|
|
271
|
-
protected
|
|
163
|
+
protected createApiToEventBridgeTargetLogGroup() {
|
|
272
164
|
if (this.props.api.useExisting) return
|
|
273
|
-
this.apiEvent.
|
|
165
|
+
this.apiEvent.logGroup = this.logManager.createLogGroup(`${this.id}-log`, this, {
|
|
274
166
|
...{
|
|
275
|
-
logGroupName: `/${this.id}/events/api-
|
|
167
|
+
logGroupName: `/${this.id}/events/api-to-eventbridge-target`,
|
|
276
168
|
},
|
|
277
|
-
...this.props.event.
|
|
169
|
+
...this.props.event.logGroup,
|
|
278
170
|
})
|
|
279
171
|
}
|
|
280
172
|
|
|
@@ -282,111 +174,53 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
282
174
|
* Method to create EventBridge rule with lambda target for success
|
|
283
175
|
* @protected
|
|
284
176
|
*/
|
|
285
|
-
protected
|
|
177
|
+
protected createApiToEventBridgeTargetRule() {
|
|
286
178
|
if (this.props.api.useExisting) return
|
|
287
|
-
this.props.event.
|
|
179
|
+
this.props.event.rule = {
|
|
288
180
|
...{
|
|
289
|
-
ruleName: `${this.id}-api-
|
|
181
|
+
ruleName: `${this.id}-api-to-eventbridge-target`,
|
|
290
182
|
eventPattern: {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
condition: ['Success'],
|
|
294
|
-
},
|
|
295
|
-
responsePayload: {
|
|
296
|
-
source: ['custom:api-destined-lambda'],
|
|
297
|
-
sourceId: [this.id],
|
|
298
|
-
},
|
|
299
|
-
},
|
|
183
|
+
source: ['api-to-eventbridge-target'],
|
|
184
|
+
detailType: ['external-client-event'],
|
|
300
185
|
},
|
|
301
186
|
},
|
|
302
|
-
...this.props.event.
|
|
187
|
+
...this.props.event.rule,
|
|
303
188
|
}
|
|
304
|
-
this.apiEvent.
|
|
305
|
-
`${this.id}-api-
|
|
189
|
+
this.apiEvent.rule = this.eventManager.createRule(
|
|
190
|
+
`${this.id}-api-to-eventbridge-target-rule`,
|
|
306
191
|
this,
|
|
307
|
-
this.props.event.
|
|
192
|
+
this.props.event.rule,
|
|
308
193
|
this.apiEvent.eventBus,
|
|
309
|
-
[new eventstargets.CloudWatchLogGroup(this.apiEvent.
|
|
194
|
+
[new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroup)]
|
|
310
195
|
)
|
|
311
196
|
}
|
|
312
197
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
*/
|
|
317
|
-
protected createApiDestinationLogGroupFailure() {
|
|
318
|
-
if (this.props.api.useExisting) return
|
|
319
|
-
this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
|
|
320
|
-
...{
|
|
321
|
-
logGroupName: `/${this.id}/events/api-destination-failure`,
|
|
322
|
-
},
|
|
323
|
-
...this.props.event.logGroupFailure,
|
|
198
|
+
protected createApiToEventBridgeTargetPolicy() {
|
|
199
|
+
this.apiToEventBridgeTargetRestApi.policy = new iam.PolicyDocument({
|
|
200
|
+
statements: [this.iamManager.statementForPutEvents()],
|
|
324
201
|
})
|
|
325
202
|
}
|
|
326
203
|
|
|
327
204
|
/**
|
|
328
|
-
* Method to create
|
|
205
|
+
* @summary Method to create a role for api integration
|
|
329
206
|
* @protected
|
|
330
207
|
*/
|
|
331
|
-
protected
|
|
332
|
-
if (this.
|
|
333
|
-
this.props.event.ruleFailure = {
|
|
334
|
-
...{
|
|
335
|
-
ruleName: `${this.id}-api-destination-failure`,
|
|
336
|
-
eventPattern: {
|
|
337
|
-
detail: {
|
|
338
|
-
responsePayload: {
|
|
339
|
-
errorType: ['Error'],
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
...this.props.event.ruleFailure,
|
|
345
|
-
}
|
|
346
|
-
this.apiEvent.ruleFailure = this.eventManager.createRule(
|
|
347
|
-
`${this.id}-api-destination-rule-failure`,
|
|
348
|
-
this,
|
|
349
|
-
this.props.event.ruleFailure,
|
|
350
|
-
this.apiEvent.eventBus,
|
|
351
|
-
[new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroupFailure)]
|
|
352
|
-
)
|
|
353
|
-
}
|
|
208
|
+
protected createApiToEventBridgeTargetRole() {
|
|
209
|
+
if (!this.apiToEventBridgeTargetRestApi.policy) throw 'Policy undefined'
|
|
354
210
|
|
|
355
|
-
|
|
356
|
-
* @summary Method to create a role for sns topic
|
|
357
|
-
* @protected
|
|
358
|
-
*/
|
|
359
|
-
protected createApiDestinedTopicRole() {
|
|
360
|
-
this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
|
|
211
|
+
this.apiToEventBridgeTargetRestApi.role = new iam.Role(this, `${this.id}-rest-api-role`, {
|
|
361
212
|
assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
|
|
213
|
+
inlinePolicies: { policy: this.apiToEventBridgeTargetRestApi.policy },
|
|
362
214
|
})
|
|
363
215
|
}
|
|
364
216
|
|
|
365
|
-
/**
|
|
366
|
-
* @summary Method to create API destined SNS topic
|
|
367
|
-
* @protected
|
|
368
|
-
*/
|
|
369
|
-
protected createApiDestinedTopic() {
|
|
370
|
-
if (!this.props.api.withResource) return
|
|
371
|
-
this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(
|
|
372
|
-
`${this.id}-destined-topic`,
|
|
373
|
-
this,
|
|
374
|
-
{
|
|
375
|
-
topicName: `${this.id}-destined-topic`,
|
|
376
|
-
},
|
|
377
|
-
this.apiDestinedLambda.function
|
|
378
|
-
)
|
|
379
|
-
|
|
380
|
-
this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole)
|
|
381
|
-
}
|
|
382
|
-
|
|
383
217
|
/**
|
|
384
218
|
* @summary Method to create api integration request parameters
|
|
385
219
|
* @protected
|
|
386
220
|
*/
|
|
387
|
-
protected
|
|
221
|
+
protected createApiToEventBridgeTargetIntegrationRequestParameters() {
|
|
388
222
|
if (!this.props.api.withResource) return
|
|
389
|
-
this.
|
|
223
|
+
this.apiToEventBridgeTargetRestApi.integrationRequestParameters = {
|
|
390
224
|
'integration.request.header.Content-Type': "'application/x-www-form-urlencoded'",
|
|
391
225
|
}
|
|
392
226
|
}
|
|
@@ -395,15 +229,24 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
395
229
|
* @summary Method to create api integration request templates
|
|
396
230
|
* @protected
|
|
397
231
|
*/
|
|
398
|
-
protected
|
|
232
|
+
protected createApiToEventBridgeTargetIntegrationRequestTemplates() {
|
|
399
233
|
if (!this.props.api.withResource) return
|
|
400
|
-
this.
|
|
234
|
+
this.apiToEventBridgeTargetRestApi.integrationRequestTemplates = {
|
|
401
235
|
'application/json': [
|
|
402
|
-
'
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
236
|
+
'#set($context.requestOverride.header.X-Amz-Target = "AWSEvents.PutEvents")',
|
|
237
|
+
'#set($context.requestOverride.header.Content-Type = "application/x-amz-json-1.1")',
|
|
238
|
+
"#set($inputRoot = $input.path('$'))",
|
|
239
|
+
`{
|
|
240
|
+
"Entries": [
|
|
241
|
+
{
|
|
242
|
+
"EventBusName": "${this.apiEvent.eventBus.eventBusName}",
|
|
243
|
+
"Source": "api-to-eventbridge-target",
|
|
244
|
+
"DetailType": "external-client-event",
|
|
245
|
+
"Detail": "$util.escapeJavaScript($input.json('$'))"
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
}`,
|
|
249
|
+
].join('\r'),
|
|
407
250
|
}
|
|
408
251
|
}
|
|
409
252
|
|
|
@@ -411,9 +254,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
411
254
|
* @summary Method to create api integration response
|
|
412
255
|
* @protected
|
|
413
256
|
*/
|
|
414
|
-
protected
|
|
257
|
+
protected createApiToEventBridgeTargetIntegrationResponse() {
|
|
415
258
|
if (!this.props.api.withResource) return
|
|
416
|
-
this.
|
|
259
|
+
this.apiToEventBridgeTargetRestApi.integrationResponse = this.props.api.integrationResponse ?? {
|
|
417
260
|
...{
|
|
418
261
|
statusCode: '200',
|
|
419
262
|
responseTemplates: {
|
|
@@ -427,9 +270,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
427
270
|
* @summary Method to create api integration error response
|
|
428
271
|
* @protected
|
|
429
272
|
*/
|
|
430
|
-
protected
|
|
273
|
+
protected createApiToEventBridgeTargetIntegrationErrorResponse() {
|
|
431
274
|
if (!this.props.api.withResource) return
|
|
432
|
-
this.
|
|
275
|
+
this.apiToEventBridgeTargetRestApi.integrationErrorResponse = {
|
|
433
276
|
...{
|
|
434
277
|
selectionPattern: '^\\[Error\\].*',
|
|
435
278
|
statusCode: '400',
|
|
@@ -453,21 +296,21 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
453
296
|
* @summary Method to create api integration
|
|
454
297
|
* @protected
|
|
455
298
|
*/
|
|
456
|
-
protected
|
|
299
|
+
protected createApiToEventBridgeTargetIntegration() {
|
|
457
300
|
if (!this.props.api.withResource) return
|
|
458
|
-
this.
|
|
301
|
+
this.apiToEventBridgeTargetRestApi.integration = new apig.Integration({
|
|
459
302
|
type: apig.IntegrationType.AWS,
|
|
460
303
|
integrationHttpMethod: 'POST',
|
|
461
|
-
uri: `arn:aws:apigateway:${this.props.region}:
|
|
304
|
+
uri: `arn:aws:apigateway:${this.props.region}:events:path//`,
|
|
462
305
|
options: {
|
|
463
306
|
...{
|
|
464
|
-
credentialsRole: this.
|
|
465
|
-
requestParameters: this.
|
|
466
|
-
requestTemplates: this.
|
|
307
|
+
credentialsRole: this.apiToEventBridgeTargetRestApi.role,
|
|
308
|
+
requestParameters: this.apiToEventBridgeTargetRestApi.integrationRequestParameters,
|
|
309
|
+
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
467
310
|
passthroughBehavior: apig.PassthroughBehavior.NEVER,
|
|
468
311
|
integrationResponses: [
|
|
469
|
-
this.
|
|
470
|
-
this.
|
|
312
|
+
this.apiToEventBridgeTargetRestApi.integrationResponse,
|
|
313
|
+
this.apiToEventBridgeTargetRestApi.integrationErrorResponse,
|
|
471
314
|
],
|
|
472
315
|
},
|
|
473
316
|
...this.props.api.integrationOptions,
|
|
@@ -479,9 +322,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
479
322
|
* @summary Method to create api integration method response
|
|
480
323
|
* @protected
|
|
481
324
|
*/
|
|
482
|
-
protected
|
|
325
|
+
protected createApiToEventBridgeTargetMethodResponse() {
|
|
483
326
|
if (!this.props.api.withResource) return
|
|
484
|
-
this.
|
|
327
|
+
this.apiToEventBridgeTargetRestApi.methodResponse = {
|
|
485
328
|
...{
|
|
486
329
|
statusCode: '200',
|
|
487
330
|
responseParameters: {
|
|
@@ -490,7 +333,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
490
333
|
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
491
334
|
},
|
|
492
335
|
responseModels: {
|
|
493
|
-
'application/json': this.
|
|
336
|
+
'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
|
|
494
337
|
},
|
|
495
338
|
},
|
|
496
339
|
...this.props.api.methodResponse,
|
|
@@ -501,9 +344,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
501
344
|
* @summary Method to create api integration method error response
|
|
502
345
|
* @protected
|
|
503
346
|
*/
|
|
504
|
-
protected
|
|
347
|
+
protected createApiToEventBridgeTargetMethodErrorResponse() {
|
|
505
348
|
if (!this.props.api.withResource) return
|
|
506
|
-
this.
|
|
349
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse = {
|
|
507
350
|
...{
|
|
508
351
|
statusCode: '400',
|
|
509
352
|
responseParameters: {
|
|
@@ -512,7 +355,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
512
355
|
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
513
356
|
},
|
|
514
357
|
responseModels: {
|
|
515
|
-
'application/json': this.
|
|
358
|
+
'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
|
|
516
359
|
},
|
|
517
360
|
},
|
|
518
361
|
...this.props.api.methodErrorResponse,
|
|
@@ -523,26 +366,29 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
523
366
|
* @summary Method to create rest restApi for Api
|
|
524
367
|
* @protected
|
|
525
368
|
*/
|
|
526
|
-
protected
|
|
369
|
+
protected createApiToEventBridgeTargetRestApi() {
|
|
527
370
|
if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
|
|
528
|
-
this.
|
|
371
|
+
this.apiToEventBridgeTargetRestApi.api = apig.RestApi.fromRestApiId(
|
|
529
372
|
this,
|
|
530
|
-
`${this.id}-
|
|
373
|
+
`${this.id}-rest-api`,
|
|
531
374
|
cdk.Fn.importValue(this.props.api.importedRestApiRef)
|
|
532
375
|
)
|
|
533
376
|
return
|
|
534
377
|
}
|
|
535
378
|
|
|
536
|
-
const accessLogGroup = this.logManager.createLogGroup(`${this.id}-
|
|
537
|
-
logGroupName: `/custom/api/${this.id}-
|
|
379
|
+
const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
|
|
380
|
+
logGroupName: `/custom/api/${this.id}-rest-api-access-${this.props.stage}`,
|
|
538
381
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
539
382
|
})
|
|
540
383
|
|
|
541
|
-
this.
|
|
384
|
+
this.apiToEventBridgeTargetRestApi.api = new apig.RestApi(this, `${this.id}-rest-api`, {
|
|
542
385
|
...{
|
|
543
|
-
defaultIntegration: this.
|
|
386
|
+
defaultIntegration: this.apiToEventBridgeTargetRestApi.integration,
|
|
544
387
|
defaultMethodOptions: {
|
|
545
|
-
methodResponses: [
|
|
388
|
+
methodResponses: [
|
|
389
|
+
this.apiToEventBridgeTargetRestApi.methodResponse,
|
|
390
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse,
|
|
391
|
+
],
|
|
546
392
|
},
|
|
547
393
|
deployOptions: {
|
|
548
394
|
dataTraceEnabled: true,
|
|
@@ -561,22 +407,22 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
561
407
|
allowMethods: ['POST'],
|
|
562
408
|
allowHeaders: apig.Cors.DEFAULT_HEADERS,
|
|
563
409
|
},
|
|
564
|
-
restApiName: `${this.id}-
|
|
410
|
+
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
565
411
|
},
|
|
566
412
|
...this.props.api,
|
|
567
413
|
})
|
|
568
|
-
this.addCfnOutput(`${this.id}-restApiId`, this.
|
|
569
|
-
this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.
|
|
414
|
+
this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId)
|
|
415
|
+
this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToEventBridgeTargetRestApi.api.root.resourceId)
|
|
570
416
|
}
|
|
571
417
|
|
|
572
418
|
/**
|
|
573
419
|
* @summary Method to create api integration response model
|
|
574
420
|
* @protected
|
|
575
421
|
*/
|
|
576
|
-
protected
|
|
422
|
+
protected createApiToEventBridgeTargetResponseModel() {
|
|
577
423
|
if (!this.props.api.withResource) return
|
|
578
|
-
this.
|
|
579
|
-
restApi: this.
|
|
424
|
+
this.apiToEventBridgeTargetRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
|
|
425
|
+
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
580
426
|
...{
|
|
581
427
|
contentType: 'application/json',
|
|
582
428
|
modelName: 'ResponseModel',
|
|
@@ -595,10 +441,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
595
441
|
* @summary Method to create api integration error response model
|
|
596
442
|
* @protected
|
|
597
443
|
*/
|
|
598
|
-
protected
|
|
444
|
+
protected createApiToEventBridgeTargetErrorResponseModel() {
|
|
599
445
|
if (!this.props.api.withResource) return
|
|
600
|
-
this.
|
|
601
|
-
restApi: this.
|
|
446
|
+
this.apiToEventBridgeTargetRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
|
|
447
|
+
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
602
448
|
...{
|
|
603
449
|
contentType: 'application/json',
|
|
604
450
|
modelName: 'ErrorResponseModel',
|
|
@@ -620,35 +466,38 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
620
466
|
* @summary Method to create api integration resource
|
|
621
467
|
* @protected
|
|
622
468
|
*/
|
|
623
|
-
protected
|
|
469
|
+
protected createApiToEventBridgeTargetResource() {
|
|
624
470
|
if (!this.props.api.withResource) return
|
|
625
471
|
|
|
626
472
|
let rootResource
|
|
627
473
|
if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
|
|
628
474
|
rootResource = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
|
|
629
475
|
resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
|
|
630
|
-
restApi: this.
|
|
476
|
+
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
631
477
|
path: '/',
|
|
632
478
|
})
|
|
633
479
|
} else {
|
|
634
|
-
rootResource = this.
|
|
480
|
+
rootResource = this.apiToEventBridgeTargetRestApi.api.root
|
|
635
481
|
}
|
|
636
482
|
|
|
637
|
-
this.
|
|
483
|
+
this.apiToEventBridgeTargetRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource)
|
|
638
484
|
}
|
|
639
485
|
|
|
640
486
|
/**
|
|
641
487
|
* @summary Method to create api integration resource method
|
|
642
488
|
* @protected
|
|
643
489
|
*/
|
|
644
|
-
protected
|
|
490
|
+
protected createApiToEventBridgeTargetResourceMethod() {
|
|
645
491
|
if (!this.props.api.withResource) return
|
|
646
|
-
this.
|
|
492
|
+
this.apiToEventBridgeTargetRestApi.method = this.apiToEventBridgeTargetRestApi.resource.addMethod(
|
|
647
493
|
'POST',
|
|
648
|
-
this.
|
|
494
|
+
this.apiToEventBridgeTargetRestApi.integration,
|
|
649
495
|
{
|
|
650
|
-
authorizer: this.
|
|
651
|
-
methodResponses: [
|
|
496
|
+
authorizer: this.apiToEventBridgeTargetRestApi.authoriser,
|
|
497
|
+
methodResponses: [
|
|
498
|
+
this.apiToEventBridgeTargetRestApi.methodResponse,
|
|
499
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse,
|
|
500
|
+
],
|
|
652
501
|
}
|
|
653
502
|
)
|
|
654
503
|
}
|
|
@@ -659,13 +508,13 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
659
508
|
*/
|
|
660
509
|
protected createApiDomain() {
|
|
661
510
|
if (this.props.api.useExisting) return
|
|
662
|
-
this.
|
|
511
|
+
this.apiToEventBridgeTargetRestApi.domain = this.apiManager.createApiDomain(
|
|
663
512
|
`${this.id}-api-domain`,
|
|
664
513
|
this,
|
|
665
514
|
this.isProductionStage() || this.props.skipStageForARecords
|
|
666
515
|
? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
|
|
667
516
|
: `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`,
|
|
668
|
-
this.
|
|
517
|
+
this.apiToEventBridgeTargetRestApi.certificate
|
|
669
518
|
)
|
|
670
519
|
}
|
|
671
520
|
|
|
@@ -677,9 +526,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
677
526
|
if (this.props.api.useExisting) return
|
|
678
527
|
new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
|
|
679
528
|
basePath: '',
|
|
680
|
-
domainName: this.
|
|
681
|
-
restApi: this.
|
|
682
|
-
stage: this.
|
|
529
|
+
domainName: this.apiToEventBridgeTargetRestApi.domain,
|
|
530
|
+
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
531
|
+
stage: this.apiToEventBridgeTargetRestApi.api.deploymentStage,
|
|
683
532
|
})
|
|
684
533
|
}
|
|
685
534
|
|
|
@@ -693,8 +542,8 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
693
542
|
`${this.id}-custom-domain-a-record`,
|
|
694
543
|
this,
|
|
695
544
|
this.props.apiSubDomain,
|
|
696
|
-
this.
|
|
697
|
-
this.
|
|
545
|
+
this.apiToEventBridgeTargetRestApi.domain,
|
|
546
|
+
this.apiToEventBridgeTargetRestApi.hostedZone,
|
|
698
547
|
this.props.skipStageForARecords
|
|
699
548
|
)
|
|
700
549
|
}
|