@gradientedge/cdk-utils 4.10.0 → 4.11.1

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
  /**
@@ -111,7 +111,7 @@ class EventManager {
111
111
  scheduleExpression: scheduleExpression,
112
112
  name: `${props.name}-${scope.props.stage}`,
113
113
  state: props.state,
114
- targets: [{ arn: lambdaFunction.functionArn, id: `${id}-${scope.props.stage}` }],
114
+ targets: [{ arn: lambdaFunction.functionArn, id: `${id}-${scope.props.stage}`, input: props.input ?? undefined }],
115
115
  });
116
116
  new lambda.CfnPermission(scope, `${id}LambdaPermission`, {
117
117
  action: 'lambda:InvokeFunction',
@@ -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);
@@ -58,7 +58,7 @@ class KmsManager {
58
58
  throw `KMS Key props undefined`;
59
59
  const key = new kms.Key(scope, `${id}`, {
60
60
  description: props.description,
61
- alias: props.alias,
61
+ alias: `${props.alias}-${scope.props.stage}`,
62
62
  enableKeyRotation: props.enableKeyRotation,
63
63
  enabled: props.enabled,
64
64
  keySpec: props.keySpec,
@@ -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
  /**
@@ -413,6 +414,7 @@ export interface EksClusterProps extends eks.ClusterProps {
413
414
  * @subcategory Properties
414
415
  */
415
416
  export interface RuleProps extends events.CfnRuleProps {
417
+ input?: string;
416
418
  }
417
419
  /**
418
420
  * @category cdk-utils.event-manager
@@ -510,4 +512,14 @@ export interface WafWebACLProps extends wafv2.CfnWebACLProps {
510
512
  */
511
513
  export interface ElastiCacheProps extends elasticache.CfnCacheClusterProps {
512
514
  }
515
+ /**
516
+ * @category cdk-utils.sqs-manager
517
+ * @subcategory Properties
518
+ */
519
+ export interface QueueProps extends sqs.QueueProps {
520
+ visibilityTimeoutInSecs: number;
521
+ receiveMessageWaitTimeInSecs: number;
522
+ dataKeyReuseInSecs: number;
523
+ deliveryDelayInSecs: number;
524
+ }
513
525
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "4.10.0",
3
+ "version": "4.11.1",
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
@@ -109,7 +110,7 @@ export class EventManager {
109
110
  scheduleExpression: scheduleExpression,
110
111
  name: `${props.name}-${scope.props.stage}`,
111
112
  state: props.state,
112
- targets: [{ arn: lambdaFunction.functionArn, id: `${id}-${scope.props.stage}` }],
113
+ targets: [{ arn: lambdaFunction.functionArn, id: `${id}-${scope.props.stage}`, input: props.input ?? undefined }],
113
114
  })
114
115
 
115
116
  new lambda.CfnPermission(scope, `${id}LambdaPermission`, {
@@ -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'
@@ -35,7 +35,7 @@ export class KmsManager {
35
35
 
36
36
  const key = new kms.Key(scope, `${id}`, {
37
37
  description: props.description,
38
- alias: props.alias,
38
+ alias: `${props.alias}-${scope.props.stage}`,
39
39
  enableKeyRotation: props.enableKeyRotation,
40
40
  enabled: props.enabled,
41
41
  keySpec: props.keySpec,
@@ -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
 
@@ -437,7 +438,9 @@ export interface EksClusterProps extends eks.ClusterProps {
437
438
  * @category cdk-utils.event-manager
438
439
  * @subcategory Properties
439
440
  */
440
- export interface RuleProps extends events.CfnRuleProps {}
441
+ export interface RuleProps extends events.CfnRuleProps {
442
+ input?: string
443
+ }
441
444
 
442
445
  /**
443
446
  * @category cdk-utils.event-manager
@@ -540,3 +543,14 @@ export interface WafWebACLProps extends wafv2.CfnWebACLProps {}
540
543
  * @category Compute
541
544
  */
542
545
  export interface ElastiCacheProps extends elasticache.CfnCacheClusterProps {}
546
+
547
+ /**
548
+ * @category cdk-utils.sqs-manager
549
+ * @subcategory Properties
550
+ */
551
+ export interface QueueProps extends sqs.QueueProps {
552
+ visibilityTimeoutInSecs: number
553
+ receiveMessageWaitTimeInSecs: number
554
+ dataKeyReuseInSecs: number
555
+ deliveryDelayInSecs: number
556
+ }