@gradientedge/cdk-utils 4.10.1 → 4.11.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.
@@ -44,6 +44,7 @@ export declare class CommonConstruct extends Construct {
44
44
  ssMManager: aws.SsmManager;
45
45
  vpcManager: aws.VpcManager;
46
46
  wafManager: aws.WafManager;
47
+ sqsManager: aws.SqsManager;
47
48
  fullyQualifiedDomainName: string;
48
49
  constructor(parent: Construct, id: string, props: types.CommonStackProps);
49
50
  /**
@@ -69,6 +69,7 @@ class CommonConstruct extends constructs_1.Construct {
69
69
  ssMManager;
70
70
  vpcManager;
71
71
  wafManager;
72
+ sqsManager;
72
73
  fullyQualifiedDomainName;
73
74
  constructor(parent, id, props) {
74
75
  super(parent, id);
@@ -97,6 +98,7 @@ class CommonConstruct extends constructs_1.Construct {
97
98
  this.ssMManager = new aws.SsmManager();
98
99
  this.vpcManager = new aws.VpcManager();
99
100
  this.wafManager = new aws.WafManager();
101
+ this.sqsManager = new aws.SqsManager();
100
102
  this.determineFullyQualifiedDomain();
101
103
  }
102
104
  /**
@@ -1,8 +1,10 @@
1
1
  import * as cdk from 'aws-cdk-lib';
2
2
  import * as ecs from 'aws-cdk-lib/aws-ecs';
3
+ import * as events from 'aws-cdk-lib/aws-events';
3
4
  import * as iam from 'aws-cdk-lib/aws-iam';
4
5
  import * as logs from 'aws-cdk-lib/aws-logs';
5
6
  import * as s3 from 'aws-cdk-lib/aws-s3';
7
+ import * as sqs from 'aws-cdk-lib/aws-sqs';
6
8
  import * as common from '../../common';
7
9
  /**
8
10
  * @stability stable
@@ -151,4 +153,11 @@ export declare class IamManager {
151
153
  * @param {iam.ServicePrincipal} servicePrinicpal
152
154
  */
153
155
  createRoleForLambda(id: string, scope: common.CommonConstruct, policy: iam.PolicyDocument, servicePrinicpal?: iam.ServicePrincipal): cdk.aws_iam.Role;
156
+ /**
157
+ * @summary Method to create iam policy for sqs
158
+ * @param {string} id scoped id of the resource
159
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
160
+ * @param {iam.ServicePrincipal} servicePrinicpal
161
+ */
162
+ createPolicyForSqsEvent(id: string, scope: common.CommonConstruct, sqsQueue: sqs.Queue, eventBridgeRule: events.IRule, servicePrincipals?: iam.ServicePrincipal[]): cdk.aws_iam.PolicyDocument;
154
163
  }
@@ -380,5 +380,29 @@ class IamManager {
380
380
  utils.createCfnOutput(`${id}Name`, scope, role.roleName);
381
381
  return role;
382
382
  }
383
+ /**
384
+ * @summary Method to create iam policy for sqs
385
+ * @param {string} id scoped id of the resource
386
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
387
+ * @param {iam.ServicePrincipal} servicePrinicpal
388
+ */
389
+ createPolicyForSqsEvent(id, scope, sqsQueue, eventBridgeRule, servicePrincipals) {
390
+ const policy = new iam.PolicyDocument({
391
+ statements: [
392
+ new iam.PolicyStatement({
393
+ actions: ['sqs:*'],
394
+ effect: iam.Effect.ALLOW,
395
+ conditions: {
396
+ ArnEquals: {
397
+ 'aws:SourceArn': eventBridgeRule,
398
+ },
399
+ },
400
+ principals: servicePrincipals ?? [new iam.ServicePrincipal('events.amazonaws.com')],
401
+ resources: [sqsQueue.queueArn],
402
+ }),
403
+ ],
404
+ });
405
+ return policy;
406
+ }
383
407
  }
384
408
  exports.IamManager = IamManager;
@@ -19,6 +19,7 @@ export * from './route53-manager';
19
19
  export * from './s3-manager';
20
20
  export * from './secrets-manager';
21
21
  export * from './sns-manager';
22
+ export * from './sqs-manager';
22
23
  export * from './ssm-manager';
23
24
  export * from './vpc-manager';
24
25
  export * from './waf-manager';
@@ -35,6 +35,7 @@ __exportStar(require("./route53-manager"), exports);
35
35
  __exportStar(require("./s3-manager"), exports);
36
36
  __exportStar(require("./secrets-manager"), exports);
37
37
  __exportStar(require("./sns-manager"), exports);
38
+ __exportStar(require("./sqs-manager"), exports);
38
39
  __exportStar(require("./ssm-manager"), exports);
39
40
  __exportStar(require("./vpc-manager"), exports);
40
41
  __exportStar(require("./waf-manager"), exports);
@@ -0,0 +1,34 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import * as sqs from 'aws-cdk-lib/aws-sqs';
3
+ import * as common from '../../common';
4
+ import * as types from '../../types';
5
+ /**
6
+ * @stability stable
7
+ * @category cdk-utils.sqs-manager
8
+ * @subcategory Construct
9
+ * @classdesc Provides operations on AWS Simple Queue Service.
10
+ * - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
11
+ * - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
12
+ * @example
13
+ * import * as common from '@gradientedge/cdk-utils'
14
+ *
15
+ * class CustomConstruct extends common.common.CommonConstruct {
16
+ * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
17
+ * super(parent, id, props)
18
+ * this.props = props
19
+ * this.sqsManager.createSqsQueue('MySqs', this)
20
+ * }
21
+ * }
22
+ *
23
+ * @see [CDK Simple Queue Service Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs-readme.html}
24
+ */
25
+ export declare class SqsManager {
26
+ /**
27
+ * @summary Method to create a lambda queue service
28
+ * @param {string} id scoped id of the resource
29
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
30
+ * @param {types.QueueProps} props
31
+ * @param {sqs.deadLetterQueue} deadLetterQueue
32
+ */
33
+ createQueueService(id: string, scope: common.CommonConstruct, props: types.QueueProps, deadLetterQueue?: sqs.DeadLetterQueue): cdk.aws_sqs.Queue;
34
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.SqsManager = void 0;
27
+ const cdk = __importStar(require("aws-cdk-lib"));
28
+ const sqs = __importStar(require("aws-cdk-lib/aws-sqs"));
29
+ const utils = __importStar(require("../../utils"));
30
+ /**
31
+ * @stability stable
32
+ * @category cdk-utils.sqs-manager
33
+ * @subcategory Construct
34
+ * @classdesc Provides operations on AWS Simple Queue Service.
35
+ * - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
36
+ * - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
37
+ * @example
38
+ * import * as common from '@gradientedge/cdk-utils'
39
+ *
40
+ * class CustomConstruct extends common.common.CommonConstruct {
41
+ * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
42
+ * super(parent, id, props)
43
+ * this.props = props
44
+ * this.sqsManager.createSqsQueue('MySqs', this)
45
+ * }
46
+ * }
47
+ *
48
+ * @see [CDK Simple Queue Service Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs-readme.html}
49
+ */
50
+ class SqsManager {
51
+ /**
52
+ * @summary Method to create a lambda queue service
53
+ * @param {string} id scoped id of the resource
54
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
55
+ * @param {types.QueueProps} props
56
+ * @param {sqs.deadLetterQueue} deadLetterQueue
57
+ */
58
+ createQueueService(id, scope, props, deadLetterQueue) {
59
+ if (!props)
60
+ throw `Queue props undefined`;
61
+ const queue = new sqs.Queue(scope, id, {
62
+ queueName: props.queueName,
63
+ visibilityTimeout: cdk.Duration.seconds(props.visibilityTimeoutInSecs),
64
+ receiveMessageWaitTime: cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs),
65
+ contentBasedDeduplication: props.contentBasedDeduplication,
66
+ dataKeyReuse: cdk.Duration.seconds(props.dataKeyReuseInSecs),
67
+ deadLetterQueue: deadLetterQueue,
68
+ deduplicationScope: props.deduplicationScope,
69
+ deliveryDelay: cdk.Duration.seconds(props.deliveryDelayInSecs),
70
+ encryption: props.encryption,
71
+ encryptionMasterKey: props.encryptionMasterKey,
72
+ fifo: props.fifo,
73
+ fifoThroughputLimit: props.fifoThroughputLimit,
74
+ maxMessageSizeBytes: props.maxMessageSizeBytes,
75
+ removalPolicy: props.removalPolicy,
76
+ retentionPeriod: props.retentionPeriod,
77
+ });
78
+ utils.createCfnOutput(`${id}-queueArn`, scope, queue.queueArn);
79
+ utils.createCfnOutput(`${id}-queueName`, scope, queue.queueName);
80
+ utils.createCfnOutput(`${id}-queueUrl`, scope, queue.queueUrl);
81
+ return queue;
82
+ }
83
+ }
84
+ exports.SqsManager = SqsManager;
@@ -22,6 +22,7 @@ import * as route53 from 'aws-cdk-lib/aws-route53';
22
22
  import * as s3 from 'aws-cdk-lib/aws-s3';
23
23
  import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
24
24
  import * as sns from 'aws-cdk-lib/aws-sns';
25
+ import * as sqs from 'aws-cdk-lib/aws-sqs';
25
26
  import * as wafv2 from 'aws-cdk-lib/aws-wafv2';
26
27
  import * as types from '../index';
27
28
  /**
@@ -510,4 +511,14 @@ export interface WafWebACLProps extends wafv2.CfnWebACLProps {
510
511
  */
511
512
  export interface ElastiCacheProps extends elasticache.CfnCacheClusterProps {
512
513
  }
514
+ /**
515
+ * @category cdk-utils.sqs-manager
516
+ * @subcategory Properties
517
+ */
518
+ export interface QueueProps extends sqs.QueueProps {
519
+ visibilityTimeoutInSecs: number;
520
+ receiveMessageWaitTimeInSecs: number;
521
+ dataKeyReuseInSecs: number;
522
+ deliveryDelayInSecs: number;
523
+ }
513
524
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "4.10.1",
3
+ "version": "4.11.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -46,6 +46,8 @@ export class CommonConstruct extends Construct {
46
46
  ssMManager: aws.SsmManager
47
47
  vpcManager: aws.VpcManager
48
48
  wafManager: aws.WafManager
49
+ sqsManager: aws.SqsManager
50
+
49
51
  fullyQualifiedDomainName: string
50
52
 
51
53
  constructor(parent: Construct, id: string, props: types.CommonStackProps) {
@@ -75,6 +77,7 @@ export class CommonConstruct extends Construct {
75
77
  this.ssMManager = new aws.SsmManager()
76
78
  this.vpcManager = new aws.VpcManager()
77
79
  this.wafManager = new aws.WafManager()
80
+ this.sqsManager = new aws.SqsManager()
78
81
 
79
82
  this.determineFullyQualifiedDomain()
80
83
  }
@@ -81,6 +81,7 @@ export class EventManager {
81
81
 
82
82
  return rule
83
83
  }
84
+
84
85
  /**
85
86
  * @summary Method to create an eventbridge rule with lambda target
86
87
  * @param {string} id scoped id of the resource
@@ -1,8 +1,10 @@
1
1
  import * as cdk from 'aws-cdk-lib'
2
2
  import * as ecs from 'aws-cdk-lib/aws-ecs'
3
+ import * as events from 'aws-cdk-lib/aws-events'
3
4
  import * as iam from 'aws-cdk-lib/aws-iam'
4
5
  import * as logs from 'aws-cdk-lib/aws-logs'
5
6
  import * as s3 from 'aws-cdk-lib/aws-s3'
7
+ import * as sqs from 'aws-cdk-lib/aws-sqs'
6
8
  import * as common from '../../common'
7
9
  import * as utils from '../../utils'
8
10
 
@@ -412,4 +414,36 @@ export class IamManager {
412
414
 
413
415
  return role
414
416
  }
417
+
418
+ /**
419
+ * @summary Method to create iam policy for sqs
420
+ * @param {string} id scoped id of the resource
421
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
422
+ * @param {iam.ServicePrincipal} servicePrinicpal
423
+ */
424
+ public createPolicyForSqsEvent(
425
+ id: string,
426
+ scope: common.CommonConstruct,
427
+ sqsQueue: sqs.Queue,
428
+ eventBridgeRule: events.IRule,
429
+ servicePrincipals?: iam.ServicePrincipal[]
430
+ ) {
431
+ const policy = new iam.PolicyDocument({
432
+ statements: [
433
+ new iam.PolicyStatement({
434
+ actions: ['sqs:*'],
435
+ effect: iam.Effect.ALLOW,
436
+ conditions: {
437
+ ArnEquals: {
438
+ 'aws:SourceArn': eventBridgeRule,
439
+ },
440
+ },
441
+ principals: servicePrincipals ?? [new iam.ServicePrincipal('events.amazonaws.com')],
442
+ resources: [sqsQueue.queueArn],
443
+ }),
444
+ ],
445
+ })
446
+
447
+ return policy
448
+ }
415
449
  }
@@ -19,6 +19,7 @@ export * from './route53-manager'
19
19
  export * from './s3-manager'
20
20
  export * from './secrets-manager'
21
21
  export * from './sns-manager'
22
+ export * from './sqs-manager'
22
23
  export * from './ssm-manager'
23
24
  export * from './vpc-manager'
24
25
  export * from './waf-manager'
@@ -0,0 +1,67 @@
1
+ import * as cdk from 'aws-cdk-lib'
2
+ import * as sqs from 'aws-cdk-lib/aws-sqs'
3
+ import * as common from '../../common'
4
+ import * as types from '../../types'
5
+ import * as utils from '../../utils'
6
+
7
+ /**
8
+ * @stability stable
9
+ * @category cdk-utils.sqs-manager
10
+ * @subcategory Construct
11
+ * @classdesc Provides operations on AWS Simple Queue Service.
12
+ * - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
13
+ * - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
14
+ * @example
15
+ * import * as common from '@gradientedge/cdk-utils'
16
+ *
17
+ * class CustomConstruct extends common.common.CommonConstruct {
18
+ * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
19
+ * super(parent, id, props)
20
+ * this.props = props
21
+ * this.sqsManager.createSqsQueue('MySqs', this)
22
+ * }
23
+ * }
24
+ *
25
+ * @see [CDK Simple Queue Service Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs-readme.html}
26
+ */
27
+ export class SqsManager {
28
+ /**
29
+ * @summary Method to create a lambda queue service
30
+ * @param {string} id scoped id of the resource
31
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
32
+ * @param {types.QueueProps} props
33
+ * @param {sqs.deadLetterQueue} deadLetterQueue
34
+ */
35
+ public createQueueService(
36
+ id: string,
37
+ scope: common.CommonConstruct,
38
+ props: types.QueueProps,
39
+ deadLetterQueue?: sqs.DeadLetterQueue
40
+ ) {
41
+ if (!props) throw `Queue props undefined`
42
+
43
+ const queue = new sqs.Queue(scope, id, {
44
+ queueName: props.queueName,
45
+ visibilityTimeout: cdk.Duration.seconds(props.visibilityTimeoutInSecs),
46
+ receiveMessageWaitTime: cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs),
47
+ contentBasedDeduplication: props.contentBasedDeduplication,
48
+ dataKeyReuse: cdk.Duration.seconds(props.dataKeyReuseInSecs),
49
+ deadLetterQueue: deadLetterQueue,
50
+ deduplicationScope: props.deduplicationScope,
51
+ deliveryDelay: cdk.Duration.seconds(props.deliveryDelayInSecs),
52
+ encryption: props.encryption,
53
+ encryptionMasterKey: props.encryptionMasterKey,
54
+ fifo: props.fifo,
55
+ fifoThroughputLimit: props.fifoThroughputLimit,
56
+ maxMessageSizeBytes: props.maxMessageSizeBytes,
57
+ removalPolicy: props.removalPolicy,
58
+ retentionPeriod: props.retentionPeriod,
59
+ })
60
+
61
+ utils.createCfnOutput(`${id}-queueArn`, scope, queue.queueArn)
62
+ utils.createCfnOutput(`${id}-queueName`, scope, queue.queueName)
63
+ utils.createCfnOutput(`${id}-queueUrl`, scope, queue.queueUrl)
64
+
65
+ return queue
66
+ }
67
+ }
@@ -22,6 +22,7 @@ import * as route53 from 'aws-cdk-lib/aws-route53'
22
22
  import * as s3 from 'aws-cdk-lib/aws-s3'
23
23
  import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment'
24
24
  import * as sns from 'aws-cdk-lib/aws-sns'
25
+ import * as sqs from 'aws-cdk-lib/aws-sqs'
25
26
  import * as wafv2 from 'aws-cdk-lib/aws-wafv2'
26
27
  import * as types from '../index'
27
28
 
@@ -540,3 +541,14 @@ export interface WafWebACLProps extends wafv2.CfnWebACLProps {}
540
541
  * @category Compute
541
542
  */
542
543
  export interface ElastiCacheProps extends elasticache.CfnCacheClusterProps {}
544
+
545
+ /**
546
+ * @category cdk-utils.sqs-manager
547
+ * @subcategory Properties
548
+ */
549
+ export interface QueueProps extends sqs.QueueProps {
550
+ visibilityTimeoutInSecs: number
551
+ receiveMessageWaitTimeInSecs: number
552
+ dataKeyReuseInSecs: number
553
+ deliveryDelayInSecs: number
554
+ }