@gradientedge/cdk-utils 8.118.0 → 8.119.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/app/api-destined-function/package.json +1 -1
- package/dist/src/lib/common/construct.d.ts +32 -32
- package/dist/src/lib/common/construct.js +36 -59
- package/dist/src/lib/common/stack.d.ts +8 -7
- package/dist/src/lib/common/stack.js +17 -37
- package/dist/src/lib/common/types.d.ts +2 -2
- package/dist/src/lib/construct/api-to-eventbridge-target/api.d.ts +22 -22
- package/dist/src/lib/construct/api-to-eventbridge-target/event.d.ts +9 -9
- package/dist/src/lib/construct/api-to-eventbridge-target/main.d.ts +3 -3
- package/dist/src/lib/construct/api-to-eventbridge-target/main.js +37 -60
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.d.ts +9 -9
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.d.ts +3 -3
- package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.js +40 -63
- package/dist/src/lib/construct/api-to-lambda-target/api.d.ts +23 -23
- package/dist/src/lib/construct/api-to-lambda-target/main.d.ts +2 -2
- package/dist/src/lib/construct/api-to-lambda-target/main.js +15 -38
- package/dist/src/lib/construct/application-configuration/main.d.ts +7 -7
- package/dist/src/lib/construct/application-configuration/main.js +17 -41
- package/dist/src/lib/construct/graphql-api-lambda/main.d.ts +17 -17
- package/dist/src/lib/construct/graphql-api-lambda/main.js +6 -29
- package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.d.ts +5 -5
- package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.js +7 -7
- package/dist/src/lib/construct/lambda-with-iam-access/main.d.ts +16 -16
- package/dist/src/lib/construct/lambda-with-iam-access/main.js +8 -31
- package/dist/src/lib/construct/lambda-with-iam-access/types.d.ts +4 -4
- package/dist/src/lib/construct/rest-api-lambda/main.d.ts +16 -16
- package/dist/src/lib/construct/rest-api-lambda/main.js +5 -28
- package/dist/src/lib/construct/rest-api-lambda-with-cache/main.d.ts +5 -5
- package/dist/src/lib/construct/rest-api-lambda-with-cache/main.js +9 -32
- package/dist/src/lib/construct/site-with-ecs-backend/main.d.ts +38 -39
- package/dist/src/lib/construct/site-with-ecs-backend/main.js +33 -54
- package/dist/src/lib/construct/static-asset-deployment/main.d.ts +4 -4
- package/dist/src/lib/construct/static-asset-deployment/main.js +3 -26
- package/dist/src/lib/construct/static-site/main.d.ts +15 -15
- package/dist/src/lib/construct/static-site/main.js +4 -27
- package/dist/src/lib/services/aws/api-gateway/main.d.ts +10 -10
- package/dist/src/lib/services/aws/api-gateway/main.js +21 -44
- package/dist/src/lib/services/aws/api-gateway/types.d.ts +2 -2
- package/dist/src/lib/services/aws/appconfig/main.d.ts +7 -7
- package/dist/src/lib/services/aws/appconfig/main.js +14 -37
- package/dist/src/lib/services/aws/certificate-manager/main.d.ts +5 -5
- package/dist/src/lib/services/aws/certificate-manager/main.js +10 -33
- package/dist/src/lib/services/aws/certificate-manager/types.d.ts +2 -2
- package/dist/src/lib/services/aws/cloudfront/main.d.ts +18 -18
- package/dist/src/lib/services/aws/cloudfront/main.js +46 -45
- package/dist/src/lib/services/aws/cloudfront/types.d.ts +2 -3
- package/dist/src/lib/services/aws/cloudtrail/main.d.ts +5 -5
- package/dist/src/lib/services/aws/cloudtrail/main.js +5 -28
- package/dist/src/lib/services/aws/codebuild/main.d.ts +3 -3
- package/dist/src/lib/services/aws/codebuild/main.js +7 -30
- package/dist/src/lib/services/aws/dynamodb/main.d.ts +3 -3
- package/dist/src/lib/services/aws/dynamodb/main.js +8 -31
- package/dist/src/lib/services/aws/elastic-container-registry/main.d.ts +2 -2
- package/dist/src/lib/services/aws/elastic-container-registry/main.js +4 -27
- package/dist/src/lib/services/aws/elastic-container-service/main.d.ts +10 -10
- package/dist/src/lib/services/aws/elastic-container-service/main.js +27 -50
- package/dist/src/lib/services/aws/elastic-container-service/types.d.ts +4 -4
- package/dist/src/lib/services/aws/elastic-file-system/main.d.ts +3 -3
- package/dist/src/lib/services/aws/elastic-file-system/main.js +12 -35
- package/dist/src/lib/services/aws/elastic-kubernetes-service/main.d.ts +4 -4
- package/dist/src/lib/services/aws/elastic-kubernetes-service/main.js +8 -31
- package/dist/src/lib/services/aws/elasticache/main.d.ts +4 -4
- package/dist/src/lib/services/aws/elasticache/main.js +10 -33
- package/dist/src/lib/services/aws/eventbridge/main.d.ts +13 -13
- package/dist/src/lib/services/aws/eventbridge/main.js +26 -49
- package/dist/src/lib/services/aws/eventbridge/target.d.ts +10 -10
- package/dist/src/lib/services/aws/eventbridge/target.js +6 -29
- package/dist/src/lib/services/aws/evidently/main.d.ts +7 -7
- package/dist/src/lib/services/aws/evidently/main.js +18 -41
- package/dist/src/lib/services/aws/identity-access-management/main.d.ts +48 -49
- package/dist/src/lib/services/aws/identity-access-management/main.js +110 -133
- package/dist/src/lib/services/aws/key-management-service/main.d.ts +2 -2
- package/dist/src/lib/services/aws/key-management-service/main.js +5 -28
- package/dist/src/lib/services/aws/lambda/main.d.ts +11 -13
- package/dist/src/lib/services/aws/lambda/main.js +31 -58
- package/dist/src/lib/services/aws/route53/main.d.ts +9 -9
- package/dist/src/lib/services/aws/route53/main.js +21 -44
- package/dist/src/lib/services/aws/secrets-manager/main.d.ts +5 -6
- package/dist/src/lib/services/aws/secrets-manager/main.js +10 -33
- package/dist/src/lib/services/aws/simple-notification-service/main.d.ts +4 -4
- package/dist/src/lib/services/aws/simple-notification-service/main.js +11 -34
- package/dist/src/lib/services/aws/simple-queue-service/main.d.ts +6 -7
- package/dist/src/lib/services/aws/simple-queue-service/main.js +15 -38
- package/dist/src/lib/services/aws/simple-storage-service/main.d.ts +10 -11
- package/dist/src/lib/services/aws/simple-storage-service/main.js +31 -54
- package/dist/src/lib/services/aws/step-function/main.d.ts +31 -32
- package/dist/src/lib/services/aws/step-function/main.js +33 -57
- package/dist/src/lib/services/aws/systems-manager/main.d.ts +4 -4
- package/dist/src/lib/services/aws/systems-manager/main.js +10 -33
- package/dist/src/lib/services/aws/virtual-private-cloud/main.d.ts +5 -6
- package/dist/src/lib/services/aws/virtual-private-cloud/main.js +14 -37
- package/dist/src/lib/services/aws/web-application-firewall/main.d.ts +3 -3
- package/dist/src/lib/services/aws/web-application-firewall/main.js +8 -31
- package/dist/src/lib/utils/aws/index.d.ts +6 -3
- package/dist/src/lib/utils/aws/index.js +9 -26
- package/package.json +15 -15
- package/src/lib/common/construct.ts +97 -67
- package/src/lib/common/stack.ts +12 -12
- package/src/lib/common/types.ts +2 -2
- package/src/lib/construct/api-to-eventbridge-target/api.ts +31 -22
- package/src/lib/construct/api-to-eventbridge-target/event.ts +9 -9
- package/src/lib/construct/api-to-eventbridge-target/main.ts +56 -41
- package/src/lib/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.ts +9 -9
- package/src/lib/construct/api-to-eventbridge-target-with-sns/main.ts +62 -47
- package/src/lib/construct/api-to-lambda-target/api.ts +33 -23
- package/src/lib/construct/api-to-lambda-target/main.ts +24 -18
- package/src/lib/construct/application-configuration/main.ts +31 -24
- package/src/lib/construct/graphql-api-lambda/main.ts +22 -22
- package/src/lib/construct/graphql-api-lambda-with-cache/main.ts +13 -13
- package/src/lib/construct/lambda-with-iam-access/main.ts +25 -25
- package/src/lib/construct/lambda-with-iam-access/types.ts +4 -4
- package/src/lib/construct/rest-api-lambda/main.ts +21 -21
- package/src/lib/construct/rest-api-lambda-with-cache/main.ts +14 -14
- package/src/lib/construct/site-with-ecs-backend/main.ts +79 -60
- package/src/lib/construct/static-asset-deployment/main.ts +6 -6
- package/src/lib/construct/static-site/main.ts +23 -17
- package/src/lib/services/aws/api-gateway/main.ts +42 -36
- package/src/lib/services/aws/api-gateway/types.ts +2 -2
- package/src/lib/services/aws/appconfig/main.ts +19 -19
- package/src/lib/services/aws/certificate-manager/main.ts +14 -14
- package/src/lib/services/aws/certificate-manager/types.ts +2 -2
- package/src/lib/services/aws/cloudfront/main.ts +88 -74
- package/src/lib/services/aws/cloudfront/types.ts +6 -3
- package/src/lib/services/aws/cloudtrail/main.ts +11 -11
- package/src/lib/services/aws/codebuild/main.ts +7 -7
- package/src/lib/services/aws/dynamodb/main.ts +8 -8
- package/src/lib/services/aws/elastic-container-registry/main.ts +4 -4
- package/src/lib/services/aws/elastic-container-service/main.ts +48 -37
- package/src/lib/services/aws/elastic-container-service/types.ts +4 -4
- package/src/lib/services/aws/elastic-file-system/main.ts +16 -16
- package/src/lib/services/aws/elastic-kubernetes-service/main.ts +11 -11
- package/src/lib/services/aws/elasticache/main.ts +10 -10
- package/src/lib/services/aws/eventbridge/main.ts +37 -37
- package/src/lib/services/aws/eventbridge/target.ts +14 -14
- package/src/lib/services/aws/evidently/main.ts +18 -18
- package/src/lib/services/aws/identity-access-management/main.ts +142 -134
- package/src/lib/services/aws/key-management-service/main.ts +5 -5
- package/src/lib/services/aws/lambda/main.ts +65 -59
- package/src/lib/services/aws/route53/main.ts +31 -31
- package/src/lib/services/aws/secrets-manager/main.ts +11 -15
- package/src/lib/services/aws/simple-notification-service/main.ts +13 -13
- package/src/lib/services/aws/simple-queue-service/main.ts +18 -18
- package/src/lib/services/aws/simple-storage-service/main.ts +40 -40
- package/src/lib/services/aws/step-function/main.ts +77 -65
- package/src/lib/services/aws/systems-manager/main.ts +17 -12
- package/src/lib/services/aws/virtual-private-cloud/main.ts +16 -16
- package/src/lib/services/aws/web-application-firewall/main.ts +8 -8
- package/src/lib/utils/aws/index.ts +8 -5
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Fn, RemovalPolicy } from 'aws-cdk-lib'
|
|
2
|
+
import {
|
|
3
|
+
AccessLogFormat,
|
|
4
|
+
BasePathMapping,
|
|
5
|
+
Cors,
|
|
6
|
+
EndpointType,
|
|
7
|
+
Integration,
|
|
8
|
+
IntegrationType,
|
|
9
|
+
JsonSchemaType,
|
|
10
|
+
JsonSchemaVersion,
|
|
11
|
+
LogGroupLogDestination,
|
|
12
|
+
MethodLoggingLevel,
|
|
13
|
+
Model,
|
|
14
|
+
PassthroughBehavior,
|
|
15
|
+
Resource,
|
|
16
|
+
RestApi,
|
|
17
|
+
} from 'aws-cdk-lib/aws-apigateway'
|
|
18
|
+
import { EventBus } from 'aws-cdk-lib/aws-events'
|
|
19
|
+
import { CloudWatchLogGroup } from 'aws-cdk-lib/aws-events-targets'
|
|
20
|
+
import { PolicyDocument, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'
|
|
21
|
+
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'
|
|
7
22
|
import { Construct } from 'constructs'
|
|
8
23
|
import { CommonConstruct } from '../../common'
|
|
24
|
+
import { ApiToEventbridgeTargetRestApi } from './api'
|
|
25
|
+
import { ApiToEventbridgeTargetEvent } from './event'
|
|
9
26
|
import {
|
|
10
27
|
ApiToEventBridgeTargetEventType,
|
|
11
28
|
ApiToEventBridgeTargetProps,
|
|
12
29
|
ApiToEventBridgeTargetRestApiType,
|
|
13
30
|
} from './types'
|
|
14
|
-
import { ApiToEventbridgeTargetEvent } from './event'
|
|
15
|
-
import { ApiToEventbridgeTargetRestApi } from './api'
|
|
16
31
|
|
|
17
32
|
/**
|
|
18
33
|
* @classdesc Provides a construct to create and deploy API Gateway invocations to EventBridge
|
|
@@ -36,7 +51,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
36
51
|
id: string
|
|
37
52
|
|
|
38
53
|
/* application related resources */
|
|
39
|
-
applicationSecrets:
|
|
54
|
+
applicationSecrets: ISecret[]
|
|
40
55
|
|
|
41
56
|
/* event related resources */
|
|
42
57
|
apiEvent: ApiToEventBridgeTargetEventType
|
|
@@ -137,11 +152,11 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
137
152
|
}
|
|
138
153
|
|
|
139
154
|
/**
|
|
140
|
-
* @summary Method to create or use an existing
|
|
155
|
+
* @summary Method to create or use an existing event bus for api payload deliveries
|
|
141
156
|
*/
|
|
142
157
|
protected createApiToEventBridgeTargetEventBus() {
|
|
143
158
|
if (this.props.api.useExisting) {
|
|
144
|
-
this.apiEvent.eventBus =
|
|
159
|
+
this.apiEvent.eventBus = EventBus.fromEventBusName(
|
|
145
160
|
this,
|
|
146
161
|
`${this.id}-event-bus`,
|
|
147
162
|
`${this.props.event.eventBusName}-${this.props.stage}`
|
|
@@ -185,12 +200,12 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
185
200
|
this,
|
|
186
201
|
this.props.event.rule,
|
|
187
202
|
this.apiEvent.eventBus,
|
|
188
|
-
[new
|
|
203
|
+
[new CloudWatchLogGroup(this.apiEvent.logGroup)]
|
|
189
204
|
)
|
|
190
205
|
}
|
|
191
206
|
|
|
192
207
|
protected createApiToEventBridgeTargetPolicy() {
|
|
193
|
-
this.apiToEventBridgeTargetRestApi.policy = new
|
|
208
|
+
this.apiToEventBridgeTargetRestApi.policy = new PolicyDocument({
|
|
194
209
|
statements: [this.iamManager.statementForPutEvents()],
|
|
195
210
|
})
|
|
196
211
|
}
|
|
@@ -201,8 +216,8 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
201
216
|
protected createApiToEventBridgeTargetRole() {
|
|
202
217
|
if (!this.apiToEventBridgeTargetRestApi.policy) throw 'Policy undefined'
|
|
203
218
|
|
|
204
|
-
this.apiToEventBridgeTargetRestApi.role = new
|
|
205
|
-
assumedBy: new
|
|
219
|
+
this.apiToEventBridgeTargetRestApi.role = new Role(this, `${this.id}-rest-api-role`, {
|
|
220
|
+
assumedBy: new ServicePrincipal('apigateway.amazonaws.com'),
|
|
206
221
|
inlinePolicies: { policy: this.apiToEventBridgeTargetRestApi.policy },
|
|
207
222
|
})
|
|
208
223
|
}
|
|
@@ -224,7 +239,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
224
239
|
if (!this.props.api.withResource) return
|
|
225
240
|
this.apiToEventBridgeTargetRestApi.integrationRequestTemplates = {
|
|
226
241
|
'application/json': [
|
|
227
|
-
'#set($context.requestOverride.header.X-Amz-Target = "
|
|
242
|
+
'#set($context.requestOverride.header.X-Amz-Target = "AWSPutEvents")',
|
|
228
243
|
'#set($context.requestOverride.header.Content-Type = "application/x-amz-json-1.1")',
|
|
229
244
|
`{
|
|
230
245
|
"Entries": [
|
|
@@ -285,7 +300,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
285
300
|
*/
|
|
286
301
|
protected createApiToEventBridgeTargetIntegration() {
|
|
287
302
|
if (!this.props.api.withResource) return
|
|
288
|
-
this.apiToEventBridgeTargetRestApi.integration = new
|
|
303
|
+
this.apiToEventBridgeTargetRestApi.integration = new Integration({
|
|
289
304
|
integrationHttpMethod: 'POST',
|
|
290
305
|
options: {
|
|
291
306
|
...{
|
|
@@ -294,13 +309,13 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
294
309
|
this.apiToEventBridgeTargetRestApi.integrationResponse,
|
|
295
310
|
this.apiToEventBridgeTargetRestApi.integrationErrorResponse,
|
|
296
311
|
],
|
|
297
|
-
passthroughBehavior:
|
|
312
|
+
passthroughBehavior: PassthroughBehavior.NEVER,
|
|
298
313
|
requestParameters: this.apiToEventBridgeTargetRestApi.integrationRequestParameters,
|
|
299
314
|
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
300
315
|
},
|
|
301
316
|
...this.props.api.integrationOptions,
|
|
302
317
|
},
|
|
303
|
-
type:
|
|
318
|
+
type: IntegrationType.AWS,
|
|
304
319
|
uri: `arn:aws:apigateway:${this.props.region}:events:path//`,
|
|
305
320
|
})
|
|
306
321
|
}
|
|
@@ -353,7 +368,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
353
368
|
this,
|
|
354
369
|
{
|
|
355
370
|
logGroupName: `/custom/api/${this.id}-rest-api-access`,
|
|
356
|
-
removalPolicy:
|
|
371
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
357
372
|
}
|
|
358
373
|
)
|
|
359
374
|
}
|
|
@@ -363,21 +378,21 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
363
378
|
*/
|
|
364
379
|
protected createApiToEventBridgeTargetRestApi() {
|
|
365
380
|
if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
|
|
366
|
-
this.apiToEventBridgeTargetRestApi.api =
|
|
381
|
+
this.apiToEventBridgeTargetRestApi.api = RestApi.fromRestApiId(
|
|
367
382
|
this,
|
|
368
383
|
`${this.id}-rest-api`,
|
|
369
|
-
|
|
384
|
+
Fn.importValue(this.props.api.importedRestApiRef)
|
|
370
385
|
)
|
|
371
386
|
return
|
|
372
387
|
}
|
|
373
388
|
|
|
374
|
-
this.apiToEventBridgeTargetRestApi.api = new
|
|
389
|
+
this.apiToEventBridgeTargetRestApi.api = new RestApi(this, `${this.id}-rest-api`, {
|
|
375
390
|
...{
|
|
376
391
|
cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
|
|
377
392
|
defaultCorsPreflightOptions: {
|
|
378
|
-
allowHeaders:
|
|
393
|
+
allowHeaders: Cors.DEFAULT_HEADERS,
|
|
379
394
|
allowMethods: ['POST'],
|
|
380
|
-
allowOrigins:
|
|
395
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
381
396
|
},
|
|
382
397
|
defaultIntegration: this.apiToEventBridgeTargetRestApi.integration,
|
|
383
398
|
defaultMethodOptions: {
|
|
@@ -388,17 +403,17 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
388
403
|
},
|
|
389
404
|
deploy: this.props.api.restApi?.deploy ?? true,
|
|
390
405
|
deployOptions: {
|
|
391
|
-
accessLogDestination: new
|
|
392
|
-
accessLogFormat:
|
|
406
|
+
accessLogDestination: new LogGroupLogDestination(this.apiToEventBridgeTargetRestApi.accessLogGroup),
|
|
407
|
+
accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
|
|
393
408
|
dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
|
|
394
409
|
description: `${this.id} - ${this.props.stage} stage`,
|
|
395
|
-
loggingLevel:
|
|
410
|
+
loggingLevel: MethodLoggingLevel.INFO,
|
|
396
411
|
metricsEnabled: true,
|
|
397
412
|
stageName: this.props.stage,
|
|
398
413
|
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
399
414
|
},
|
|
400
415
|
endpointConfiguration: {
|
|
401
|
-
types: [
|
|
416
|
+
types: [EndpointType.REGIONAL],
|
|
402
417
|
},
|
|
403
418
|
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
404
419
|
},
|
|
@@ -413,16 +428,16 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
413
428
|
*/
|
|
414
429
|
protected createApiToEventBridgeTargetResponseModel() {
|
|
415
430
|
if (!this.props.api.withResource) return
|
|
416
|
-
this.apiToEventBridgeTargetRestApi.responseModel = new
|
|
431
|
+
this.apiToEventBridgeTargetRestApi.responseModel = new Model(this, `${this.id}-response-model`, {
|
|
417
432
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
418
433
|
...{
|
|
419
434
|
contentType: 'application/json',
|
|
420
435
|
modelName: 'ResponseModel',
|
|
421
436
|
schema: {
|
|
422
|
-
properties: { message: { type:
|
|
423
|
-
schema:
|
|
437
|
+
properties: { message: { type: JsonSchemaType.STRING } },
|
|
438
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
424
439
|
title: 'pollResponse',
|
|
425
|
-
type:
|
|
440
|
+
type: JsonSchemaType.OBJECT,
|
|
426
441
|
},
|
|
427
442
|
},
|
|
428
443
|
...this.props.api.responseModel,
|
|
@@ -434,19 +449,19 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
434
449
|
*/
|
|
435
450
|
protected createApiToEventBridgeTargetErrorResponseModel() {
|
|
436
451
|
if (!this.props.api.withResource) return
|
|
437
|
-
this.apiToEventBridgeTargetRestApi.errorResponseModel = new
|
|
452
|
+
this.apiToEventBridgeTargetRestApi.errorResponseModel = new Model(this, `${this.id}-error-response-model`, {
|
|
438
453
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
439
454
|
...{
|
|
440
455
|
contentType: 'application/json',
|
|
441
456
|
modelName: 'ErrorResponseModel',
|
|
442
457
|
schema: {
|
|
443
458
|
properties: {
|
|
444
|
-
message: { type:
|
|
445
|
-
state: { type:
|
|
459
|
+
message: { type: JsonSchemaType.STRING },
|
|
460
|
+
state: { type: JsonSchemaType.STRING },
|
|
446
461
|
},
|
|
447
|
-
schema:
|
|
462
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
448
463
|
title: 'errorResponse',
|
|
449
|
-
type:
|
|
464
|
+
type: JsonSchemaType.OBJECT,
|
|
450
465
|
},
|
|
451
466
|
},
|
|
452
467
|
...this.props.api.errorResponseModel,
|
|
@@ -461,9 +476,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
461
476
|
|
|
462
477
|
let rootResource
|
|
463
478
|
if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
|
|
464
|
-
rootResource =
|
|
479
|
+
rootResource = Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
|
|
465
480
|
path: '/',
|
|
466
|
-
resourceId:
|
|
481
|
+
resourceId: Fn.importValue(this.props.api.importedRestApiRootResourceRef),
|
|
467
482
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
468
483
|
})
|
|
469
484
|
} else {
|
|
@@ -511,7 +526,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
511
526
|
*/
|
|
512
527
|
protected createApiBasePathMapping() {
|
|
513
528
|
if (this.props.api.useExisting) return
|
|
514
|
-
new
|
|
529
|
+
new BasePathMapping(this, `${this.id}-base-bath-mapping`, {
|
|
515
530
|
basePath: '',
|
|
516
531
|
domainName: this.apiToEventBridgeTargetRestApi.domain,
|
|
517
532
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { PolicyDocument, Role } from 'aws-cdk-lib/aws-iam'
|
|
2
|
+
import { IFunction, LayerVersion } from 'aws-cdk-lib/aws-lambda'
|
|
3
|
+
import { EventBridgeDestination } from 'aws-cdk-lib/aws-lambda-destinations'
|
|
4
4
|
import { ApiDestinedLambdaEnvironment, ApiDestinedLambdaType } from './types'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @classdesc Provides a construct to contain lambda resources for ApiToEventBridgeTargetWithSns
|
|
8
8
|
*/
|
|
9
9
|
export class ApiDestinedLambda implements ApiDestinedLambdaType {
|
|
10
|
-
destinationFailure:
|
|
11
|
-
destinationSuccess:
|
|
10
|
+
destinationFailure: EventBridgeDestination
|
|
11
|
+
destinationSuccess: EventBridgeDestination
|
|
12
12
|
environment: ApiDestinedLambdaEnvironment
|
|
13
|
-
function:
|
|
14
|
-
layers:
|
|
15
|
-
policy:
|
|
16
|
-
role:
|
|
13
|
+
function: IFunction
|
|
14
|
+
layers: LayerVersion[]
|
|
15
|
+
policy: PolicyDocument
|
|
16
|
+
role: Role
|
|
17
17
|
}
|
|
@@ -1,21 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Fn, RemovalPolicy } from 'aws-cdk-lib'
|
|
2
|
+
import {
|
|
3
|
+
AccessLogFormat,
|
|
4
|
+
BasePathMapping,
|
|
5
|
+
Cors,
|
|
6
|
+
EndpointType,
|
|
7
|
+
Integration,
|
|
8
|
+
IntegrationType,
|
|
9
|
+
JsonSchemaType,
|
|
10
|
+
JsonSchemaVersion,
|
|
11
|
+
LogGroupLogDestination,
|
|
12
|
+
MethodLoggingLevel,
|
|
13
|
+
Model,
|
|
14
|
+
PassthroughBehavior,
|
|
15
|
+
Resource,
|
|
16
|
+
RestApi,
|
|
17
|
+
} from 'aws-cdk-lib/aws-apigateway'
|
|
18
|
+
import { EventBus } from 'aws-cdk-lib/aws-events'
|
|
19
|
+
import { CloudWatchLogGroup } from 'aws-cdk-lib/aws-events-targets'
|
|
20
|
+
import { PolicyDocument, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'
|
|
21
|
+
import { LayerVersion } from 'aws-cdk-lib/aws-lambda'
|
|
22
|
+
import { EventBridgeDestination } from 'aws-cdk-lib/aws-lambda-destinations'
|
|
23
|
+
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'
|
|
9
24
|
import { Construct } from 'constructs'
|
|
10
25
|
import { CommonConstruct } from '../../common'
|
|
11
|
-
import { ApiDestinedLambda } from './api-destined-lambda'
|
|
12
26
|
import {
|
|
13
|
-
ApiToEventbridgeTargetEvent,
|
|
14
27
|
ApiToEventBridgeTargetEventType,
|
|
15
28
|
ApiToEventBridgeTargetProps,
|
|
16
|
-
ApiToEventbridgeTargetRestApi,
|
|
17
29
|
ApiToEventBridgeTargetRestApiType,
|
|
30
|
+
ApiToEventbridgeTargetEvent,
|
|
31
|
+
ApiToEventbridgeTargetRestApi,
|
|
18
32
|
} from '../api-to-eventbridge-target'
|
|
33
|
+
import { ApiDestinedLambda } from './api-destined-lambda'
|
|
19
34
|
import { ApiDestinedLambdaType } from './types'
|
|
20
35
|
|
|
21
36
|
/**
|
|
@@ -41,7 +56,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
41
56
|
id: string
|
|
42
57
|
|
|
43
58
|
/* application related resources */
|
|
44
|
-
applicationSecrets:
|
|
59
|
+
applicationSecrets: ISecret[]
|
|
45
60
|
|
|
46
61
|
/* destined lambda related resources */
|
|
47
62
|
apiDestinedLambda: ApiDestinedLambdaType
|
|
@@ -159,7 +174,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
159
174
|
*/
|
|
160
175
|
protected createApiDestinedLambdaPolicy() {
|
|
161
176
|
if (this.props.api.useExisting) return
|
|
162
|
-
this.apiDestinedLambda.policy = new
|
|
177
|
+
this.apiDestinedLambda.policy = new PolicyDocument({
|
|
163
178
|
statements: [this.iamManager.statementForPutEvents([this.apiEvent.eventBus.eventBusArn])],
|
|
164
179
|
})
|
|
165
180
|
}
|
|
@@ -194,7 +209,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
194
209
|
*/
|
|
195
210
|
protected createApiDestinedLambdaLayers() {
|
|
196
211
|
if (this.props.api.useExisting) return
|
|
197
|
-
const layers:
|
|
212
|
+
const layers: LayerVersion[] = []
|
|
198
213
|
if (this.props.lambda && this.props.lambda.layerSource) {
|
|
199
214
|
layers.push(
|
|
200
215
|
this.lambdaManager.createLambdaLayer(`${this.id}-lambda-destined-layer`, this, this.props.lambda.layerSource)
|
|
@@ -209,8 +224,8 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
209
224
|
*/
|
|
210
225
|
protected createApiDestinedLambdaDestinations() {
|
|
211
226
|
if (this.props.api.useExisting) return
|
|
212
|
-
this.apiDestinedLambda.destinationSuccess = new
|
|
213
|
-
this.apiDestinedLambda.destinationFailure = new
|
|
227
|
+
this.apiDestinedLambda.destinationSuccess = new EventBridgeDestination(this.apiEvent.eventBus)
|
|
228
|
+
this.apiDestinedLambda.destinationFailure = new EventBridgeDestination(this.apiEvent.eventBus)
|
|
214
229
|
}
|
|
215
230
|
|
|
216
231
|
/**
|
|
@@ -239,11 +254,11 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
239
254
|
}
|
|
240
255
|
|
|
241
256
|
/**
|
|
242
|
-
* @summary Method to create or use an existing
|
|
257
|
+
* @summary Method to create or use an existing event bus for api destined payload deliveries
|
|
243
258
|
*/
|
|
244
259
|
protected createApiDestinedEventBus() {
|
|
245
260
|
if (this.props.api.useExisting) {
|
|
246
|
-
this.apiEvent.eventBus =
|
|
261
|
+
this.apiEvent.eventBus = EventBus.fromEventBusName(
|
|
247
262
|
this,
|
|
248
263
|
`${this.id}-destined-event-bus`,
|
|
249
264
|
`${this.props.event.eventBusName}-${this.props.stage}`
|
|
@@ -295,7 +310,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
295
310
|
this,
|
|
296
311
|
this.props.event.ruleSuccess,
|
|
297
312
|
this.apiEvent.eventBus,
|
|
298
|
-
[new
|
|
313
|
+
[new CloudWatchLogGroup(this.apiEvent.logGroupSuccess)]
|
|
299
314
|
)
|
|
300
315
|
}
|
|
301
316
|
|
|
@@ -335,7 +350,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
335
350
|
this,
|
|
336
351
|
this.props.event.ruleFailure,
|
|
337
352
|
this.apiEvent.eventBus,
|
|
338
|
-
[new
|
|
353
|
+
[new CloudWatchLogGroup(this.apiEvent.logGroupFailure)]
|
|
339
354
|
)
|
|
340
355
|
}
|
|
341
356
|
|
|
@@ -343,8 +358,8 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
343
358
|
* @summary Method to create a role for sns topic
|
|
344
359
|
*/
|
|
345
360
|
protected createApiDestinedTopicRole() {
|
|
346
|
-
this.apiDestinedRestApi.role = new
|
|
347
|
-
assumedBy: new
|
|
361
|
+
this.apiDestinedRestApi.role = new Role(this, `${this.id}-sns-rest-api-role`, {
|
|
362
|
+
assumedBy: new ServicePrincipal('apigateway.amazonaws.com'),
|
|
348
363
|
})
|
|
349
364
|
}
|
|
350
365
|
|
|
@@ -438,7 +453,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
438
453
|
*/
|
|
439
454
|
protected createApiDestinedIntegration() {
|
|
440
455
|
if (!this.props.api.withResource) return
|
|
441
|
-
this.apiDestinedRestApi.integration = new
|
|
456
|
+
this.apiDestinedRestApi.integration = new Integration({
|
|
442
457
|
integrationHttpMethod: 'POST',
|
|
443
458
|
options: {
|
|
444
459
|
...{
|
|
@@ -447,13 +462,13 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
447
462
|
this.apiDestinedRestApi.integrationResponse,
|
|
448
463
|
this.apiDestinedRestApi.integrationErrorResponse,
|
|
449
464
|
],
|
|
450
|
-
passthroughBehavior:
|
|
465
|
+
passthroughBehavior: PassthroughBehavior.NEVER,
|
|
451
466
|
requestParameters: this.apiDestinedRestApi.integrationRequestParameters,
|
|
452
467
|
requestTemplates: this.apiDestinedRestApi.integrationRequestTemplates,
|
|
453
468
|
},
|
|
454
469
|
...this.props.api.integrationOptions,
|
|
455
470
|
},
|
|
456
|
-
type:
|
|
471
|
+
type: IntegrationType.AWS,
|
|
457
472
|
uri: `arn:aws:apigateway:${this.props.region}:sns:path//`,
|
|
458
473
|
})
|
|
459
474
|
}
|
|
@@ -505,41 +520,41 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
505
520
|
*/
|
|
506
521
|
protected createApiDestinedRestApi() {
|
|
507
522
|
if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
|
|
508
|
-
this.apiDestinedRestApi.api =
|
|
523
|
+
this.apiDestinedRestApi.api = RestApi.fromRestApiId(
|
|
509
524
|
this,
|
|
510
525
|
`${this.id}-sns-rest-api`,
|
|
511
|
-
|
|
526
|
+
Fn.importValue(this.props.api.importedRestApiRef)
|
|
512
527
|
)
|
|
513
528
|
return
|
|
514
529
|
}
|
|
515
530
|
|
|
516
531
|
const accessLogGroup = this.logManager.createLogGroup(`${this.id}-sns-rest-api-access-log`, this, {
|
|
517
532
|
logGroupName: `/custom/api/${this.id}-destined-rest-api-access`,
|
|
518
|
-
removalPolicy:
|
|
533
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
519
534
|
})
|
|
520
535
|
|
|
521
|
-
this.apiDestinedRestApi.api = new
|
|
536
|
+
this.apiDestinedRestApi.api = new RestApi(this, `${this.id}-sns-rest-api`, {
|
|
522
537
|
...{
|
|
523
538
|
defaultCorsPreflightOptions: {
|
|
524
|
-
allowHeaders:
|
|
539
|
+
allowHeaders: Cors.DEFAULT_HEADERS,
|
|
525
540
|
allowMethods: ['POST'],
|
|
526
|
-
allowOrigins:
|
|
541
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
527
542
|
},
|
|
528
543
|
defaultIntegration: this.apiDestinedRestApi.integration,
|
|
529
544
|
defaultMethodOptions: {
|
|
530
545
|
methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
|
|
531
546
|
},
|
|
532
547
|
deployOptions: {
|
|
533
|
-
accessLogDestination: new
|
|
534
|
-
accessLogFormat:
|
|
548
|
+
accessLogDestination: new LogGroupLogDestination(accessLogGroup),
|
|
549
|
+
accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
|
|
535
550
|
dataTraceEnabled: true,
|
|
536
551
|
description: `${this.id} - ${this.props.stage} stage`,
|
|
537
|
-
loggingLevel:
|
|
552
|
+
loggingLevel: MethodLoggingLevel.INFO,
|
|
538
553
|
metricsEnabled: true,
|
|
539
554
|
stageName: this.props.stage,
|
|
540
555
|
},
|
|
541
556
|
endpointConfiguration: {
|
|
542
|
-
types: [
|
|
557
|
+
types: [EndpointType.REGIONAL],
|
|
543
558
|
},
|
|
544
559
|
restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
|
|
545
560
|
},
|
|
@@ -554,16 +569,16 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
554
569
|
*/
|
|
555
570
|
protected createApiDestinedResponseModel() {
|
|
556
571
|
if (!this.props.api.withResource) return
|
|
557
|
-
this.apiDestinedRestApi.responseModel = new
|
|
572
|
+
this.apiDestinedRestApi.responseModel = new Model(this, `${this.id}-response-model`, {
|
|
558
573
|
restApi: this.apiDestinedRestApi.api,
|
|
559
574
|
...{
|
|
560
575
|
contentType: 'application/json',
|
|
561
576
|
modelName: 'ResponseModel',
|
|
562
577
|
schema: {
|
|
563
|
-
properties: { message: { type:
|
|
564
|
-
schema:
|
|
578
|
+
properties: { message: { type: JsonSchemaType.STRING } },
|
|
579
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
565
580
|
title: 'pollResponse',
|
|
566
|
-
type:
|
|
581
|
+
type: JsonSchemaType.OBJECT,
|
|
567
582
|
},
|
|
568
583
|
},
|
|
569
584
|
...this.props.api.responseModel,
|
|
@@ -575,19 +590,19 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
575
590
|
*/
|
|
576
591
|
protected createApiDestinedErrorResponseModel() {
|
|
577
592
|
if (!this.props.api.withResource) return
|
|
578
|
-
this.apiDestinedRestApi.errorResponseModel = new
|
|
593
|
+
this.apiDestinedRestApi.errorResponseModel = new Model(this, `${this.id}-error-response-model`, {
|
|
579
594
|
restApi: this.apiDestinedRestApi.api,
|
|
580
595
|
...{
|
|
581
596
|
contentType: 'application/json',
|
|
582
597
|
modelName: 'ErrorResponseModel',
|
|
583
598
|
schema: {
|
|
584
599
|
properties: {
|
|
585
|
-
message: { type:
|
|
586
|
-
state: { type:
|
|
600
|
+
message: { type: JsonSchemaType.STRING },
|
|
601
|
+
state: { type: JsonSchemaType.STRING },
|
|
587
602
|
},
|
|
588
|
-
schema:
|
|
603
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
589
604
|
title: 'errorResponse',
|
|
590
|
-
type:
|
|
605
|
+
type: JsonSchemaType.OBJECT,
|
|
591
606
|
},
|
|
592
607
|
},
|
|
593
608
|
...this.props.api.errorResponseModel,
|
|
@@ -602,9 +617,9 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
602
617
|
|
|
603
618
|
let rootResource
|
|
604
619
|
if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
|
|
605
|
-
rootResource =
|
|
620
|
+
rootResource = Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
|
|
606
621
|
path: '/',
|
|
607
|
-
resourceId:
|
|
622
|
+
resourceId: Fn.importValue(this.props.api.importedRestApiRootResourceRef),
|
|
608
623
|
restApi: this.apiDestinedRestApi.api,
|
|
609
624
|
})
|
|
610
625
|
} else {
|
|
@@ -649,7 +664,7 @@ export class ApiToEventBridgeTargetWithSns extends CommonConstruct {
|
|
|
649
664
|
*/
|
|
650
665
|
protected createApiBasePathMapping() {
|
|
651
666
|
if (this.props.api.useExisting) return
|
|
652
|
-
new
|
|
667
|
+
new BasePathMapping(this, `${this.id}-base-bath-mapping`, {
|
|
653
668
|
basePath: '',
|
|
654
669
|
domainName: this.apiDestinedRestApi.domain,
|
|
655
670
|
restApi: this.apiDestinedRestApi.api,
|
|
@@ -1,32 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
BasePathMapping,
|
|
3
|
+
DomainName,
|
|
4
|
+
Integration,
|
|
5
|
+
IntegrationResponse,
|
|
6
|
+
Method,
|
|
7
|
+
MethodResponse,
|
|
8
|
+
Model,
|
|
9
|
+
Resource,
|
|
10
|
+
RestApi,
|
|
11
|
+
} from 'aws-cdk-lib/aws-apigateway'
|
|
12
|
+
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
|
|
13
|
+
import { Role } from 'aws-cdk-lib/aws-iam'
|
|
14
|
+
import { IFunction } from 'aws-cdk-lib/aws-lambda'
|
|
15
|
+
import { IHostedZone } from 'aws-cdk-lib/aws-route53'
|
|
16
|
+
import { Topic } from 'aws-cdk-lib/aws-sns'
|
|
7
17
|
import { ApiToLambdaTargetRestApiType } from './types'
|
|
8
18
|
|
|
9
19
|
/**
|
|
10
20
|
* @classdesc Provides a construct to contain api resources for ApiToLambdaTarget
|
|
11
21
|
*/
|
|
12
22
|
export class ApiToLambdaTargetRestApi implements ApiToLambdaTargetRestApiType {
|
|
13
|
-
api:
|
|
14
|
-
basePathMappings:
|
|
15
|
-
certificate:
|
|
16
|
-
domain:
|
|
17
|
-
errorResponseModel:
|
|
18
|
-
hostedZone:
|
|
19
|
-
integration:
|
|
20
|
-
integrationErrorResponse:
|
|
23
|
+
api: RestApi
|
|
24
|
+
basePathMappings: BasePathMapping[] = []
|
|
25
|
+
certificate: ICertificate
|
|
26
|
+
domain: DomainName
|
|
27
|
+
errorResponseModel: Model
|
|
28
|
+
hostedZone: IHostedZone
|
|
29
|
+
integration: Integration
|
|
30
|
+
integrationErrorResponse: IntegrationResponse
|
|
21
31
|
integrationRequestParameters: { [p: string]: string }
|
|
22
32
|
integrationRequestTemplates: { [p: string]: string }
|
|
23
|
-
integrationResponse:
|
|
24
|
-
lambda:
|
|
25
|
-
method:
|
|
26
|
-
methodErrorResponse:
|
|
27
|
-
methodResponse:
|
|
28
|
-
resource:
|
|
29
|
-
responseModel:
|
|
30
|
-
topic:
|
|
31
|
-
role:
|
|
33
|
+
integrationResponse: IntegrationResponse
|
|
34
|
+
lambda: IFunction
|
|
35
|
+
method: Method
|
|
36
|
+
methodErrorResponse: MethodResponse
|
|
37
|
+
methodResponse: MethodResponse
|
|
38
|
+
resource: Resource
|
|
39
|
+
responseModel: Model
|
|
40
|
+
topic: Topic
|
|
41
|
+
role: Role
|
|
32
42
|
}
|