@gradientedge/cdk-utils 8.121.0 → 8.123.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/README.md +2 -1
- package/dist/src/lib/aws/common/construct.d.ts +0 -1
- package/dist/src/lib/aws/common/construct.js +6 -13
- package/dist/src/lib/aws/common/stack.js +7 -9
- package/dist/src/lib/aws/common/types.d.ts +2 -8
- package/dist/src/lib/aws/construct/api-to-any-target/main.js +24 -26
- package/dist/src/lib/aws/construct/api-to-eventbridge-target/main.js +85 -103
- package/dist/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.js +94 -120
- package/dist/src/lib/aws/construct/api-to-lambda-target/main.js +8 -10
- package/dist/src/lib/aws/construct/graphql-api-lambda/main.js +7 -3
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/main.js +5 -1
- package/dist/src/lib/aws/construct/lambda-with-iam-access/main.js +5 -1
- package/dist/src/lib/aws/construct/rest-api-lambda/main.js +7 -3
- package/dist/src/lib/aws/construct/rest-api-lambda-with-cache/main.js +5 -1
- package/dist/src/lib/aws/construct/site-with-ecs-backend/main.js +8 -6
- package/dist/src/lib/aws/construct/static-asset-deployment/main.js +5 -1
- package/dist/src/lib/aws/services/api-gateway/main.js +18 -10
- package/dist/src/lib/aws/services/cloudfront/main.js +11 -7
- package/dist/src/lib/aws/services/cloudwatch/logs.js +8 -4
- package/dist/src/lib/aws/services/cloudwatch/main.js +36 -78
- package/dist/src/lib/aws/services/dynamodb/main.js +6 -2
- package/dist/src/lib/aws/services/elastic-container-service/main.js +8 -4
- package/dist/src/lib/aws/services/elastic-file-system/main.js +5 -1
- package/dist/src/lib/aws/services/elasticache/main.js +6 -2
- package/dist/src/lib/aws/services/eventbridge/main.js +8 -4
- package/dist/src/lib/aws/services/lambda/main.js +7 -3
- package/dist/src/lib/aws/services/simple-notification-service/main.js +6 -2
- package/dist/src/lib/aws/services/simple-queue-service/main.js +6 -2
- package/dist/src/lib/aws/services/simple-storage-service/main.js +8 -4
- package/dist/src/lib/aws/services/step-function/main.js +52 -32
- package/dist/src/lib/aws/services/virtual-private-cloud/main.js +8 -4
- package/dist/src/lib/aws/types/index.d.ts +6 -1
- package/dist/src/lib/aws/types/index.js +0 -15
- package/dist/src/lib/aws/utils/index.d.ts +13 -23
- package/dist/src/lib/aws/utils/index.js +37 -46
- package/dist/src/lib/azure/common/construct.d.ts +35 -0
- package/dist/src/lib/azure/common/construct.js +49 -0
- package/dist/src/lib/azure/common/index.d.ts +3 -0
- package/dist/src/lib/azure/common/index.js +19 -0
- package/dist/src/lib/azure/common/stack.d.ts +52 -0
- package/dist/src/lib/azure/common/stack.js +134 -0
- package/dist/src/lib/azure/common/types.d.ts +7 -0
- package/dist/src/lib/azure/index.d.ts +4 -0
- package/dist/src/lib/azure/index.js +20 -0
- package/dist/src/lib/azure/services/index.d.ts +1 -0
- package/dist/src/lib/azure/services/index.js +17 -0
- package/dist/src/lib/azure/services/storage/index.d.ts +2 -0
- package/dist/src/lib/azure/services/storage/index.js +18 -0
- package/dist/src/lib/azure/services/storage/main.d.ts +43 -0
- package/dist/src/lib/azure/services/storage/main.js +124 -0
- package/dist/src/lib/azure/services/storage/types.d.ts +10 -0
- package/dist/src/lib/azure/services/storage/types.js +2 -0
- package/dist/src/lib/azure/types/index.d.ts +3 -0
- package/dist/src/lib/azure/types/index.js +2 -0
- package/dist/src/lib/azure/utils/index.d.ts +3 -0
- package/dist/src/lib/azure/utils/index.js +20 -0
- package/dist/src/lib/common/construct.d.ts +29 -0
- package/dist/src/lib/common/construct.js +8 -0
- package/dist/src/lib/common/index.d.ts +5 -0
- package/dist/src/lib/common/index.js +33 -0
- package/dist/src/lib/common/stack.d.ts +21 -0
- package/dist/src/lib/common/stack.js +8 -0
- package/dist/src/lib/common/types.d.ts +9 -0
- package/dist/src/lib/common/types.js +2 -0
- package/dist/src/lib/common/utils.d.ts +26 -0
- package/dist/src/lib/common/utils.js +34 -0
- package/dist/src/lib/index.d.ts +2 -0
- package/dist/src/lib/index.js +2 -0
- package/package.json +9 -7
- package/setup.js +2 -0
- package/src/lib/aws/common/construct.ts +2 -13
- package/src/lib/aws/common/stack.ts +6 -8
- package/src/lib/aws/common/types.ts +2 -8
- package/src/lib/aws/construct/api-to-any-target/main.ts +25 -27
- package/src/lib/aws/construct/api-to-eventbridge-target/main.ts +85 -103
- package/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.ts +94 -120
- package/src/lib/aws/construct/api-to-lambda-target/main.ts +8 -10
- package/src/lib/aws/construct/graphql-api-lambda/main.ts +4 -3
- package/src/lib/aws/construct/graphql-api-lambda-with-cache/main.ts +2 -1
- package/src/lib/aws/construct/lambda-with-iam-access/main.ts +2 -1
- package/src/lib/aws/construct/rest-api-lambda/main.ts +4 -3
- package/src/lib/aws/construct/rest-api-lambda-with-cache/main.ts +2 -1
- package/src/lib/aws/construct/site-with-ecs-backend/main.ts +8 -9
- package/src/lib/aws/construct/static-asset-deployment/main.ts +2 -1
- package/src/lib/aws/services/api-gateway/main.ts +9 -6
- package/src/lib/aws/services/cloudfront/main.ts +8 -7
- package/src/lib/aws/services/cloudwatch/logs.ts +6 -5
- package/src/lib/aws/services/cloudwatch/main.ts +35 -81
- package/src/lib/aws/services/dynamodb/main.ts +3 -2
- package/src/lib/aws/services/elastic-container-service/main.ts +5 -4
- package/src/lib/aws/services/elastic-file-system/main.ts +2 -1
- package/src/lib/aws/services/elasticache/main.ts +3 -2
- package/src/lib/aws/services/eventbridge/main.ts +5 -4
- package/src/lib/aws/services/lambda/main.ts +4 -3
- package/src/lib/aws/services/simple-notification-service/main.ts +3 -2
- package/src/lib/aws/services/simple-queue-service/main.ts +3 -2
- package/src/lib/aws/services/simple-storage-service/main.ts +5 -4
- package/src/lib/aws/services/step-function/main.ts +17 -16
- package/src/lib/aws/services/virtual-private-cloud/main.ts +5 -4
- package/src/lib/aws/types/index.ts +6 -1
- package/src/lib/aws/utils/index.ts +41 -29
- package/src/lib/azure/common/construct.ts +57 -0
- package/src/lib/azure/common/index.ts +3 -0
- package/src/lib/azure/common/stack.ts +143 -0
- package/src/lib/azure/common/types.ts +8 -0
- package/src/lib/azure/index.ts +4 -0
- package/src/lib/azure/services/index.ts +1 -0
- package/src/lib/azure/services/storage/index.ts +2 -0
- package/src/lib/azure/services/storage/main.ts +134 -0
- package/src/lib/azure/services/storage/types.ts +10 -0
- package/src/lib/azure/types/index.ts +3 -0
- package/src/lib/azure/utils/index.ts +23 -0
- package/src/lib/common/construct.ts +35 -0
- package/src/lib/common/index.ts +18 -0
- package/src/lib/common/stack.ts +26 -0
- package/src/lib/common/types.ts +9 -0
- package/src/lib/common/utils.ts +27 -0
- package/src/lib/index.ts +2 -0
- package/dist/src/lib/aws/types/aws/index.d.ts +0 -6
- package/dist/src/lib/aws/utils/aws/index.d.ts +0 -17
- package/dist/src/lib/aws/utils/aws/index.js +0 -40
- package/src/lib/aws/types/aws/index.ts +0 -6
- package/src/lib/aws/utils/aws/index.ts +0 -41
- /package/dist/src/lib/{aws/types/aws/index.js → azure/common/types.js} +0 -0
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'
|
|
13
13
|
import { Construct } from 'constructs'
|
|
14
14
|
import { CommonConstruct } from '../../common'
|
|
15
|
-
import { ApiToAnyTargetProps, ApiToAnyTargetRestApiResource, ApiToAnyTargetRestApiType } from './types'
|
|
16
15
|
import { ApiToAnyTargetRestApi } from './target'
|
|
16
|
+
import { ApiToAnyTargetProps, ApiToAnyTargetRestApiResource, ApiToAnyTargetRestApiType } from './types'
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @classdesc Provides a construct to create and deploy a shallow API Gateway
|
|
@@ -127,33 +127,31 @@ export class ApiToAnyTarget extends CommonConstruct {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
this.apiToAnyTargetRestApi.api = new RestApi(this, `${this.id}-rest-api`, {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
types: [this.isProductionStage() ? EndpointType.EDGE : EndpointType.REGIONAL],
|
|
154
|
-
},
|
|
155
|
-
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
130
|
+
cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
|
|
131
|
+
defaultCorsPreflightOptions: {
|
|
132
|
+
allowHeaders: Cors.DEFAULT_HEADERS,
|
|
133
|
+
allowMethods: Cors.ALL_METHODS,
|
|
134
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
135
|
+
},
|
|
136
|
+
defaultIntegration: this.apiToAnyTargetRestApi.integration,
|
|
137
|
+
defaultMethodOptions: {
|
|
138
|
+
methodResponses: [this.apiToAnyTargetRestApi.methodResponse, this.apiToAnyTargetRestApi.methodErrorResponse],
|
|
139
|
+
},
|
|
140
|
+
deploy: this.props.api.restApi?.deploy ?? true,
|
|
141
|
+
deployOptions: {
|
|
142
|
+
accessLogDestination: new LogGroupLogDestination(this.apiToAnyTargetRestApi.accessLogGroup),
|
|
143
|
+
accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
|
|
144
|
+
dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
|
|
145
|
+
description: `${this.id} - ${this.props.stage} stage`,
|
|
146
|
+
loggingLevel: MethodLoggingLevel.INFO,
|
|
147
|
+
metricsEnabled: true,
|
|
148
|
+
stageName: this.props.stage,
|
|
149
|
+
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
150
|
+
},
|
|
151
|
+
endpointConfiguration: {
|
|
152
|
+
types: [this.isProductionStage() ? EndpointType.EDGE : EndpointType.REGIONAL],
|
|
156
153
|
},
|
|
154
|
+
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
157
155
|
...this.props.api.restApi,
|
|
158
156
|
})
|
|
159
157
|
this.addCfnOutput(`${this.id}-restApiId`, this.apiToAnyTargetRestApi.api.restApiId)
|
|
@@ -187,12 +187,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
187
187
|
protected createApiToEventBridgeTargetRule() {
|
|
188
188
|
if (this.props.api.useExisting) return
|
|
189
189
|
this.props.event.rule = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
source: ['api-to-eventbridge-target'],
|
|
193
|
-
},
|
|
194
|
-
ruleName: `${this.id}-api-to-eventbridge-target`,
|
|
190
|
+
eventPattern: {
|
|
191
|
+
source: ['api-to-eventbridge-target'],
|
|
195
192
|
},
|
|
193
|
+
ruleName: `${this.id}-api-to-eventbridge-target`,
|
|
196
194
|
...this.props.event.rule,
|
|
197
195
|
}
|
|
198
196
|
this.apiEvent.rule = this.eventManager.createRule(
|
|
@@ -261,12 +259,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
261
259
|
protected createApiToEventBridgeTargetIntegrationResponse() {
|
|
262
260
|
if (!this.props.api.withResource) return
|
|
263
261
|
this.apiToEventBridgeTargetRestApi.integrationResponse = this.props.api.integrationResponse ?? {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
267
|
-
},
|
|
268
|
-
statusCode: '200',
|
|
262
|
+
responseTemplates: {
|
|
263
|
+
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
269
264
|
},
|
|
265
|
+
statusCode: '200',
|
|
270
266
|
}
|
|
271
267
|
}
|
|
272
268
|
|
|
@@ -276,21 +272,19 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
276
272
|
protected createApiToEventBridgeTargetIntegrationErrorResponse() {
|
|
277
273
|
if (!this.props.api.withResource) return
|
|
278
274
|
this.apiToEventBridgeTargetRestApi.integrationErrorResponse = {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
'method.response.header.Content-Type': "'application/json'",
|
|
284
|
-
},
|
|
285
|
-
responseTemplates: {
|
|
286
|
-
'application/json': JSON.stringify({
|
|
287
|
-
message: "$util.escapeJavaScript($input.path('$.errorMessage'))",
|
|
288
|
-
state: 'error',
|
|
289
|
-
}),
|
|
290
|
-
},
|
|
291
|
-
selectionPattern: '^\\[Error\\].*',
|
|
292
|
-
statusCode: '400',
|
|
275
|
+
responseParameters: {
|
|
276
|
+
'method.response.header.Access-Control-Allow-Credentials': "'true'",
|
|
277
|
+
'method.response.header.Access-Control-Allow-Origin': "'*'",
|
|
278
|
+
'method.response.header.Content-Type': "'application/json'",
|
|
293
279
|
},
|
|
280
|
+
responseTemplates: {
|
|
281
|
+
'application/json': JSON.stringify({
|
|
282
|
+
message: "$util.escapeJavaScript($input.path('$.errorMessage'))",
|
|
283
|
+
state: 'error',
|
|
284
|
+
}),
|
|
285
|
+
},
|
|
286
|
+
selectionPattern: '^\\[Error\\].*',
|
|
287
|
+
statusCode: '400',
|
|
294
288
|
...this.props.api.integrationErrorResponse,
|
|
295
289
|
}
|
|
296
290
|
}
|
|
@@ -303,16 +297,14 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
303
297
|
this.apiToEventBridgeTargetRestApi.integration = new Integration({
|
|
304
298
|
integrationHttpMethod: 'POST',
|
|
305
299
|
options: {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
315
|
-
},
|
|
300
|
+
credentialsRole: this.apiToEventBridgeTargetRestApi.role,
|
|
301
|
+
integrationResponses: [
|
|
302
|
+
this.apiToEventBridgeTargetRestApi.integrationResponse,
|
|
303
|
+
this.apiToEventBridgeTargetRestApi.integrationErrorResponse,
|
|
304
|
+
],
|
|
305
|
+
passthroughBehavior: PassthroughBehavior.NEVER,
|
|
306
|
+
requestParameters: this.apiToEventBridgeTargetRestApi.integrationRequestParameters,
|
|
307
|
+
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
316
308
|
...this.props.api.integrationOptions,
|
|
317
309
|
},
|
|
318
310
|
type: IntegrationType.AWS,
|
|
@@ -326,17 +318,15 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
326
318
|
protected createApiToEventBridgeTargetMethodResponse() {
|
|
327
319
|
if (!this.props.api.withResource) return
|
|
328
320
|
this.apiToEventBridgeTargetRestApi.methodResponse = {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
|
|
332
|
-
},
|
|
333
|
-
responseParameters: {
|
|
334
|
-
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
335
|
-
'method.response.header.Access-Control-Allow-Origin': true,
|
|
336
|
-
'method.response.header.Content-Type': true,
|
|
337
|
-
},
|
|
338
|
-
statusCode: '200',
|
|
321
|
+
responseModels: {
|
|
322
|
+
'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
|
|
339
323
|
},
|
|
324
|
+
responseParameters: {
|
|
325
|
+
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
326
|
+
'method.response.header.Access-Control-Allow-Origin': true,
|
|
327
|
+
'method.response.header.Content-Type': true,
|
|
328
|
+
},
|
|
329
|
+
statusCode: '200',
|
|
340
330
|
...this.props.api.methodResponse,
|
|
341
331
|
}
|
|
342
332
|
}
|
|
@@ -347,17 +337,15 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
347
337
|
protected createApiToEventBridgeTargetMethodErrorResponse() {
|
|
348
338
|
if (!this.props.api.withResource) return
|
|
349
339
|
this.apiToEventBridgeTargetRestApi.methodErrorResponse = {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
|
|
353
|
-
},
|
|
354
|
-
responseParameters: {
|
|
355
|
-
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
356
|
-
'method.response.header.Access-Control-Allow-Origin': true,
|
|
357
|
-
'method.response.header.Content-Type': true,
|
|
358
|
-
},
|
|
359
|
-
statusCode: '400',
|
|
340
|
+
responseModels: {
|
|
341
|
+
'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
|
|
360
342
|
},
|
|
343
|
+
responseParameters: {
|
|
344
|
+
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
345
|
+
'method.response.header.Access-Control-Allow-Origin': true,
|
|
346
|
+
'method.response.header.Content-Type': true,
|
|
347
|
+
},
|
|
348
|
+
statusCode: '400',
|
|
361
349
|
...this.props.api.methodErrorResponse,
|
|
362
350
|
}
|
|
363
351
|
}
|
|
@@ -387,36 +375,34 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
387
375
|
}
|
|
388
376
|
|
|
389
377
|
this.apiToEventBridgeTargetRestApi.api = new RestApi(this, `${this.id}-rest-api`, {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
414
|
-
},
|
|
415
|
-
endpointConfiguration: {
|
|
416
|
-
types: [EndpointType.REGIONAL],
|
|
417
|
-
},
|
|
418
|
-
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
378
|
+
cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
|
|
379
|
+
defaultCorsPreflightOptions: {
|
|
380
|
+
allowHeaders: Cors.DEFAULT_HEADERS,
|
|
381
|
+
allowMethods: ['POST'],
|
|
382
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
383
|
+
},
|
|
384
|
+
defaultIntegration: this.apiToEventBridgeTargetRestApi.integration,
|
|
385
|
+
defaultMethodOptions: {
|
|
386
|
+
methodResponses: [
|
|
387
|
+
this.apiToEventBridgeTargetRestApi.methodResponse,
|
|
388
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse,
|
|
389
|
+
],
|
|
390
|
+
},
|
|
391
|
+
deploy: this.props.api.restApi?.deploy ?? true,
|
|
392
|
+
deployOptions: {
|
|
393
|
+
accessLogDestination: new LogGroupLogDestination(this.apiToEventBridgeTargetRestApi.accessLogGroup),
|
|
394
|
+
accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
|
|
395
|
+
dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
|
|
396
|
+
description: `${this.id} - ${this.props.stage} stage`,
|
|
397
|
+
loggingLevel: MethodLoggingLevel.INFO,
|
|
398
|
+
metricsEnabled: true,
|
|
399
|
+
stageName: this.props.stage,
|
|
400
|
+
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
419
401
|
},
|
|
402
|
+
endpointConfiguration: {
|
|
403
|
+
types: [EndpointType.REGIONAL],
|
|
404
|
+
},
|
|
405
|
+
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
420
406
|
...this.props.api.restApi,
|
|
421
407
|
})
|
|
422
408
|
this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId)
|
|
@@ -430,15 +416,13 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
430
416
|
if (!this.props.api.withResource) return
|
|
431
417
|
this.apiToEventBridgeTargetRestApi.responseModel = new Model(this, `${this.id}-response-model`, {
|
|
432
418
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
type: JsonSchemaType.OBJECT,
|
|
441
|
-
},
|
|
419
|
+
contentType: 'application/json',
|
|
420
|
+
modelName: 'ResponseModel',
|
|
421
|
+
schema: {
|
|
422
|
+
properties: { message: { type: JsonSchemaType.STRING } },
|
|
423
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
424
|
+
title: 'pollResponse',
|
|
425
|
+
type: JsonSchemaType.OBJECT,
|
|
442
426
|
},
|
|
443
427
|
...this.props.api.responseModel,
|
|
444
428
|
})
|
|
@@ -451,18 +435,16 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
451
435
|
if (!this.props.api.withResource) return
|
|
452
436
|
this.apiToEventBridgeTargetRestApi.errorResponseModel = new Model(this, `${this.id}-error-response-model`, {
|
|
453
437
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
state: { type: JsonSchemaType.STRING },
|
|
461
|
-
},
|
|
462
|
-
schema: JsonSchemaVersion.DRAFT4,
|
|
463
|
-
title: 'errorResponse',
|
|
464
|
-
type: JsonSchemaType.OBJECT,
|
|
438
|
+
contentType: 'application/json',
|
|
439
|
+
modelName: 'ErrorResponseModel',
|
|
440
|
+
schema: {
|
|
441
|
+
properties: {
|
|
442
|
+
message: { type: JsonSchemaType.STRING },
|
|
443
|
+
state: { type: JsonSchemaType.STRING },
|
|
465
444
|
},
|
|
445
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
446
|
+
title: 'errorResponse',
|
|
447
|
+
type: JsonSchemaType.OBJECT,
|
|
466
448
|
},
|
|
467
449
|
...this.props.api.errorResponseModel,
|
|
468
450
|
})
|
|
@@ -240,10 +240,8 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
240
240
|
this,
|
|
241
241
|
{
|
|
242
242
|
...this.props.lambda.function,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
onSuccess: this.apiDestinedLambda.destinationSuccess,
|
|
246
|
-
},
|
|
243
|
+
onFailure: this.apiDestinedLambda.destinationFailure,
|
|
244
|
+
onSuccess: this.apiDestinedLambda.destinationSuccess,
|
|
247
245
|
},
|
|
248
246
|
this.apiDestinedLambda.role,
|
|
249
247
|
this.apiDestinedLambda.layers,
|
|
@@ -276,9 +274,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
276
274
|
protected createApiDestinationLogGroupSuccess() {
|
|
277
275
|
if (this.props.api.useExisting) return
|
|
278
276
|
this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
|
|
279
|
-
|
|
280
|
-
logGroupName: `/${this.id}/events/api-destination-success`,
|
|
281
|
-
},
|
|
277
|
+
logGroupName: `/${this.id}/events/api-destination-success`,
|
|
282
278
|
...this.props.event.logGroupSuccess,
|
|
283
279
|
})
|
|
284
280
|
}
|
|
@@ -289,20 +285,18 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
289
285
|
protected createApiDestinationRuleSuccess() {
|
|
290
286
|
if (this.props.api.useExisting) return
|
|
291
287
|
this.props.event.ruleSuccess = {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
sourceId: [this.id],
|
|
301
|
-
},
|
|
288
|
+
eventPattern: {
|
|
289
|
+
detail: {
|
|
290
|
+
requestContext: {
|
|
291
|
+
condition: ['Success'],
|
|
292
|
+
},
|
|
293
|
+
responsePayload: {
|
|
294
|
+
source: ['custom:api-destined-lambda'],
|
|
295
|
+
sourceId: [this.id],
|
|
302
296
|
},
|
|
303
297
|
},
|
|
304
|
-
ruleName: `${this.id}-api-destination-success`,
|
|
305
298
|
},
|
|
299
|
+
ruleName: `${this.id}-api-destination-success`,
|
|
306
300
|
...this.props.event.ruleSuccess,
|
|
307
301
|
}
|
|
308
302
|
this.apiEvent.ruleSuccess = this.eventManager.createRule(
|
|
@@ -320,9 +314,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
320
314
|
protected createApiDestinationLogGroupFailure() {
|
|
321
315
|
if (this.props.api.useExisting) return
|
|
322
316
|
this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
|
|
323
|
-
|
|
324
|
-
logGroupName: `/${this.id}/events/api-destination-failure`,
|
|
325
|
-
},
|
|
317
|
+
logGroupName: `/${this.id}/events/api-destination-failure`,
|
|
326
318
|
...this.props.event.logGroupFailure,
|
|
327
319
|
})
|
|
328
320
|
}
|
|
@@ -333,16 +325,14 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
333
325
|
protected createApiDestinationRuleFailure() {
|
|
334
326
|
if (this.props.api.useExisting) return
|
|
335
327
|
this.props.event.ruleFailure = {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
errorType: ['Error'],
|
|
341
|
-
},
|
|
328
|
+
eventPattern: {
|
|
329
|
+
detail: {
|
|
330
|
+
responsePayload: {
|
|
331
|
+
errorType: ['Error'],
|
|
342
332
|
},
|
|
343
333
|
},
|
|
344
|
-
ruleName: `${this.id}-api-destination-failure`,
|
|
345
334
|
},
|
|
335
|
+
ruleName: `${this.id}-api-destination-failure`,
|
|
346
336
|
...this.props.event.ruleFailure,
|
|
347
337
|
}
|
|
348
338
|
this.apiEvent.ruleFailure = this.eventManager.createRule(
|
|
@@ -414,12 +404,10 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
414
404
|
protected createApiDestinedIntegrationResponse() {
|
|
415
405
|
if (!this.props.api.withResource) return
|
|
416
406
|
this.apiDestinedRestApi.integrationResponse = this.props.api.integrationResponse ?? {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
420
|
-
},
|
|
421
|
-
statusCode: '200',
|
|
407
|
+
responseTemplates: {
|
|
408
|
+
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
422
409
|
},
|
|
410
|
+
statusCode: '200',
|
|
423
411
|
}
|
|
424
412
|
}
|
|
425
413
|
|
|
@@ -429,21 +417,19 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
429
417
|
protected createApiDestinedIntegrationErrorResponse() {
|
|
430
418
|
if (!this.props.api.withResource) return
|
|
431
419
|
this.apiDestinedRestApi.integrationErrorResponse = {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
'method.response.header.Content-Type': "'application/json'",
|
|
437
|
-
},
|
|
438
|
-
responseTemplates: {
|
|
439
|
-
'application/json': JSON.stringify({
|
|
440
|
-
message: "$util.escapeJavaScript($input.path('$.errorMessage'))",
|
|
441
|
-
state: 'error',
|
|
442
|
-
}),
|
|
443
|
-
},
|
|
444
|
-
selectionPattern: '^\\[Error\\].*',
|
|
445
|
-
statusCode: '400',
|
|
420
|
+
responseParameters: {
|
|
421
|
+
'method.response.header.Access-Control-Allow-Credentials': "'true'",
|
|
422
|
+
'method.response.header.Access-Control-Allow-Origin': "'*'",
|
|
423
|
+
'method.response.header.Content-Type': "'application/json'",
|
|
446
424
|
},
|
|
425
|
+
responseTemplates: {
|
|
426
|
+
'application/json': JSON.stringify({
|
|
427
|
+
message: "$util.escapeJavaScript($input.path('$.errorMessage'))",
|
|
428
|
+
state: 'error',
|
|
429
|
+
}),
|
|
430
|
+
},
|
|
431
|
+
selectionPattern: '^\\[Error\\].*',
|
|
432
|
+
statusCode: '400',
|
|
447
433
|
...this.props.api.integrationErrorResponse,
|
|
448
434
|
}
|
|
449
435
|
}
|
|
@@ -456,16 +442,14 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
456
442
|
this.apiDestinedRestApi.integration = new Integration({
|
|
457
443
|
integrationHttpMethod: 'POST',
|
|
458
444
|
options: {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
requestTemplates: this.apiDestinedRestApi.integrationRequestTemplates,
|
|
468
|
-
},
|
|
445
|
+
credentialsRole: this.apiDestinedRestApi.role,
|
|
446
|
+
integrationResponses: [
|
|
447
|
+
this.apiDestinedRestApi.integrationResponse,
|
|
448
|
+
this.apiDestinedRestApi.integrationErrorResponse,
|
|
449
|
+
],
|
|
450
|
+
passthroughBehavior: PassthroughBehavior.NEVER,
|
|
451
|
+
requestParameters: this.apiDestinedRestApi.integrationRequestParameters,
|
|
452
|
+
requestTemplates: this.apiDestinedRestApi.integrationRequestTemplates,
|
|
469
453
|
...this.props.api.integrationOptions,
|
|
470
454
|
},
|
|
471
455
|
type: IntegrationType.AWS,
|
|
@@ -479,17 +463,15 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
479
463
|
protected createApiDestinedMethodResponse() {
|
|
480
464
|
if (!this.props.api.withResource) return
|
|
481
465
|
this.apiDestinedRestApi.methodResponse = {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
'method.response.header.Content-Type': true,
|
|
490
|
-
},
|
|
491
|
-
statusCode: '200',
|
|
466
|
+
responseModels: {
|
|
467
|
+
'application/json': this.apiDestinedRestApi.responseModel,
|
|
468
|
+
},
|
|
469
|
+
responseParameters: {
|
|
470
|
+
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
471
|
+
'method.response.header.Access-Control-Allow-Origin': true,
|
|
472
|
+
'method.response.header.Content-Type': true,
|
|
492
473
|
},
|
|
474
|
+
statusCode: '200',
|
|
493
475
|
...this.props.api.methodResponse,
|
|
494
476
|
}
|
|
495
477
|
}
|
|
@@ -500,17 +482,15 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
500
482
|
protected createApiDestinedMethodErrorResponse() {
|
|
501
483
|
if (!this.props.api.withResource) return
|
|
502
484
|
this.apiDestinedRestApi.methodErrorResponse = {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
'method.response.header.Content-Type': true,
|
|
511
|
-
},
|
|
512
|
-
statusCode: '400',
|
|
485
|
+
responseModels: {
|
|
486
|
+
'application/json': this.apiDestinedRestApi.errorResponseModel,
|
|
487
|
+
},
|
|
488
|
+
responseParameters: {
|
|
489
|
+
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
490
|
+
'method.response.header.Access-Control-Allow-Origin': true,
|
|
491
|
+
'method.response.header.Content-Type': true,
|
|
513
492
|
},
|
|
493
|
+
statusCode: '400',
|
|
514
494
|
...this.props.api.methodErrorResponse,
|
|
515
495
|
}
|
|
516
496
|
}
|
|
@@ -534,30 +514,28 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
534
514
|
})
|
|
535
515
|
|
|
536
516
|
this.apiDestinedRestApi.api = new RestApi(this, `${this.id}-sns-rest-api`, {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
allowOrigins: Cors.ALL_ORIGINS,
|
|
542
|
-
},
|
|
543
|
-
defaultIntegration: this.apiDestinedRestApi.integration,
|
|
544
|
-
defaultMethodOptions: {
|
|
545
|
-
methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
|
|
546
|
-
},
|
|
547
|
-
deployOptions: {
|
|
548
|
-
accessLogDestination: new LogGroupLogDestination(accessLogGroup),
|
|
549
|
-
accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
|
|
550
|
-
dataTraceEnabled: true,
|
|
551
|
-
description: `${this.id} - ${this.props.stage} stage`,
|
|
552
|
-
loggingLevel: MethodLoggingLevel.INFO,
|
|
553
|
-
metricsEnabled: true,
|
|
554
|
-
stageName: this.props.stage,
|
|
555
|
-
},
|
|
556
|
-
endpointConfiguration: {
|
|
557
|
-
types: [EndpointType.REGIONAL],
|
|
558
|
-
},
|
|
559
|
-
restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
|
|
517
|
+
defaultCorsPreflightOptions: {
|
|
518
|
+
allowHeaders: Cors.DEFAULT_HEADERS,
|
|
519
|
+
allowMethods: ['POST'],
|
|
520
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
560
521
|
},
|
|
522
|
+
defaultIntegration: this.apiDestinedRestApi.integration,
|
|
523
|
+
defaultMethodOptions: {
|
|
524
|
+
methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
|
|
525
|
+
},
|
|
526
|
+
deployOptions: {
|
|
527
|
+
accessLogDestination: new LogGroupLogDestination(accessLogGroup),
|
|
528
|
+
accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
|
|
529
|
+
dataTraceEnabled: true,
|
|
530
|
+
description: `${this.id} - ${this.props.stage} stage`,
|
|
531
|
+
loggingLevel: MethodLoggingLevel.INFO,
|
|
532
|
+
metricsEnabled: true,
|
|
533
|
+
stageName: this.props.stage,
|
|
534
|
+
},
|
|
535
|
+
endpointConfiguration: {
|
|
536
|
+
types: [EndpointType.REGIONAL],
|
|
537
|
+
},
|
|
538
|
+
restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
|
|
561
539
|
...this.props.api,
|
|
562
540
|
})
|
|
563
541
|
this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
|
|
@@ -570,16 +548,14 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
570
548
|
protected createApiDestinedResponseModel() {
|
|
571
549
|
if (!this.props.api.withResource) return
|
|
572
550
|
this.apiDestinedRestApi.responseModel = new Model(this, `${this.id}-response-model`, {
|
|
551
|
+
contentType: 'application/json',
|
|
552
|
+
modelName: 'ResponseModel',
|
|
573
553
|
restApi: this.apiDestinedRestApi.api,
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
schema: JsonSchemaVersion.DRAFT4,
|
|
580
|
-
title: 'pollResponse',
|
|
581
|
-
type: JsonSchemaType.OBJECT,
|
|
582
|
-
},
|
|
554
|
+
schema: {
|
|
555
|
+
properties: { message: { type: JsonSchemaType.STRING } },
|
|
556
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
557
|
+
title: 'pollResponse',
|
|
558
|
+
type: JsonSchemaType.OBJECT,
|
|
583
559
|
},
|
|
584
560
|
...this.props.api.responseModel,
|
|
585
561
|
})
|
|
@@ -591,19 +567,17 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
591
567
|
protected createApiDestinedErrorResponseModel() {
|
|
592
568
|
if (!this.props.api.withResource) return
|
|
593
569
|
this.apiDestinedRestApi.errorResponseModel = new Model(this, `${this.id}-error-response-model`, {
|
|
570
|
+
contentType: 'application/json',
|
|
571
|
+
modelName: 'ErrorResponseModel',
|
|
594
572
|
restApi: this.apiDestinedRestApi.api,
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
properties: {
|
|
600
|
-
message: { type: JsonSchemaType.STRING },
|
|
601
|
-
state: { type: JsonSchemaType.STRING },
|
|
602
|
-
},
|
|
603
|
-
schema: JsonSchemaVersion.DRAFT4,
|
|
604
|
-
title: 'errorResponse',
|
|
605
|
-
type: JsonSchemaType.OBJECT,
|
|
573
|
+
schema: {
|
|
574
|
+
properties: {
|
|
575
|
+
message: { type: JsonSchemaType.STRING },
|
|
576
|
+
state: { type: JsonSchemaType.STRING },
|
|
606
577
|
},
|
|
578
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
579
|
+
title: 'errorResponse',
|
|
580
|
+
type: JsonSchemaType.OBJECT,
|
|
607
581
|
},
|
|
608
582
|
...this.props.api.errorResponseModel,
|
|
609
583
|
})
|
|
@@ -162,16 +162,14 @@ export class ApiToLambdaTarget extends CommonConstruct {
|
|
|
162
162
|
|
|
163
163
|
this.props.api.restApi = {
|
|
164
164
|
...this.props.api.restApi,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
accessLogDestination: new LogGroupLogDestination(accessLogGroup),
|
|
174
|
-
},
|
|
165
|
+
defaultMethodOptions: {
|
|
166
|
+
methodResponses: [
|
|
167
|
+
this.apiToLambdaTargetRestApi.methodResponse,
|
|
168
|
+
this.apiToLambdaTargetRestApi.methodErrorResponse,
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
deployOptions: {
|
|
172
|
+
accessLogDestination: new LogGroupLogDestination(accessLogGroup),
|
|
175
173
|
},
|
|
176
174
|
}
|
|
177
175
|
|