@gradientedge/cdk-utils 5.12.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/src/lib/construct/api-to-eventbridge-target/index.d.ts +0 -3
  2. package/dist/src/lib/construct/api-to-eventbridge-target/index.js +0 -3
  3. package/dist/src/lib/construct/api-to-eventbridge-target/main.d.ts +23 -68
  4. package/dist/src/lib/construct/api-to-eventbridge-target/main.js +120 -241
  5. package/dist/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.d.ts +1 -1
  6. package/dist/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.js +1 -1
  7. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/index.d.ts +2 -0
  8. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/index.js +18 -0
  9. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.d.ts +193 -0
  10. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.js +631 -0
  11. package/dist/src/lib/construct/index.d.ts +1 -0
  12. package/dist/src/lib/construct/index.js +1 -0
  13. package/dist/src/lib/construct/site-with-ecs-backend/main.d.ts +0 -7
  14. package/dist/src/lib/construct/site-with-ecs-backend/main.js +1 -12
  15. package/dist/src/lib/construct/static-site/main.d.ts +0 -7
  16. package/dist/src/lib/construct/static-site/main.js +1 -12
  17. package/dist/src/lib/{construct/api-to-eventbridge-target/api-destination-event.d.ts → helper/api-to-eventbridge-target-event.d.ts} +5 -3
  18. package/dist/src/lib/{construct/api-to-eventbridge-target/api-destination-event.js → helper/api-to-eventbridge-target-event.js} +6 -4
  19. package/dist/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.d.ts → helper/api-to-eventbridge-target-rest-api.d.ts} +4 -4
  20. package/dist/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.js → helper/api-to-eventbridge-target-rest-api.js} +5 -5
  21. package/dist/src/lib/helper/index.d.ts +2 -0
  22. package/dist/src/lib/helper/index.js +18 -0
  23. package/dist/src/lib/manager/aws/cloudfront-manager.d.ts +3 -6
  24. package/dist/src/lib/manager/aws/cloudfront-manager.js +6 -9
  25. package/dist/src/lib/manager/aws/sqs-manager.js +9 -6
  26. package/dist/src/lib/types/aws/index.d.ts +10 -7
  27. package/package.json +24 -24
  28. package/src/lib/construct/api-to-eventbridge-target/index.ts +0 -3
  29. package/src/lib/construct/api-to-eventbridge-target/main.ts +127 -278
  30. package/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.ts +1 -1
  31. package/src/lib/construct/api-to-eventbridge-target-with-sns/index.ts +2 -0
  32. package/src/lib/construct/api-to-eventbridge-target-with-sns/main.ts +703 -0
  33. package/src/lib/construct/index.ts +1 -0
  34. package/src/lib/construct/site-with-ecs-backend/main.ts +1 -15
  35. package/src/lib/construct/static-site/main.ts +1 -15
  36. package/src/lib/{construct/api-to-eventbridge-target/api-destination-event.ts → helper/api-to-eventbridge-target-event.ts} +5 -3
  37. package/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.ts → helper/api-to-eventbridge-target-rest-api.ts} +4 -4
  38. package/src/lib/helper/index.ts +2 -0
  39. package/src/lib/manager/aws/cloudfront-manager.ts +6 -12
  40. package/src/lib/manager/aws/sqs-manager.ts +9 -6
  41. package/src/lib/types/aws/index.ts +10 -7
@@ -1,4 +1,5 @@
1
1
  export * from './api-to-eventbridge-target'
2
+ export * from './api-to-eventbridge-target-with-sns'
2
3
  export * from './graphql-api-lambda'
3
4
  export * from './graphql-api-lambda-with-cache'
4
5
  export * from './site-with-ecs-backend'
@@ -11,7 +11,6 @@ import * as logs from 'aws-cdk-lib/aws-logs'
11
11
  import * as route53 from 'aws-cdk-lib/aws-route53'
12
12
  import * as s3 from 'aws-cdk-lib/aws-s3'
13
13
  import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
14
- import * as wafv2 from 'aws-cdk-lib/aws-wafv2'
15
14
  import { Construct } from 'constructs'
16
15
  import { CommonConstruct } from '../../common'
17
16
  import { SiteWithEcsBackendProps } from '../../types'
@@ -66,7 +65,6 @@ export class SiteWithEcsBackend extends CommonConstruct {
66
65
  siteDomainNames: string[]
67
66
  siteCloudfrontFunction: cloudfront.Function
68
67
  siteFunctionAssociations: cloudfront.FunctionAssociation[]
69
- siteWebAcl: wafv2.CfnWebACL
70
68
 
71
69
  constructor(parent: Construct, id: string, props: SiteWithEcsBackendProps) {
72
70
  super(parent, id, props)
@@ -97,7 +95,6 @@ export class SiteWithEcsBackend extends CommonConstruct {
97
95
  this.createSiteOrigin()
98
96
  this.createSiteCloudfrontFunction()
99
97
  this.resolveSiteFunctionAssociations()
100
- this.createSiteWebAcl()
101
98
  this.createDistribution()
102
99
  this.createNetworkMappings()
103
100
  this.invalidateDistributionCache()
@@ -342,16 +339,6 @@ export class SiteWithEcsBackend extends CommonConstruct {
342
339
  }
343
340
  }
344
341
 
345
- /**
346
- * @summary Method to create WAF
347
- * @protected
348
- */
349
- protected createSiteWebAcl() {
350
- if (!this.props.siteWebAcl) throw 'SiteWebAcl props undefined'
351
-
352
- this.siteWebAcl = this.wafManager.createWebAcl(`${this.id}-waf`, this, this.props.siteWebAcl)
353
- }
354
-
355
342
  /**
356
343
  * Method to create Site distribution
357
344
  * @protected
@@ -365,8 +352,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
365
352
  this.siteDomainNames,
366
353
  this.siteLogBucket,
367
354
  this.siteCertificate,
368
- this.siteFunctionAssociations,
369
- this.siteWebAcl.attrId
355
+ this.siteFunctionAssociations
370
356
  )
371
357
  }
372
358
 
@@ -3,7 +3,6 @@ import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'
3
3
  import * as origins from 'aws-cdk-lib/aws-cloudfront-origins'
4
4
  import * as route53 from 'aws-cdk-lib/aws-route53'
5
5
  import * as s3 from 'aws-cdk-lib/aws-s3'
6
- import * as wafv2 from 'aws-cdk-lib/aws-wafv2'
7
6
  import { Construct } from 'constructs'
8
7
  import { CommonConstruct } from '../../common'
9
8
  import { StaticSiteProps } from '../../types'
@@ -44,7 +43,6 @@ export class StaticSite extends CommonConstruct {
44
43
  siteOriginAccessIdentity: cloudfront.OriginAccessIdentity
45
44
  siteCloudfrontFunction: cloudfront.Function
46
45
  siteFunctionAssociations: cloudfront.FunctionAssociation[]
47
- siteWebAcl: wafv2.CfnWebACL
48
46
 
49
47
  constructor(parent: Construct, id: string, props: StaticSiteProps) {
50
48
  super(parent, id, props)
@@ -65,7 +63,6 @@ export class StaticSite extends CommonConstruct {
65
63
  this.createSiteOrigin()
66
64
  this.createSiteCloudfrontFunction()
67
65
  this.resolveSiteFunctionAssociations()
68
- this.createSiteWebAcl()
69
66
  this.createSiteDistribution()
70
67
  this.createSiteRouteAssets()
71
68
  this.deploySite()
@@ -156,16 +153,6 @@ export class StaticSite extends CommonConstruct {
156
153
  }
157
154
  }
158
155
 
159
- /**
160
- * @summary Method to create WAF
161
- * @protected
162
- */
163
- protected createSiteWebAcl() {
164
- if (!this.props.siteWebAcl) throw 'SiteWebAcl props undefined'
165
-
166
- this.siteWebAcl = this.wafManager.createWebAcl(`${this.id}-waf`, this, this.props.siteWebAcl)
167
- }
168
-
169
156
  /**
170
157
  * @summary Method to create a site cloudfront distribution
171
158
  * @protected
@@ -183,8 +170,7 @@ export class StaticSite extends CommonConstruct {
183
170
  this.siteOriginAccessIdentity,
184
171
  this.siteCertificate,
185
172
  this.props.siteAliases,
186
- this.siteFunctionAssociations,
187
- this.siteWebAcl.attrId
173
+ this.siteFunctionAssociations
188
174
  )
189
175
  }
190
176
 
@@ -1,17 +1,19 @@
1
1
  import * as events from 'aws-cdk-lib/aws-events'
2
2
  import * as logs from 'aws-cdk-lib/aws-logs'
3
- import * as types from '../../types/aws'
3
+ import * as types from '../types/aws'
4
4
 
5
5
  /**
6
6
  * @stability stable
7
7
  * @category cdk-utils.api-to-eventbridge-target
8
8
  * @subcategory member
9
- * @classdesc Provides a construct to contain event resources for ApiToEventBridgeTarget
9
+ * @classdesc Provides a construct to contain event resources for ApiToEventBridgeTargetWithSns
10
10
  */
11
- export class ApiDestinationEvent implements types.ApiDestinationEventType {
11
+ export class ApiToEventbridgeTargetEvent implements types.ApiToEventBridgeTargetEventType {
12
12
  eventBus: events.IEventBus
13
+ logGroup: logs.LogGroup
13
14
  logGroupFailure: logs.LogGroup
14
15
  logGroupSuccess: logs.LogGroup
16
+ rule: events.Rule
15
17
  ruleFailure: events.Rule
16
18
  ruleSuccess: events.Rule
17
19
  }
@@ -3,15 +3,15 @@ import * as acm from 'aws-cdk-lib/aws-certificatemanager'
3
3
  import * as iam from 'aws-cdk-lib/aws-iam'
4
4
  import * as route53 from 'aws-cdk-lib/aws-route53'
5
5
  import * as sns from 'aws-cdk-lib/aws-sns'
6
- import * as types from '../../types/aws'
6
+ import * as types from '../types/aws'
7
7
 
8
8
  /**
9
9
  * @stability stable
10
10
  * @category cdk-utils.api-to-eventbridge-target
11
11
  * @subcategory member
12
- * @classdesc Provides a construct to contain api resources for ApiToEventBridgeTarget
12
+ * @classdesc Provides a construct to contain api resources for ApiToEventBridgeTargetWithSns
13
13
  */
14
- export class ApiDestinedRestApi implements types.ApiDestinedRestApiType {
14
+ export class ApiToEventbridgeTargetRestApi implements types.ApiToEventBridgeTargetRestApiType {
15
15
  api: apig.RestApi
16
16
  certificate: acm.ICertificate
17
17
  domain: apig.DomainName
@@ -28,5 +28,5 @@ export class ApiDestinedRestApi implements types.ApiDestinedRestApiType {
28
28
  resource: apig.Resource
29
29
  responseModel: apig.Model
30
30
  topic: sns.Topic
31
- topicRole: iam.Role
31
+ role: iam.Role
32
32
  }
@@ -0,0 +1,2 @@
1
+ export * from './api-to-eventbridge-target-event'
2
+ export * from './api-to-eventbridge-target-rest-api'
@@ -61,7 +61,6 @@ export class CloudFrontManager {
61
61
  * @param {cloudfront.OriginAccessIdentity?} oai
62
62
  * @param {acm.ICertificate?} certificate
63
63
  * @param {string[]?} aliases
64
- * @param {string?} webAclId
65
64
  */
66
65
  public createCloudFrontDistribution(
67
66
  id: string,
@@ -71,8 +70,7 @@ export class CloudFrontManager {
71
70
  logBucket?: s3.IBucket,
72
71
  oai?: cloudfront.OriginAccessIdentity,
73
72
  certificate?: acm.ICertificate,
74
- aliases?: string[],
75
- webAclId?: string
73
+ aliases?: string[]
76
74
  ) {
77
75
  if (!siteBucket) throw `SiteBucket not defined`
78
76
  if (!certificate) throw `Certificate not defined`
@@ -105,7 +103,7 @@ export class CloudFrontManager {
105
103
  securityPolicy: cloudfront.SecurityPolicyProtocol.TLS_V1_1_2016,
106
104
  sslMethod: cloudfront.SSLMethod.SNI,
107
105
  }),
108
- webACLId: webAclId,
106
+ webACLId: props.webACLId,
109
107
  })
110
108
 
111
109
  utils.createCfnOutput(`${id}-distributionId`, scope, distribution.distributionId)
@@ -126,7 +124,6 @@ export class CloudFrontManager {
126
124
  * @param {acm.ICertificate?} certificate
127
125
  * @param {string[]?} aliases
128
126
  * @param {cloudfront.FunctionAssociation?} defaultFunctionAssociations
129
- * @param {string?} webAclId
130
127
  */
131
128
  public createDistributionWithS3Origin(
132
129
  id: string,
@@ -138,8 +135,7 @@ export class CloudFrontManager {
138
135
  oai?: cloudfront.OriginAccessIdentity,
139
136
  certificate?: acm.ICertificate,
140
137
  aliases?: string[],
141
- defaultFunctionAssociations?: cloudfront.FunctionAssociation[],
142
- webAclId?: string
138
+ defaultFunctionAssociations?: cloudfront.FunctionAssociation[]
143
139
  ) {
144
140
  const distribution = new cloudfront.Distribution(scope, `${id}`, {
145
141
  certificate: certificate,
@@ -165,7 +161,7 @@ export class CloudFrontManager {
165
161
  logFilePrefix: props.logFilePrefix ?? `edge/`,
166
162
  minimumProtocolVersion: props.minimumProtocolVersion ?? cloudfront.SecurityPolicyProtocol.TLS_V1_2_2021,
167
163
  priceClass: props.priceClass ?? cloudfront.PriceClass.PRICE_CLASS_ALL,
168
- webAclId: webAclId,
164
+ webAclId: props.webAclId,
169
165
  })
170
166
 
171
167
  utils.createCfnOutput(`${id}-distributionId`, scope, distribution.distributionId)
@@ -184,7 +180,6 @@ export class CloudFrontManager {
184
180
  * @param {s3.IBucket?} logBucket
185
181
  * @param {acm.ICertificate?} certificate
186
182
  * @param {cloudfront.FunctionAssociation?} defaultFunctionAssociations
187
- * @param {string?} webAclId
188
183
  */
189
184
  public createDistributionWithHttpOrigin(
190
185
  id: string,
@@ -194,8 +189,7 @@ export class CloudFrontManager {
194
189
  domainNames: string[],
195
190
  logBucket?: s3.IBucket,
196
191
  certificate?: acm.ICertificate,
197
- defaultFunctionAssociations?: cloudfront.FunctionAssociation[],
198
- webAclId?: string
192
+ defaultFunctionAssociations?: cloudfront.FunctionAssociation[]
199
193
  ) {
200
194
  const distribution = new cloudfront.Distribution(scope, `${id}`, {
201
195
  certificate: certificate,
@@ -221,7 +215,7 @@ export class CloudFrontManager {
221
215
  logFilePrefix: props.logFilePrefix ?? `edge/`,
222
216
  minimumProtocolVersion: props.minimumProtocolVersion ?? cloudfront.SecurityPolicyProtocol.TLS_V1_2_2021,
223
217
  priceClass: props.priceClass ?? cloudfront.PriceClass.PRICE_CLASS_ALL,
224
- webAclId: webAclId,
218
+ webAclId: props.webAclId,
225
219
  })
226
220
 
227
221
  utils.createCfnOutput(`${id}-distributionId`, scope, distribution.distributionId)
@@ -37,10 +37,14 @@ export class SqsManager {
37
37
 
38
38
  const queue = new sqs.Queue(scope, id, {
39
39
  queueName: props.queueName,
40
- visibilityTimeout: cdk.Duration.seconds(props.visibilityTimeoutInSecs),
41
- receiveMessageWaitTime: cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs),
40
+ visibilityTimeout: props.visibilityTimeoutInSecs
41
+ ? cdk.Duration.seconds(props.visibilityTimeoutInSecs)
42
+ : undefined,
43
+ receiveMessageWaitTime: props.receiveMessageWaitTimeInSecs
44
+ ? cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs)
45
+ : undefined,
42
46
  contentBasedDeduplication: props.contentBasedDeduplication,
43
- dataKeyReuse: cdk.Duration.seconds(props.dataKeyReuseInSecs),
47
+ dataKeyReuse: props.dataKeyReuseInSecs ? cdk.Duration.seconds(props.dataKeyReuseInSecs) : undefined,
44
48
  deadLetterQueue: !deadLetterQueue
45
49
  ? undefined
46
50
  : {
@@ -48,7 +52,7 @@ export class SqsManager {
48
52
  maxReceiveCount: props.maxReceiveCount,
49
53
  },
50
54
  deduplicationScope: props.deduplicationScope,
51
- deliveryDelay: cdk.Duration.seconds(props.deliveryDelayInSecs),
55
+ deliveryDelay: props.deliveryDelayInSecs ? cdk.Duration.seconds(props.deliveryDelayInSecs) : undefined,
52
56
  encryption: props.encryption,
53
57
  encryptionMasterKey: props.encryptionMasterKey,
54
58
  fifo: props.fifo,
@@ -72,10 +76,9 @@ export class SqsManager {
72
76
  * @param {types.LambdaProps} props the lambda properties
73
77
  */
74
78
  public createRedriveQueueForLambda(id: string, scope: common.CommonConstruct, props: types.LambdaProps) {
75
- if (!props.dlq || !props.redriveq) throw `Redrive queue props for Lambda undefined`
79
+ if (!props.redriveq) throw `Redrive queue props for Lambda undefined`
76
80
 
77
81
  return this.createQueue(`${id}`, scope, {
78
- ...props.dlq,
79
82
  ...props.redriveq,
80
83
  ...{
81
84
  queueName: `${props.functionName}-redriveq-${scope.props.stage}`,
@@ -75,7 +75,6 @@ export interface SiteWithEcsBackendProps extends CommonStackProps {
75
75
  siteSubDomain: string
76
76
  siteTask: ecsPatterns.ApplicationLoadBalancedFargateServiceProps
77
77
  siteVpc: ec2.VpcProps
78
- siteWebAcl?: WafWebACLProps
79
78
  useExistingHostedZone: boolean
80
79
  nodeEnv: string
81
80
  logLevel: string
@@ -99,7 +98,6 @@ export interface StaticSiteProps extends CommonStackProps {
99
98
  siteRecordName?: string
100
99
  siteSubDomain?: string
101
100
  siteAliases?: string[]
102
- siteWebAcl?: WafWebACLProps
103
101
  useExistingHostedZone: boolean
104
102
  nodeEnv: string
105
103
  logLevel: string
@@ -244,10 +242,12 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
244
242
  * @category cdk-utils.api-to-eventbridge-target
245
243
  * @subcategory Types
246
244
  */
247
- export interface ApiDestinationEventType {
245
+ export interface ApiToEventBridgeTargetEventType {
248
246
  eventBus: events.IEventBus
247
+ logGroup: logs.LogGroup
249
248
  logGroupFailure: logs.LogGroup
250
249
  logGroupSuccess: logs.LogGroup
250
+ rule: events.Rule
251
251
  ruleFailure: events.Rule
252
252
  ruleSuccess: events.Rule
253
253
  }
@@ -256,7 +256,7 @@ export interface ApiDestinationEventType {
256
256
  * @category cdk-utils.api-to-eventbridge-target
257
257
  * @subcategory Types
258
258
  */
259
- export interface ApiDestinedRestApiType {
259
+ export interface ApiToEventBridgeTargetRestApiType {
260
260
  api: apig.IRestApi
261
261
  authoriser?: apig.IAuthorizer
262
262
  certificate: acm.ICertificate
@@ -273,8 +273,9 @@ export interface ApiDestinedRestApiType {
273
273
  methodResponse: apig.MethodResponse
274
274
  resource: apig.Resource
275
275
  responseModel: apig.Model
276
- topic: sns.ITopic
277
- topicRole: iam.Role
276
+ topic?: sns.ITopic
277
+ role?: iam.Role
278
+ policy?: iam.PolicyDocument
278
279
  }
279
280
 
280
281
  /**
@@ -331,8 +332,10 @@ interface ApiToEventBridgeTargetLambdaProps {
331
332
  */
332
333
  interface ApiToEventBridgeTargetEventProps {
333
334
  eventBusName?: string
335
+ logGroup?: LogProps
334
336
  logGroupSuccess?: LogProps
335
337
  logGroupFailure?: LogProps
338
+ rule: EventRuleProps
336
339
  ruleSuccess: EventRuleProps
337
340
  ruleFailure: EventRuleProps
338
341
  }
@@ -346,7 +349,7 @@ export interface ApiToEventBridgeTargetProps extends CommonStackProps {
346
349
  apiSubDomain: string
347
350
  api: ApiToEventBridgeTargetRestApiProps
348
351
  event: ApiToEventBridgeTargetEventProps
349
- lambda: ApiToEventBridgeTargetLambdaProps
352
+ lambda?: ApiToEventBridgeTargetLambdaProps
350
353
  logLevel: string
351
354
  nodeEnv: string
352
355
  timezone: string