@gradientedge/cdk-utils 8.117.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.
Files changed (148) hide show
  1. package/app/api-destined-function/package.json +1 -1
  2. package/dist/src/lib/common/construct.d.ts +32 -32
  3. package/dist/src/lib/common/construct.js +36 -59
  4. package/dist/src/lib/common/stack.d.ts +8 -7
  5. package/dist/src/lib/common/stack.js +17 -37
  6. package/dist/src/lib/common/types.d.ts +2 -2
  7. package/dist/src/lib/construct/api-to-eventbridge-target/api.d.ts +22 -22
  8. package/dist/src/lib/construct/api-to-eventbridge-target/event.d.ts +9 -9
  9. package/dist/src/lib/construct/api-to-eventbridge-target/main.d.ts +3 -3
  10. package/dist/src/lib/construct/api-to-eventbridge-target/main.js +37 -60
  11. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.d.ts +9 -9
  12. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.d.ts +3 -3
  13. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.js +40 -63
  14. package/dist/src/lib/construct/api-to-lambda-target/api.d.ts +23 -23
  15. package/dist/src/lib/construct/api-to-lambda-target/main.d.ts +2 -2
  16. package/dist/src/lib/construct/api-to-lambda-target/main.js +15 -38
  17. package/dist/src/lib/construct/application-configuration/main.d.ts +7 -7
  18. package/dist/src/lib/construct/application-configuration/main.js +17 -41
  19. package/dist/src/lib/construct/graphql-api-lambda/main.d.ts +17 -17
  20. package/dist/src/lib/construct/graphql-api-lambda/main.js +6 -29
  21. package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.d.ts +5 -5
  22. package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.js +7 -7
  23. package/dist/src/lib/construct/lambda-with-iam-access/main.d.ts +16 -16
  24. package/dist/src/lib/construct/lambda-with-iam-access/main.js +8 -31
  25. package/dist/src/lib/construct/lambda-with-iam-access/types.d.ts +4 -4
  26. package/dist/src/lib/construct/rest-api-lambda/main.d.ts +16 -16
  27. package/dist/src/lib/construct/rest-api-lambda/main.js +5 -28
  28. package/dist/src/lib/construct/rest-api-lambda-with-cache/main.d.ts +5 -5
  29. package/dist/src/lib/construct/rest-api-lambda-with-cache/main.js +9 -32
  30. package/dist/src/lib/construct/site-with-ecs-backend/main.d.ts +38 -39
  31. package/dist/src/lib/construct/site-with-ecs-backend/main.js +33 -54
  32. package/dist/src/lib/construct/static-asset-deployment/main.d.ts +4 -4
  33. package/dist/src/lib/construct/static-asset-deployment/main.js +3 -26
  34. package/dist/src/lib/construct/static-site/main.d.ts +15 -15
  35. package/dist/src/lib/construct/static-site/main.js +4 -27
  36. package/dist/src/lib/services/aws/api-gateway/main.d.ts +10 -10
  37. package/dist/src/lib/services/aws/api-gateway/main.js +21 -44
  38. package/dist/src/lib/services/aws/api-gateway/types.d.ts +2 -2
  39. package/dist/src/lib/services/aws/appconfig/main.d.ts +7 -7
  40. package/dist/src/lib/services/aws/appconfig/main.js +14 -37
  41. package/dist/src/lib/services/aws/certificate-manager/main.d.ts +5 -5
  42. package/dist/src/lib/services/aws/certificate-manager/main.js +10 -33
  43. package/dist/src/lib/services/aws/certificate-manager/types.d.ts +2 -2
  44. package/dist/src/lib/services/aws/cloudfront/main.d.ts +18 -18
  45. package/dist/src/lib/services/aws/cloudfront/main.js +46 -45
  46. package/dist/src/lib/services/aws/cloudfront/types.d.ts +2 -3
  47. package/dist/src/lib/services/aws/cloudtrail/main.d.ts +5 -5
  48. package/dist/src/lib/services/aws/cloudtrail/main.js +5 -28
  49. package/dist/src/lib/services/aws/codebuild/main.d.ts +3 -3
  50. package/dist/src/lib/services/aws/codebuild/main.js +7 -30
  51. package/dist/src/lib/services/aws/dynamodb/main.d.ts +3 -3
  52. package/dist/src/lib/services/aws/dynamodb/main.js +8 -31
  53. package/dist/src/lib/services/aws/elastic-container-registry/main.d.ts +2 -2
  54. package/dist/src/lib/services/aws/elastic-container-registry/main.js +4 -27
  55. package/dist/src/lib/services/aws/elastic-container-service/main.d.ts +10 -10
  56. package/dist/src/lib/services/aws/elastic-container-service/main.js +27 -50
  57. package/dist/src/lib/services/aws/elastic-container-service/types.d.ts +4 -4
  58. package/dist/src/lib/services/aws/elastic-file-system/main.d.ts +3 -3
  59. package/dist/src/lib/services/aws/elastic-file-system/main.js +12 -35
  60. package/dist/src/lib/services/aws/elastic-kubernetes-service/main.d.ts +4 -4
  61. package/dist/src/lib/services/aws/elastic-kubernetes-service/main.js +8 -31
  62. package/dist/src/lib/services/aws/elasticache/main.d.ts +4 -4
  63. package/dist/src/lib/services/aws/elasticache/main.js +10 -33
  64. package/dist/src/lib/services/aws/eventbridge/main.d.ts +13 -13
  65. package/dist/src/lib/services/aws/eventbridge/main.js +26 -49
  66. package/dist/src/lib/services/aws/eventbridge/target.d.ts +10 -10
  67. package/dist/src/lib/services/aws/eventbridge/target.js +6 -29
  68. package/dist/src/lib/services/aws/evidently/main.d.ts +7 -7
  69. package/dist/src/lib/services/aws/evidently/main.js +18 -41
  70. package/dist/src/lib/services/aws/identity-access-management/main.d.ts +48 -49
  71. package/dist/src/lib/services/aws/identity-access-management/main.js +110 -133
  72. package/dist/src/lib/services/aws/key-management-service/main.d.ts +2 -2
  73. package/dist/src/lib/services/aws/key-management-service/main.js +5 -28
  74. package/dist/src/lib/services/aws/lambda/main.d.ts +11 -13
  75. package/dist/src/lib/services/aws/lambda/main.js +31 -58
  76. package/dist/src/lib/services/aws/route53/main.d.ts +9 -9
  77. package/dist/src/lib/services/aws/route53/main.js +21 -44
  78. package/dist/src/lib/services/aws/secrets-manager/main.d.ts +5 -6
  79. package/dist/src/lib/services/aws/secrets-manager/main.js +10 -33
  80. package/dist/src/lib/services/aws/simple-notification-service/main.d.ts +4 -4
  81. package/dist/src/lib/services/aws/simple-notification-service/main.js +11 -34
  82. package/dist/src/lib/services/aws/simple-queue-service/main.d.ts +6 -7
  83. package/dist/src/lib/services/aws/simple-queue-service/main.js +15 -38
  84. package/dist/src/lib/services/aws/simple-storage-service/main.d.ts +10 -11
  85. package/dist/src/lib/services/aws/simple-storage-service/main.js +31 -54
  86. package/dist/src/lib/services/aws/step-function/main.d.ts +31 -32
  87. package/dist/src/lib/services/aws/step-function/main.js +33 -57
  88. package/dist/src/lib/services/aws/systems-manager/main.d.ts +4 -4
  89. package/dist/src/lib/services/aws/systems-manager/main.js +10 -33
  90. package/dist/src/lib/services/aws/virtual-private-cloud/main.d.ts +5 -6
  91. package/dist/src/lib/services/aws/virtual-private-cloud/main.js +14 -37
  92. package/dist/src/lib/services/aws/web-application-firewall/main.d.ts +3 -3
  93. package/dist/src/lib/services/aws/web-application-firewall/main.js +8 -31
  94. package/dist/src/lib/utils/aws/index.d.ts +6 -3
  95. package/dist/src/lib/utils/aws/index.js +9 -26
  96. package/package.json +21 -21
  97. package/src/lib/common/construct.ts +97 -67
  98. package/src/lib/common/stack.ts +12 -12
  99. package/src/lib/common/types.ts +2 -2
  100. package/src/lib/construct/api-to-eventbridge-target/api.ts +31 -22
  101. package/src/lib/construct/api-to-eventbridge-target/event.ts +9 -9
  102. package/src/lib/construct/api-to-eventbridge-target/main.ts +56 -41
  103. package/src/lib/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.ts +9 -9
  104. package/src/lib/construct/api-to-eventbridge-target-with-sns/main.ts +62 -47
  105. package/src/lib/construct/api-to-lambda-target/api.ts +33 -23
  106. package/src/lib/construct/api-to-lambda-target/main.ts +24 -18
  107. package/src/lib/construct/application-configuration/main.ts +31 -24
  108. package/src/lib/construct/graphql-api-lambda/main.ts +22 -22
  109. package/src/lib/construct/graphql-api-lambda-with-cache/main.ts +13 -13
  110. package/src/lib/construct/lambda-with-iam-access/main.ts +25 -25
  111. package/src/lib/construct/lambda-with-iam-access/types.ts +4 -4
  112. package/src/lib/construct/rest-api-lambda/main.ts +21 -21
  113. package/src/lib/construct/rest-api-lambda-with-cache/main.ts +14 -14
  114. package/src/lib/construct/site-with-ecs-backend/main.ts +79 -60
  115. package/src/lib/construct/static-asset-deployment/main.ts +6 -6
  116. package/src/lib/construct/static-site/main.ts +23 -17
  117. package/src/lib/services/aws/api-gateway/main.ts +42 -36
  118. package/src/lib/services/aws/api-gateway/types.ts +2 -2
  119. package/src/lib/services/aws/appconfig/main.ts +19 -19
  120. package/src/lib/services/aws/certificate-manager/main.ts +14 -14
  121. package/src/lib/services/aws/certificate-manager/types.ts +2 -2
  122. package/src/lib/services/aws/cloudfront/main.ts +88 -74
  123. package/src/lib/services/aws/cloudfront/types.ts +6 -3
  124. package/src/lib/services/aws/cloudtrail/main.ts +11 -11
  125. package/src/lib/services/aws/codebuild/main.ts +7 -7
  126. package/src/lib/services/aws/dynamodb/main.ts +8 -8
  127. package/src/lib/services/aws/elastic-container-registry/main.ts +4 -4
  128. package/src/lib/services/aws/elastic-container-service/main.ts +48 -37
  129. package/src/lib/services/aws/elastic-container-service/types.ts +4 -4
  130. package/src/lib/services/aws/elastic-file-system/main.ts +16 -16
  131. package/src/lib/services/aws/elastic-kubernetes-service/main.ts +11 -11
  132. package/src/lib/services/aws/elasticache/main.ts +10 -10
  133. package/src/lib/services/aws/eventbridge/main.ts +37 -37
  134. package/src/lib/services/aws/eventbridge/target.ts +14 -14
  135. package/src/lib/services/aws/evidently/main.ts +18 -18
  136. package/src/lib/services/aws/identity-access-management/main.ts +142 -134
  137. package/src/lib/services/aws/key-management-service/main.ts +5 -5
  138. package/src/lib/services/aws/lambda/main.ts +65 -59
  139. package/src/lib/services/aws/route53/main.ts +31 -31
  140. package/src/lib/services/aws/secrets-manager/main.ts +11 -15
  141. package/src/lib/services/aws/simple-notification-service/main.ts +13 -13
  142. package/src/lib/services/aws/simple-queue-service/main.ts +18 -18
  143. package/src/lib/services/aws/simple-storage-service/main.ts +40 -40
  144. package/src/lib/services/aws/step-function/main.ts +77 -65
  145. package/src/lib/services/aws/systems-manager/main.ts +17 -12
  146. package/src/lib/services/aws/virtual-private-cloud/main.ts +16 -16
  147. package/src/lib/services/aws/web-application-firewall/main.ts +8 -8
  148. package/src/lib/utils/aws/index.ts +8 -5
@@ -1,18 +1,33 @@
1
- import * as cdk from 'aws-cdk-lib'
2
- import * as apig from 'aws-cdk-lib/aws-apigateway'
3
- import * as events from 'aws-cdk-lib/aws-events'
4
- import * as eventstargets from 'aws-cdk-lib/aws-events-targets'
5
- import * as iam from 'aws-cdk-lib/aws-iam'
6
- import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
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: secretsmanager.ISecret[]
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 eventbus for api payload deliveries
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 = events.EventBus.fromEventBusName(
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 eventstargets.CloudWatchLogGroup(this.apiEvent.logGroup)]
203
+ [new CloudWatchLogGroup(this.apiEvent.logGroup)]
189
204
  )
190
205
  }
191
206
 
192
207
  protected createApiToEventBridgeTargetPolicy() {
193
- this.apiToEventBridgeTargetRestApi.policy = new iam.PolicyDocument({
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 iam.Role(this, `${this.id}-rest-api-role`, {
205
- assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
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 = "AWSEvents.PutEvents")',
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 apig.Integration({
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: apig.PassthroughBehavior.NEVER,
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: apig.IntegrationType.AWS,
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: cdk.RemovalPolicy.DESTROY,
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 = apig.RestApi.fromRestApiId(
381
+ this.apiToEventBridgeTargetRestApi.api = RestApi.fromRestApiId(
367
382
  this,
368
383
  `${this.id}-rest-api`,
369
- cdk.Fn.importValue(this.props.api.importedRestApiRef)
384
+ Fn.importValue(this.props.api.importedRestApiRef)
370
385
  )
371
386
  return
372
387
  }
373
388
 
374
- this.apiToEventBridgeTargetRestApi.api = new apig.RestApi(this, `${this.id}-rest-api`, {
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: apig.Cors.DEFAULT_HEADERS,
393
+ allowHeaders: Cors.DEFAULT_HEADERS,
379
394
  allowMethods: ['POST'],
380
- allowOrigins: apig.Cors.ALL_ORIGINS,
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 apig.LogGroupLogDestination(this.apiToEventBridgeTargetRestApi.accessLogGroup),
392
- accessLogFormat: apig.AccessLogFormat.jsonWithStandardFields(),
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: apig.MethodLoggingLevel.INFO,
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: [apig.EndpointType.REGIONAL],
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 apig.Model(this, `${this.id}-response-model`, {
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: apig.JsonSchemaType.STRING } },
423
- schema: apig.JsonSchemaVersion.DRAFT4,
437
+ properties: { message: { type: JsonSchemaType.STRING } },
438
+ schema: JsonSchemaVersion.DRAFT4,
424
439
  title: 'pollResponse',
425
- type: apig.JsonSchemaType.OBJECT,
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 apig.Model(this, `${this.id}-error-response-model`, {
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: apig.JsonSchemaType.STRING },
445
- state: { type: apig.JsonSchemaType.STRING },
459
+ message: { type: JsonSchemaType.STRING },
460
+ state: { type: JsonSchemaType.STRING },
446
461
  },
447
- schema: apig.JsonSchemaVersion.DRAFT4,
462
+ schema: JsonSchemaVersion.DRAFT4,
448
463
  title: 'errorResponse',
449
- type: apig.JsonSchemaType.OBJECT,
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 = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
479
+ rootResource = Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
465
480
  path: '/',
466
- resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
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 apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
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 * as iam from 'aws-cdk-lib/aws-iam'
2
- import * as lambda from 'aws-cdk-lib/aws-lambda'
3
- import * as destinations from 'aws-cdk-lib/aws-lambda-destinations'
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: destinations.EventBridgeDestination
11
- destinationSuccess: destinations.EventBridgeDestination
10
+ destinationFailure: EventBridgeDestination
11
+ destinationSuccess: EventBridgeDestination
12
12
  environment: ApiDestinedLambdaEnvironment
13
- function: lambda.Function
14
- layers: lambda.LayerVersion[]
15
- policy: iam.PolicyDocument
16
- role: iam.Role
13
+ function: IFunction
14
+ layers: LayerVersion[]
15
+ policy: PolicyDocument
16
+ role: Role
17
17
  }
@@ -1,21 +1,36 @@
1
- import * as cdk from 'aws-cdk-lib'
2
- import * as apig from 'aws-cdk-lib/aws-apigateway'
3
- import * as events from 'aws-cdk-lib/aws-events'
4
- import * as eventstargets from 'aws-cdk-lib/aws-events-targets'
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
- import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
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: secretsmanager.ISecret[]
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 iam.PolicyDocument({
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: lambda.LayerVersion[] = []
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 destinations.EventBridgeDestination(this.apiEvent.eventBus)
213
- this.apiDestinedLambda.destinationFailure = new destinations.EventBridgeDestination(this.apiEvent.eventBus)
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 eventbus for api destined payload deliveries
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 = events.EventBus.fromEventBusName(
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 eventstargets.CloudWatchLogGroup(this.apiEvent.logGroupSuccess)]
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 eventstargets.CloudWatchLogGroup(this.apiEvent.logGroupFailure)]
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 iam.Role(this, `${this.id}-sns-rest-api-role`, {
347
- assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
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 apig.Integration({
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: apig.PassthroughBehavior.NEVER,
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: apig.IntegrationType.AWS,
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 = apig.RestApi.fromRestApiId(
523
+ this.apiDestinedRestApi.api = RestApi.fromRestApiId(
509
524
  this,
510
525
  `${this.id}-sns-rest-api`,
511
- cdk.Fn.importValue(this.props.api.importedRestApiRef)
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: cdk.RemovalPolicy.DESTROY,
533
+ removalPolicy: RemovalPolicy.DESTROY,
519
534
  })
520
535
 
521
- this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
536
+ this.apiDestinedRestApi.api = new RestApi(this, `${this.id}-sns-rest-api`, {
522
537
  ...{
523
538
  defaultCorsPreflightOptions: {
524
- allowHeaders: apig.Cors.DEFAULT_HEADERS,
539
+ allowHeaders: Cors.DEFAULT_HEADERS,
525
540
  allowMethods: ['POST'],
526
- allowOrigins: apig.Cors.ALL_ORIGINS,
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 apig.LogGroupLogDestination(accessLogGroup),
534
- accessLogFormat: apig.AccessLogFormat.jsonWithStandardFields(),
548
+ accessLogDestination: new LogGroupLogDestination(accessLogGroup),
549
+ accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
535
550
  dataTraceEnabled: true,
536
551
  description: `${this.id} - ${this.props.stage} stage`,
537
- loggingLevel: apig.MethodLoggingLevel.INFO,
552
+ loggingLevel: MethodLoggingLevel.INFO,
538
553
  metricsEnabled: true,
539
554
  stageName: this.props.stage,
540
555
  },
541
556
  endpointConfiguration: {
542
- types: [apig.EndpointType.REGIONAL],
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 apig.Model(this, `${this.id}-response-model`, {
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: apig.JsonSchemaType.STRING } },
564
- schema: apig.JsonSchemaVersion.DRAFT4,
578
+ properties: { message: { type: JsonSchemaType.STRING } },
579
+ schema: JsonSchemaVersion.DRAFT4,
565
580
  title: 'pollResponse',
566
- type: apig.JsonSchemaType.OBJECT,
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 apig.Model(this, `${this.id}-error-response-model`, {
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: apig.JsonSchemaType.STRING },
586
- state: { type: apig.JsonSchemaType.STRING },
600
+ message: { type: JsonSchemaType.STRING },
601
+ state: { type: JsonSchemaType.STRING },
587
602
  },
588
- schema: apig.JsonSchemaVersion.DRAFT4,
603
+ schema: JsonSchemaVersion.DRAFT4,
589
604
  title: 'errorResponse',
590
- type: apig.JsonSchemaType.OBJECT,
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 = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
620
+ rootResource = Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
606
621
  path: '/',
607
- resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
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 apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
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 * as apig from 'aws-cdk-lib/aws-apigateway'
2
- import * as acm from 'aws-cdk-lib/aws-certificatemanager'
3
- import * as iam from 'aws-cdk-lib/aws-iam'
4
- import * as lambda from 'aws-cdk-lib/aws-lambda'
5
- import * as route53 from 'aws-cdk-lib/aws-route53'
6
- import * as sns from 'aws-cdk-lib/aws-sns'
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: apig.RestApi
14
- basePathMappings: apig.BasePathMapping[] = []
15
- certificate: acm.ICertificate
16
- domain: apig.DomainName
17
- errorResponseModel: apig.Model
18
- hostedZone: route53.IHostedZone
19
- integration: apig.Integration
20
- integrationErrorResponse: apig.IntegrationResponse
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: apig.IntegrationResponse
24
- lambda: lambda.IFunction
25
- method: apig.Method
26
- methodErrorResponse: apig.MethodResponse
27
- methodResponse: apig.MethodResponse
28
- resource: apig.Resource
29
- responseModel: apig.Model
30
- topic: sns.Topic
31
- role: iam.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
  }