@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,9 +1,9 @@
1
- import * as cdk from 'aws-cdk-lib'
2
- import * as sqs from 'aws-cdk-lib/aws-sqs'
3
- import * as utils from '../../../utils'
1
+ import { Duration, RemovalPolicy, Tags } from 'aws-cdk-lib'
2
+ import { IQueue, Queue } from 'aws-cdk-lib/aws-sqs'
4
3
  import { CommonConstruct } from '../../../common'
5
- import { QueueProps } from './types'
4
+ import { createCfnOutput } from '../../../utils'
6
5
  import { LambdaProps } from '../lambda'
6
+ import { QueueProps } from './types'
7
7
 
8
8
  /**
9
9
  * @classdesc Provides operations on AWS Simple Queue Service.
@@ -13,7 +13,7 @@ import { LambdaProps } from '../lambda'
13
13
  * import { CommonConstruct } from '@gradientedge/cdk-utils'
14
14
  *
15
15
  * class CustomConstruct extends CommonConstruct {
16
- * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
16
+ * constructor(parent: Construct, id: string, props: common.CommonStackProps) {
17
17
  * super(parent, id, props)
18
18
  * this.props = props
19
19
  * this.sqsManager.createQueue('MySqs', this, {...})
@@ -29,12 +29,12 @@ export class SqsManager {
29
29
  * @param props
30
30
  * @param deadLetterQueue
31
31
  */
32
- public createQueue(id: string, scope: CommonConstruct, props: QueueProps, deadLetterQueue?: sqs.IQueue) {
32
+ public createQueue(id: string, scope: CommonConstruct, props: QueueProps, deadLetterQueue?: IQueue) {
33
33
  if (!props) throw `Queue props undefined for ${id}`
34
34
 
35
- const queue = new sqs.Queue(scope, id, {
35
+ const queue = new Queue(scope, id, {
36
36
  contentBasedDeduplication: props.contentBasedDeduplication,
37
- dataKeyReuse: props.dataKeyReuseInSecs ? cdk.Duration.seconds(props.dataKeyReuseInSecs) : props.dataKeyReuse,
37
+ dataKeyReuse: props.dataKeyReuseInSecs ? Duration.seconds(props.dataKeyReuseInSecs) : props.dataKeyReuse,
38
38
  deadLetterQueue: !deadLetterQueue
39
39
  ? undefined
40
40
  : {
@@ -42,7 +42,7 @@ export class SqsManager {
42
42
  queue: deadLetterQueue,
43
43
  },
44
44
  deduplicationScope: props.deduplicationScope,
45
- deliveryDelay: props.deliveryDelayInSecs ? cdk.Duration.seconds(props.deliveryDelayInSecs) : undefined,
45
+ deliveryDelay: props.deliveryDelayInSecs ? Duration.seconds(props.deliveryDelayInSecs) : undefined,
46
46
  encryption: props.encryption,
47
47
  encryptionMasterKey: props.encryptionMasterKey,
48
48
  fifo: props.fifo,
@@ -50,24 +50,24 @@ export class SqsManager {
50
50
  maxMessageSizeBytes: props.maxMessageSizeBytes,
51
51
  queueName: props.queueName,
52
52
  receiveMessageWaitTime: props.receiveMessageWaitTimeInSecs
53
- ? cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs)
53
+ ? Duration.seconds(props.receiveMessageWaitTimeInSecs)
54
54
  : props.receiveMessageWaitTime,
55
- removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.DESTROY,
56
- retentionPeriod: props.retentionInDays ? cdk.Duration.days(props.retentionInDays) : cdk.Duration.days(7),
55
+ removalPolicy: props.removalPolicy ?? RemovalPolicy.DESTROY,
56
+ retentionPeriod: props.retentionInDays ? Duration.days(props.retentionInDays) : Duration.days(7),
57
57
  visibilityTimeout: props.visibilityTimeoutInSecs
58
- ? cdk.Duration.seconds(props.visibilityTimeoutInSecs)
58
+ ? Duration.seconds(props.visibilityTimeoutInSecs)
59
59
  : props.visibilityTimeout,
60
60
  })
61
61
 
62
62
  if (props.tags && props.tags.length > 0) {
63
63
  props.tags.forEach(tag => {
64
- cdk.Tags.of(queue).add(tag.key, tag.value)
64
+ Tags.of(queue).add(tag.key, tag.value)
65
65
  })
66
66
  }
67
67
 
68
- utils.createCfnOutput(`${id}-queueArn`, scope, queue.queueArn)
69
- utils.createCfnOutput(`${id}-queueName`, scope, queue.queueName)
70
- utils.createCfnOutput(`${id}-queueUrl`, scope, queue.queueUrl)
68
+ createCfnOutput(`${id}-queueArn`, scope, queue.queueArn)
69
+ createCfnOutput(`${id}-queueName`, scope, queue.queueName)
70
+ createCfnOutput(`${id}-queueUrl`, scope, queue.queueUrl)
71
71
 
72
72
  return queue
73
73
  }
@@ -98,7 +98,7 @@ export class SqsManager {
98
98
  id: string,
99
99
  scope: CommonConstruct,
100
100
  props: LambdaProps,
101
- deadLetterQueue: sqs.IQueue
101
+ deadLetterQueue: IQueue
102
102
  ) {
103
103
  let queueProps
104
104
  if (props.dlq) {
@@ -1,21 +1,21 @@
1
- import * as cdk from 'aws-cdk-lib'
2
- import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'
3
- import * as iam from 'aws-cdk-lib/aws-iam'
4
- import * as s3 from 'aws-cdk-lib/aws-s3'
5
- import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment'
6
- import * as utils from '../../../utils'
7
- import { LifecycleRule, S3BucketProps } from './types'
1
+ import { Duration, RemovalPolicy, Stack, Tags } from 'aws-cdk-lib'
2
+ import { IDistribution } from 'aws-cdk-lib/aws-cloudfront'
3
+ import { Effect, PolicyDocument, PolicyStatement, ServicePrincipal } from 'aws-cdk-lib/aws-iam'
4
+ import { BlockPublicAccess, Bucket, BucketEncryption, CfnBucket, CfnBucketPolicy, IBucket } from 'aws-cdk-lib/aws-s3'
5
+ import { BucketDeployment, ISource, ServerSideEncryption, Source } from 'aws-cdk-lib/aws-s3-deployment'
8
6
  import { CommonConstruct } from '../../../common'
7
+ import { createCfnOutput } from '../../../utils'
8
+ import { LifecycleRule, S3BucketProps } from './types'
9
9
 
10
10
  /**
11
- * @classdesc Provides operations on AWS S3.
11
+ * @classdesc Provides operations on AWS S3
12
12
  * - A new instance of this class is injected into {@link CommonConstruct} constructor.
13
13
  * - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
14
14
  * @example
15
15
  * import { CommonConstruct } from '@gradientedge/cdk-utils'
16
16
  *
17
17
  * class CustomConstruct extends CommonConstruct {
18
- * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
18
+ * constructor(parent: Construct, id: string, props: common.CommonStackProps) {
19
19
  * super(parent, id, props)
20
20
  * this.props = props
21
21
  * this.s3Manager.createS3Bucket('MyBucket', this)
@@ -36,12 +36,12 @@ export class S3Manager {
36
36
  bucketLifecycleRules.push({
37
37
  abortIncompleteMultipartUploadAfter: lifecycleRule.abortIncompleteMultipartUploadAfter,
38
38
  enabled: lifecycleRule.enabled,
39
- expiration: lifecycleRule.expirationInDays ? cdk.Duration.days(lifecycleRule.expirationInDays) : undefined,
39
+ expiration: lifecycleRule.expirationInDays ? Duration.days(lifecycleRule.expirationInDays) : undefined,
40
40
  expirationDate: lifecycleRule.expirationDate,
41
41
  expiredObjectDeleteMarker: lifecycleRule.expiredObjectDeleteMarker,
42
42
  id: lifecycleRule.id,
43
43
  noncurrentVersionExpiration: lifecycleRule.noncurrentVersionExpirationInDays
44
- ? cdk.Duration.days(lifecycleRule.noncurrentVersionExpirationInDays)
44
+ ? Duration.days(lifecycleRule.noncurrentVersionExpirationInDays)
45
45
  : undefined,
46
46
  noncurrentVersionTransitions: lifecycleRule.noncurrentVersionTransitions,
47
47
  prefix: lifecycleRule.prefix,
@@ -59,7 +59,7 @@ export class S3Manager {
59
59
  * @param bucketName the bucket name
60
60
  */
61
61
  protected static determineBucketNameByAccountAndRegion(scope: CommonConstruct, bucketName: string) {
62
- return `${bucketName}-${cdk.Stack.of(scope).account}-${scope.props.region}-${scope.props.stage}`
62
+ return `${bucketName}-${Stack.of(scope).account}-${scope.props.region}-${scope.props.stage}`
63
63
  }
64
64
 
65
65
  /**
@@ -93,32 +93,32 @@ export class S3Manager {
93
93
  public createS3Bucket(id: string, scope: CommonConstruct, props: S3BucketProps) {
94
94
  if (!props) throw `S3 props undefined for ${id}`
95
95
 
96
- let bucket: s3.IBucket
96
+ let bucket: IBucket
97
97
 
98
98
  const bucketName = S3Manager.determineBucketName(scope, props.bucketName)
99
99
 
100
100
  if (props.existingBucket && props.bucketName) {
101
- bucket = s3.Bucket.fromBucketName(scope, `${id}`, bucketName)
101
+ bucket = Bucket.fromBucketName(scope, `${id}`, bucketName)
102
102
  } else {
103
103
  let logBucket
104
104
  if (props.logBucketName) {
105
105
  const logBucketName = S3Manager.determineBucketName(scope, props.logBucketName)
106
- logBucket = s3.Bucket.fromBucketName(scope, `${id}-logs`, logBucketName)
106
+ logBucket = Bucket.fromBucketName(scope, `${id}-logs`, logBucketName)
107
107
  }
108
108
 
109
- bucket = new s3.Bucket(scope, `${id}-bucket`, {
109
+ bucket = new Bucket(scope, `${id}-bucket`, {
110
110
  accessControl: props.accessControl,
111
111
  autoDeleteObjects: props.autoDeleteObjects,
112
- blockPublicAccess: props.blockPublicAccess || s3.BlockPublicAccess.BLOCK_ALL,
112
+ blockPublicAccess: props.blockPublicAccess || BlockPublicAccess.BLOCK_ALL,
113
113
  bucketName: bucketName,
114
114
  cors: props.cors,
115
- encryption: props.encryption || s3.BucketEncryption.S3_MANAGED,
115
+ encryption: props.encryption || BucketEncryption.S3_MANAGED,
116
116
  encryptionKey: props.encryptionKey,
117
117
  lifecycleRules: this.determineBucketLifecycleRules(props),
118
118
  metrics: props.metrics,
119
119
  objectOwnership: props.objectOwnership,
120
120
  publicReadAccess: props.publicReadAccess,
121
- removalPolicy: props.removalPolicy || cdk.RemovalPolicy.RETAIN,
121
+ removalPolicy: props.removalPolicy || RemovalPolicy.RETAIN,
122
122
  serverAccessLogsBucket: logBucket,
123
123
  serverAccessLogsPrefix: props.serverAccessLogsPrefix,
124
124
  versioned: props.versioned,
@@ -127,7 +127,7 @@ export class S3Manager {
127
127
  websiteRoutingRules: props.websiteRoutingRules,
128
128
  })
129
129
 
130
- const cfnBucket = bucket.node.defaultChild as s3.CfnBucket
130
+ const cfnBucket = bucket.node.defaultChild as CfnBucket
131
131
  cfnBucket.notificationConfiguration = {
132
132
  eventBridgeConfiguration: {
133
133
  eventBridgeEnabled: props.enableEventBridge ?? false,
@@ -137,12 +137,12 @@ export class S3Manager {
137
137
 
138
138
  if (props.tags && props.tags.length > 0) {
139
139
  props.tags.forEach(tag => {
140
- cdk.Tags.of(bucket).add(tag.key, tag.value)
140
+ Tags.of(bucket).add(tag.key, tag.value)
141
141
  })
142
142
  }
143
143
 
144
- utils.createCfnOutput(`${id}-bucketName`, scope, bucket.bucketName)
145
- utils.createCfnOutput(`${id}-bucketArn`, scope, bucket.bucketArn)
144
+ createCfnOutput(`${id}-bucketName`, scope, bucket.bucketName)
145
+ createCfnOutput(`${id}-bucketArn`, scope, bucket.bucketArn)
146
146
 
147
147
  return bucket
148
148
  }
@@ -153,27 +153,27 @@ export class S3Manager {
153
153
  * @param scope scope in which this resource is defined
154
154
  * @param bucket
155
155
  */
156
- public createBucketPolicyForCloudTrail(id: string, scope: CommonConstruct, bucket: s3.IBucket) {
157
- const bucketPolicyDocument = new iam.PolicyDocument({
156
+ public createBucketPolicyForCloudTrail(id: string, scope: CommonConstruct, bucket: IBucket) {
157
+ const bucketPolicyDocument = new PolicyDocument({
158
158
  statements: [
159
- new iam.PolicyStatement({
159
+ new PolicyStatement({
160
160
  actions: ['s3:GetBucketAcl'],
161
- effect: iam.Effect.ALLOW,
162
- principals: [new iam.ServicePrincipal('cloudtrail.amazonaws.com')],
161
+ effect: Effect.ALLOW,
162
+ principals: [new ServicePrincipal('cloudtrail.amazonaws.com')],
163
163
  resources: [bucket.bucketArn],
164
164
  sid: 'AWSCloudTrailAclCheck20150319',
165
165
  }),
166
- new iam.PolicyStatement({
166
+ new PolicyStatement({
167
167
  actions: ['s3:PutObject'],
168
- effect: iam.Effect.ALLOW,
169
- principals: [new iam.ServicePrincipal('cloudtrail.amazonaws.com')],
168
+ effect: Effect.ALLOW,
169
+ principals: [new ServicePrincipal('cloudtrail.amazonaws.com')],
170
170
  resources: [bucket.arnForObjects('*')],
171
171
  sid: 'AWSCloudTrailWrite20150319',
172
172
  }),
173
173
  ],
174
174
  })
175
175
 
176
- return new s3.CfnBucketPolicy(scope, `${id}`, {
176
+ return new CfnBucketPolicy(scope, `${id}`, {
177
177
  bucket: bucket.bucketName,
178
178
  policyDocument: bucketPolicyDocument,
179
179
  })
@@ -192,20 +192,20 @@ export class S3Manager {
192
192
  public doBucketDeployment(
193
193
  id: string,
194
194
  scope: CommonConstruct,
195
- siteBucket: s3.IBucket,
196
- distribution: cloudfront.IDistribution,
197
- sources: s3deploy.ISource[],
195
+ siteBucket: IBucket,
196
+ distribution: IDistribution,
197
+ sources: ISource[],
198
198
  prefix: string,
199
199
  prune?: boolean
200
200
  ) {
201
- new s3deploy.BucketDeployment(scope, `${id}`, {
201
+ new BucketDeployment(scope, `${id}`, {
202
202
  destinationBucket: siteBucket,
203
203
  destinationKeyPrefix: prefix,
204
204
  distribution: distribution,
205
205
  distributionPaths: ['/*'],
206
206
  memoryLimit: 1024,
207
207
  prune: !!prune,
208
- serverSideEncryption: s3deploy.ServerSideEncryption.AES_256,
208
+ serverSideEncryption: ServerSideEncryption.AES_256,
209
209
  sources: sources,
210
210
  })
211
211
  }
@@ -217,17 +217,17 @@ export class S3Manager {
217
217
  * @param bucket bucket to create the folders in
218
218
  * @param folders list of folder names to be created in the bucket
219
219
  */
220
- public createBucketFolders(id: string, scope: CommonConstruct, bucket: s3.IBucket, folders: string[]) {
220
+ public createBucketFolders(id: string, scope: CommonConstruct, bucket: IBucket, folders: string[]) {
221
221
  if (!folders || folders.length == 0) {
222
222
  throw `Folder unspecified for ${id}`
223
223
  }
224
224
 
225
225
  folders.forEach(folder => {
226
- new s3deploy.BucketDeployment(scope, `${id}-${folder}`, {
226
+ new BucketDeployment(scope, `${id}-${folder}`, {
227
227
  destinationBucket: bucket,
228
228
  destinationKeyPrefix: folder,
229
229
  prune: false,
230
- sources: [s3deploy.Source.data('README.md', `This is the ${folder} folder for ${id}`)],
230
+ sources: [Source.data('README.md', `This is the ${folder} folder for ${id}`)],
231
231
  })
232
232
  })
233
233
  }
@@ -1,16 +1,38 @@
1
- import * as cdk from 'aws-cdk-lib'
2
- import * as apig from 'aws-cdk-lib/aws-apigateway'
3
- import * as dynamodb from 'aws-cdk-lib/aws-dynamodb'
4
- import * as iam from 'aws-cdk-lib/aws-iam'
5
- import * as lambda from 'aws-cdk-lib/aws-lambda'
6
- import * as logs from 'aws-cdk-lib/aws-logs'
7
- import * as sqs from 'aws-cdk-lib/aws-sqs'
8
- import * as sfn from 'aws-cdk-lib/aws-stepfunctions'
9
- import { DefinitionBody } from 'aws-cdk-lib/aws-stepfunctions'
10
- import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks'
11
- import * as utils from '../../../utils'
1
+ import { Duration } from 'aws-cdk-lib'
2
+ import { IRestApi } from 'aws-cdk-lib/aws-apigateway'
3
+ import { ITable } from 'aws-cdk-lib/aws-dynamodb'
4
+ import { IRole } from 'aws-cdk-lib/aws-iam'
5
+ import { IFunction } from 'aws-cdk-lib/aws-lambda'
6
+ import { ILogGroup } from 'aws-cdk-lib/aws-logs'
7
+ import { IQueue } from 'aws-cdk-lib/aws-sqs'
8
+ import {
9
+ Choice,
10
+ DefinitionBody,
11
+ Fail,
12
+ IChainable,
13
+ IStateMachine,
14
+ LogLevel,
15
+ Map,
16
+ Parallel,
17
+ Pass,
18
+ StateMachine,
19
+ Succeed,
20
+ Wait,
21
+ WaitTime,
22
+ } from 'aws-cdk-lib/aws-stepfunctions'
23
+ import {
24
+ CallApiGatewayRestApiEndpoint,
25
+ DynamoAttributeValue,
26
+ DynamoDeleteItem,
27
+ DynamoGetItem,
28
+ DynamoPutItem,
29
+ LambdaInvoke,
30
+ SqsSendMessage,
31
+ StepFunctionsStartExecution,
32
+ } from 'aws-cdk-lib/aws-stepfunctions-tasks'
12
33
  import { v4 as uuidv4 } from 'uuid'
13
34
  import { CommonConstruct } from '../../../common'
35
+ import { createCfnOutput } from '../../../utils'
14
36
  import {
15
37
  SfnCallApiGatewayRestApiEndpointProps,
16
38
  SfnChoiceProps,
@@ -46,7 +68,7 @@ const DEFAULT_RETRY_CONFIG = [
46
68
  * import { CommonConstruct } from '@gradientedge/cdk-utils'
47
69
  *
48
70
  * class CustomConstruct extends CommonConstruct {
49
- * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
71
+ * constructor(parent: Construct, id: string, props: common.CommonStackProps) {
50
72
  * super(parent, id, props)
51
73
  * this.props = props
52
74
  * this.sfnManager.createSuccessStep('MyStep', this, myStepProps)
@@ -63,7 +85,7 @@ export class SfnManager {
63
85
  */
64
86
  public createSuccessStep(id: string, scope: CommonConstruct, props: SfnSucceedProps) {
65
87
  if (!props) throw `Step props undefined for ${id}`
66
- return new sfn.Succeed(scope, `${props.name}`, {
88
+ return new Succeed(scope, `${props.name}`, {
67
89
  ...props,
68
90
  ...{
69
91
  comment: `Succeed step for ${props.name} - ${scope.props.stage} stage`,
@@ -79,7 +101,7 @@ export class SfnManager {
79
101
  */
80
102
  public createFailStep(id: string, scope: CommonConstruct, props: SfnFailProps) {
81
103
  if (!props) throw `Step props undefined for ${id}`
82
- return new sfn.Fail(scope, `${props.name}`, {
104
+ return new Fail(scope, `${props.name}`, {
83
105
  ...props,
84
106
  ...{
85
107
  comment: `Fail step for ${props.name} - ${scope.props.stage} stage`,
@@ -95,7 +117,7 @@ export class SfnManager {
95
117
  */
96
118
  public createPassStep(id: string, scope: CommonConstruct, props: SfnPassProps) {
97
119
  if (!props) throw `Step props undefined for ${id}`
98
- return new sfn.Pass(scope, `${props.name}`, {
120
+ return new Pass(scope, `${props.name}`, {
99
121
  ...props,
100
122
  ...{
101
123
  comment: `Pass step for ${props.name} - ${scope.props.stage} stage`,
@@ -111,7 +133,7 @@ export class SfnManager {
111
133
  */
112
134
  public createParallelStep(id: string, scope: CommonConstruct, props: SfnParallelProps) {
113
135
  if (!props) throw `Step props undefined for ${id}`
114
- return new sfn.Parallel(scope, `${props.name}`, {
136
+ return new Parallel(scope, `${props.name}`, {
115
137
  ...props,
116
138
  ...{
117
139
  comment: `Parallel step for ${props.name} - ${scope.props.stage} stage`,
@@ -127,7 +149,7 @@ export class SfnManager {
127
149
  */
128
150
  public createChoiceStep(id: string, scope: CommonConstruct, props: SfnChoiceProps) {
129
151
  if (!props) throw `Step props undefined for ${id}`
130
- return new sfn.Choice(scope, `${props.name}`, {
152
+ return new Choice(scope, `${props.name}`, {
131
153
  ...props,
132
154
  ...{
133
155
  comment: `Choice step for ${props.name} - ${scope.props.stage} stage`,
@@ -142,11 +164,11 @@ export class SfnManager {
142
164
  * @param props
143
165
  */
144
166
  public createWaitStep(id: string, scope: CommonConstruct, props: SfnWaitProps) {
145
- return new sfn.Wait(scope, `${props.name}`, {
167
+ return new Wait(scope, `${props.name}`, {
146
168
  ...props,
147
169
  ...{
148
170
  comment: `Choice step for ${props.name} - ${scope.props.stage} stage`,
149
- time: sfn.WaitTime.duration(cdk.Duration.seconds(props.delayInSeconds)),
171
+ time: WaitTime.duration(Duration.seconds(props.delayInSeconds)),
150
172
  },
151
173
  })
152
174
  }
@@ -163,11 +185,11 @@ export class SfnManager {
163
185
  id: string,
164
186
  scope: CommonConstruct,
165
187
  props: SfnDynamoGetItemProps,
166
- table: dynamodb.ITable,
167
- tableKey: { [key: string]: tasks.DynamoAttributeValue }
188
+ table: ITable,
189
+ tableKey: { [key: string]: DynamoAttributeValue }
168
190
  ) {
169
191
  if (!props) throw `Step props undefined for ${id}`
170
- const step = new tasks.DynamoGetItem(scope, `${props.name}`, {
192
+ const step = new DynamoGetItem(scope, `${props.name}`, {
171
193
  ...props,
172
194
  ...{
173
195
  comment: `DynamoDB GetItem step for ${props.name} - ${scope.props.stage} stage`,
@@ -195,7 +217,7 @@ export class SfnManager {
195
217
  retries.forEach(retry =>
196
218
  step.addRetry({
197
219
  ...retry,
198
- ...{ interval: retry.intervalInSecs ? cdk.Duration.seconds(retry.intervalInSecs) : retry.interval },
220
+ ...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
199
221
  })
200
222
  )
201
223
 
@@ -214,11 +236,11 @@ export class SfnManager {
214
236
  id: string,
215
237
  scope: CommonConstruct,
216
238
  props: SfnDynamoPutItemProps,
217
- table: dynamodb.ITable,
218
- tableItem: { [key: string]: tasks.DynamoAttributeValue }
239
+ table: ITable,
240
+ tableItem: { [key: string]: DynamoAttributeValue }
219
241
  ) {
220
242
  if (!props) throw `Step props undefined for ${id}`
221
- const step = new tasks.DynamoPutItem(scope, `${props.name}`, {
243
+ const step = new DynamoPutItem(scope, `${props.name}`, {
222
244
  ...props,
223
245
  ...{
224
246
  comment: `DynamoDB PutItem step for ${props.name} - ${scope.props.stage} stage`,
@@ -248,7 +270,7 @@ export class SfnManager {
248
270
  retries.forEach(retry =>
249
271
  step.addRetry({
250
272
  ...retry,
251
- ...{ interval: retry.intervalInSecs ? cdk.Duration.seconds(retry.intervalInSecs) : retry.interval },
273
+ ...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
252
274
  })
253
275
  )
254
276
 
@@ -267,11 +289,11 @@ export class SfnManager {
267
289
  id: string,
268
290
  scope: CommonConstruct,
269
291
  props: SfnDynamoDeleteItemProps,
270
- table: dynamodb.ITable,
271
- tableKey: { [key: string]: tasks.DynamoAttributeValue }
292
+ table: ITable,
293
+ tableKey: { [key: string]: DynamoAttributeValue }
272
294
  ) {
273
295
  if (!props) throw `Step props undefined for ${id}`
274
- const step = new tasks.DynamoDeleteItem(scope, `${props.name}`, {
296
+ const step = new DynamoDeleteItem(scope, `${props.name}`, {
275
297
  ...props,
276
298
  ...{
277
299
  comment: `DynamoDB DeleteItem step for ${props.name} - ${scope.props.stage} stage`,
@@ -301,7 +323,7 @@ export class SfnManager {
301
323
  retries.forEach(retry =>
302
324
  step.addRetry({
303
325
  ...retry,
304
- ...{ interval: retry.intervalInSecs ? cdk.Duration.seconds(retry.intervalInSecs) : retry.interval },
326
+ ...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
305
327
  })
306
328
  )
307
329
 
@@ -315,15 +337,10 @@ export class SfnManager {
315
337
  * @param props
316
338
  * @param queue The queue to send the message to
317
339
  */
318
- public createSendSqsMessageStep(
319
- id: string,
320
- scope: CommonConstruct,
321
- props: SfnSqsSendMessageProps,
322
- queue: sqs.IQueue
323
- ) {
340
+ public createSendSqsMessageStep(id: string, scope: CommonConstruct, props: SfnSqsSendMessageProps, queue: IQueue) {
324
341
  if (!props) throw `Step props undefined for ${id}`
325
342
  if (!props.messageBody) throw 'Message body undefined'
326
- const step = new tasks.SqsSendMessage(scope, `${props.name}`, {
343
+ const step = new SqsSendMessage(scope, `${props.name}`, {
327
344
  ...props,
328
345
  ...{
329
346
  comment: `DynamoDB PutItem step for ${props.name} - ${scope.props.stage} stage`,
@@ -350,7 +367,7 @@ export class SfnManager {
350
367
  retries.forEach(retry =>
351
368
  step.addRetry({
352
369
  ...retry,
353
- ...{ interval: retry.intervalInSecs ? cdk.Duration.seconds(retry.intervalInSecs) : retry.interval },
370
+ ...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
354
371
  })
355
372
  )
356
373
 
@@ -364,14 +381,9 @@ export class SfnManager {
364
381
  * @param props
365
382
  * @param lambdaFunction
366
383
  */
367
- public createLambdaStep(
368
- id: string,
369
- scope: CommonConstruct,
370
- props: SfnLambdaInvokeProps,
371
- lambdaFunction: lambda.IFunction
372
- ) {
384
+ public createLambdaStep(id: string, scope: CommonConstruct, props: SfnLambdaInvokeProps, lambdaFunction: IFunction) {
373
385
  if (!props) throw `Step props undefined for ${id}`
374
- const step = new tasks.LambdaInvoke(scope, `${props.name}`, {
386
+ const step = new LambdaInvoke(scope, `${props.name}`, {
375
387
  ...props,
376
388
  ...{
377
389
  comment: `Lambda step for ${props.name} - ${scope.props.stage} stage`,
@@ -387,7 +399,7 @@ export class SfnManager {
387
399
  retries.forEach(retry =>
388
400
  step.addRetry({
389
401
  ...retry,
390
- ...{ interval: retry.intervalInSecs ? cdk.Duration.seconds(retry.intervalInSecs) : retry.interval },
402
+ ...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
391
403
  })
392
404
  )
393
405
 
@@ -406,12 +418,12 @@ export class SfnManager {
406
418
  id: string,
407
419
  scope: CommonConstruct,
408
420
  props: SfnLambdaInvokeProps,
409
- lambdaFunction: lambda.IFunction,
421
+ lambdaFunction: IFunction,
410
422
  skipExecution?: boolean
411
423
  ) {
412
424
  if (!props) throw `Step props undefined for ${id}`
413
- if (skipExecution) return this.createPassStep(id, scope, { name: props.name, comment: props.comment })
414
- const step = new tasks.LambdaInvoke(scope, `${props.name}`, {
425
+ if (skipExecution) return this.createPassStep(id, scope, { comment: props.comment, name: props.name })
426
+ const step = new LambdaInvoke(scope, `${props.name}`, {
415
427
  ...props,
416
428
  ...{
417
429
  comment: `Lambda step for ${props.name} - ${scope.props.stage} stage`,
@@ -427,7 +439,7 @@ export class SfnManager {
427
439
  retries.forEach(retry =>
428
440
  step.addRetry({
429
441
  ...retry,
430
- ...{ interval: retry.intervalInSecs ? cdk.Duration.seconds(retry.intervalInSecs) : retry.interval },
442
+ ...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
431
443
  })
432
444
  )
433
445
 
@@ -445,10 +457,10 @@ export class SfnManager {
445
457
  id: string,
446
458
  scope: CommonConstruct,
447
459
  props: SfnCallApiGatewayRestApiEndpointProps,
448
- api: apig.IRestApi
460
+ api: IRestApi
449
461
  ) {
450
462
  if (!props) throw `Step props undefined for ${id}`
451
- const step = new tasks.CallApiGatewayRestApiEndpoint(scope, `${props.name}`, {
463
+ const step = new CallApiGatewayRestApiEndpoint(scope, `${props.name}`, {
452
464
  ...props,
453
465
  ...{
454
466
  api,
@@ -465,7 +477,7 @@ export class SfnManager {
465
477
  retries.forEach(retry =>
466
478
  step.addRetry({
467
479
  ...retry,
468
- ...{ interval: retry.intervalInSecs ? cdk.Duration.seconds(retry.intervalInSecs) : retry.interval },
480
+ ...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
469
481
  })
470
482
  )
471
483
 
@@ -483,9 +495,9 @@ export class SfnManager {
483
495
  id: string,
484
496
  scope: CommonConstruct,
485
497
  props: SfnStartExecutionProps,
486
- stateMachine: sfn.IStateMachine
498
+ stateMachine: IStateMachine
487
499
  ) {
488
- const step = new tasks.StepFunctionsStartExecution(scope, `${id}`, {
500
+ const step = new StepFunctionsStartExecution(scope, `${id}`, {
489
501
  ...props,
490
502
  associateWithParent: props.associateWithParent ?? true,
491
503
  inputPath: props.inputPath,
@@ -501,7 +513,7 @@ export class SfnManager {
501
513
  retries.forEach(retry =>
502
514
  step.addRetry({
503
515
  ...retry,
504
- ...{ interval: retry.intervalInSecs ? cdk.Duration.seconds(retry.intervalInSecs) : retry.interval },
516
+ ...{ interval: retry.intervalInSecs ? Duration.seconds(retry.intervalInSecs) : retry.interval },
505
517
  })
506
518
  )
507
519
 
@@ -515,7 +527,7 @@ export class SfnManager {
515
527
  * @param props props for the map state
516
528
  */
517
529
  public createMapState(id: string, scope: CommonConstruct, props: SfnMapProps) {
518
- return new sfn.Map(scope, `${id}`, props)
530
+ return new Map(scope, `${id}`, props)
519
531
  }
520
532
 
521
533
  /**
@@ -531,17 +543,17 @@ export class SfnManager {
531
543
  id: string,
532
544
  scope: CommonConstruct,
533
545
  props: SfnStateMachineProps,
534
- definition: sfn.IChainable,
535
- logGroup: logs.ILogGroup,
536
- role?: iam.IRole
546
+ definition: IChainable,
547
+ logGroup: ILogGroup,
548
+ role?: IRole
537
549
  ) {
538
550
  if (!props) throw `State Machine props undefined for ${id}`
539
- const stateMachine = new sfn.StateMachine(scope, `${id}`, {
551
+ const stateMachine = new StateMachine(scope, `${id}`, {
540
552
  definitionBody: DefinitionBody.fromChainable(definition),
541
553
  logs: {
542
554
  destination: logGroup,
543
555
  includeExecutionData: props.logs?.includeExecutionData ?? true,
544
- level: props.logs?.level ?? sfn.LogLevel.ALL,
556
+ level: props.logs?.level ?? LogLevel.ALL,
545
557
  },
546
558
  role,
547
559
  stateMachineName: `${props.stateMachineName}-${scope.props.stage}`,
@@ -550,8 +562,8 @@ export class SfnManager {
550
562
  tracingEnabled: props.tracingEnabled,
551
563
  })
552
564
 
553
- utils.createCfnOutput(`${id}-stateMachineName`, scope, stateMachine.stateMachineName)
554
- utils.createCfnOutput(`${id}-stateMachineArn`, scope, stateMachine.stateMachineArn)
565
+ createCfnOutput(`${id}-stateMachineName`, scope, stateMachine.stateMachineName)
566
+ createCfnOutput(`${id}-stateMachineArn`, scope, stateMachine.stateMachineArn)
555
567
 
556
568
  return stateMachine
557
569
  }