@gradientedge/cdk-utils 8.57.0 → 8.59.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.
@@ -4,6 +4,9 @@ import * as iam from 'aws-cdk-lib/aws-iam';
4
4
  import * as lambda from 'aws-cdk-lib/aws-lambda';
5
5
  import * as common from '../../common';
6
6
  import * as types from '../../types';
7
+ import * as cdk from 'aws-cdk-lib';
8
+ import * as sqs from 'aws-cdk-lib/aws-sqs';
9
+ import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
7
10
  /**
8
11
  * @stability stable
9
12
  * @category cdk-utils.event-manager
@@ -64,4 +67,13 @@ export declare class EventManager {
64
67
  * @param {any} eventPattern
65
68
  */
66
69
  createFargateTaskRule(id: string, scope: common.CommonConstruct, props: types.RuleProps, cluster: ecs.ICluster, task: ecs.ITaskDefinition, subnetIds: string[], role: iam.Role | iam.CfnRole, eventPattern?: any): events.CfnRule;
70
+ /**
71
+ * @summary Method to create an eventbridge pipe with sqs queue as source and step function as target
72
+ * @param {string} id scoped id of the resource
73
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
74
+ * @param props the props for the pipe
75
+ * @param sourceQueue the source sqs queue
76
+ * @param targetStepFunction the target step function
77
+ */
78
+ createSqsToSfnCfnPipe(id: string, scope: common.CommonConstruct, props: types.SqsToSfnPipeProps, sourceQueue: sqs.IQueue, targetStepFunction: sfn.IStateMachine): cdk.aws_pipes.CfnPipe;
67
79
  }
@@ -29,6 +29,7 @@ const iam = __importStar(require("aws-cdk-lib/aws-iam"));
29
29
  const lambda = __importStar(require("aws-cdk-lib/aws-lambda"));
30
30
  const utils = __importStar(require("../../utils"));
31
31
  const cdk = __importStar(require("aws-cdk-lib"));
32
+ const pipes = __importStar(require("aws-cdk-lib/aws-pipes"));
32
33
  /**
33
34
  * @stability stable
34
35
  * @category cdk-utils.event-manager
@@ -170,5 +171,50 @@ class EventManager {
170
171
  utils.createCfnOutput(`${id}-ruleName`, scope, eventRule.name);
171
172
  return eventRule;
172
173
  }
174
+ /**
175
+ * @summary Method to create an eventbridge pipe with sqs queue as source and step function as target
176
+ * @param {string} id scoped id of the resource
177
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
178
+ * @param props the props for the pipe
179
+ * @param sourceQueue the source sqs queue
180
+ * @param targetStepFunction the target step function
181
+ */
182
+ createSqsToSfnCfnPipe(id, scope, props, sourceQueue, targetStepFunction) {
183
+ const pipeRole = scope.iamManager.createRoleForSqsToSfnPipe(`${id}-role`, scope, sourceQueue.queueArn, targetStepFunction.stateMachineArn);
184
+ const pipe = new pipes.CfnPipe(scope, `${id}`, {
185
+ ...props,
186
+ name: `${props.name}-${scope.props.stage}`,
187
+ description: '',
188
+ source: sourceQueue.queueArn,
189
+ sourceParameters: {
190
+ filterCriteria: props.pipeFilterPattern
191
+ ? {
192
+ filters: [
193
+ {
194
+ pattern: JSON.stringify(props.pipeFilterPattern),
195
+ },
196
+ ],
197
+ }
198
+ : undefined,
199
+ sqsQueueParameters: {
200
+ batchSize: props.sqsBatchSize,
201
+ maximumBatchingWindowInSeconds: props.sqsMaximumBatchingWindowInSeconds,
202
+ },
203
+ },
204
+ target: targetStepFunction.stateMachineArn,
205
+ targetParameters: {
206
+ inputTemplate: props.sfnInputTemplate,
207
+ stepFunctionStateMachineParameters: {
208
+ invocationType: props.sfnInvocationType ?? 'FIRE_AND_FORGET',
209
+ },
210
+ },
211
+ enrichment: props.enrichment,
212
+ enrichmentParameters: props.enrichmentParameters,
213
+ roleArn: pipeRole.roleArn,
214
+ });
215
+ utils.createCfnOutput(`${id}-pipeArn`, scope, pipe.attrArn);
216
+ utils.createCfnOutput(`${id}-pipeName`, scope, pipe.name);
217
+ return pipe;
218
+ }
173
219
  }
174
220
  exports.EventManager = EventManager;
@@ -38,6 +38,16 @@ export declare class IamManager {
38
38
  * @param {string[]} resourceArns list of ARNs to allow access to
39
39
  */
40
40
  statementForPutEvents(resourceArns?: string[]): cdk.aws_iam.PolicyStatement;
41
+ /**
42
+ * @summary Method to create iam statement to start stepfunction execution
43
+ * @param {string[]} resourceArns list of ARNs to allow access to
44
+ */
45
+ statementForStartExecution(resourceArns?: string[]): cdk.aws_iam.PolicyStatement;
46
+ /**
47
+ * @summary Method to create iam statement to poll queue
48
+ * @param {string[]} resourceArns list of ARNs to allow access to
49
+ */
50
+ statementForPollQueue(resourceArns?: string[]): cdk.aws_iam.PolicyStatement;
41
51
  /**
42
52
  * @summary Method to create iam statement to invoke lambda function
43
53
  * @param {string[]} resourceArns list of ARNs to allow access to
@@ -189,6 +199,14 @@ export declare class IamManager {
189
199
  * @param {iam.ServicePrincipal} servicePrinicpal
190
200
  */
191
201
  createRoleForStepFunction(id: string, scope: common.CommonConstruct, policy: iam.PolicyDocument, servicePrinicpal?: iam.ServicePrincipal): cdk.aws_iam.Role;
202
+ /**
203
+ * @summary Method to create iam statement for sqs to step function pipe
204
+ * @param {string} id scoped id of the resource
205
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
206
+ * @param {string} queueArn the arn of the sqs queue
207
+ * @param {string} stepFunctionArn the arn of the step function
208
+ */
209
+ createRoleForSqsToSfnPipe(id: string, scope: common.CommonConstruct, queueArn: string, stepFunctionArn: string): cdk.aws_iam.Role;
192
210
  /**
193
211
  * @summary Method to create iam policy for sqs
194
212
  * @param {string} id scoped id of the resource
@@ -73,6 +73,28 @@ class IamManager {
73
73
  resources: resourceArns ?? ['*'],
74
74
  });
75
75
  }
76
+ /**
77
+ * @summary Method to create iam statement to start stepfunction execution
78
+ * @param {string[]} resourceArns list of ARNs to allow access to
79
+ */
80
+ statementForStartExecution(resourceArns) {
81
+ return new iam.PolicyStatement({
82
+ effect: iam.Effect.ALLOW,
83
+ actions: ['states:StartExecution'],
84
+ resources: resourceArns ?? ['*'],
85
+ });
86
+ }
87
+ /**
88
+ * @summary Method to create iam statement to poll queue
89
+ * @param {string[]} resourceArns list of ARNs to allow access to
90
+ */
91
+ statementForPollQueue(resourceArns) {
92
+ return new iam.PolicyStatement({
93
+ effect: iam.Effect.ALLOW,
94
+ actions: ['sqs:ReceiveMessage', 'sqs:DeleteMessage', 'sqs:GetQueueAttributes'],
95
+ resources: resourceArns ?? ['*'],
96
+ });
97
+ }
76
98
  /**
77
99
  * @summary Method to create iam statement to invoke lambda function
78
100
  * @param {string[]} resourceArns list of ARNs to allow access to
@@ -458,6 +480,25 @@ class IamManager {
458
480
  utils.createCfnOutput(`${id}Name`, scope, role.roleName);
459
481
  return role;
460
482
  }
483
+ /**
484
+ * @summary Method to create iam statement for sqs to step function pipe
485
+ * @param {string} id scoped id of the resource
486
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
487
+ * @param {string} queueArn the arn of the sqs queue
488
+ * @param {string} stepFunctionArn the arn of the step function
489
+ */
490
+ createRoleForSqsToSfnPipe(id, scope, queueArn, stepFunctionArn) {
491
+ const role = new iam.Role(scope, `${id}`, {
492
+ assumedBy: new iam.ServicePrincipal('pipes.amazonaws.com'),
493
+ description: `Role for ${id} Pipe`,
494
+ roleName: `${id}-${scope.props.stage}`,
495
+ });
496
+ role.addToPolicy(this.statementForPollQueue([queueArn]));
497
+ role.addToPolicy(this.statementForStartExecution([stepFunctionArn]));
498
+ utils.createCfnOutput(`${id}Arn`, scope, role.roleArn);
499
+ utils.createCfnOutput(`${id}Name`, scope, role.roleName);
500
+ return role;
501
+ }
461
502
  /**
462
503
  * @summary Method to create iam policy for sqs
463
504
  * @param {string} id scoped id of the resource
@@ -129,6 +129,13 @@ export declare class SfnManager {
129
129
  * @param {apig.IRestApi} api
130
130
  */
131
131
  createApiStep(id: string, scope: common.CommonConstruct, props: types.SfnCallApiGatewayRestApiEndpointProps, api: apig.IRestApi): cdk.aws_stepfunctions_tasks.CallApiGatewayRestApiEndpoint;
132
+ /**
133
+ * @summary Method to create a step function map state
134
+ * @param {string} id scoped id of the resource
135
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
136
+ * @param {types.SfnMapProps} props props for the map state
137
+ */
138
+ createMapState(id: string, scope: common.CommonConstruct, props: types.SfnMapProps): cdk.aws_stepfunctions.Map;
132
139
  /**
133
140
  * @summary Method to create a state machine
134
141
  * @param {string} id scoped id of the resource
@@ -358,6 +358,15 @@ class SfnManager {
358
358
  }
359
359
  return step;
360
360
  }
361
+ /**
362
+ * @summary Method to create a step function map state
363
+ * @param {string} id scoped id of the resource
364
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
365
+ * @param {types.SfnMapProps} props props for the map state
366
+ */
367
+ createMapState(id, scope, props) {
368
+ return new sfn.Map(scope, `${id}`, props);
369
+ }
361
370
  /**
362
371
  * @summary Method to create a state machine
363
372
  * @param {string} id scoped id of the resource
@@ -29,6 +29,7 @@ import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
29
29
  import * as wafv2 from 'aws-cdk-lib/aws-wafv2';
30
30
  import * as types from '../index';
31
31
  import * as appAutoscaling from 'aws-cdk-lib/aws-applicationautoscaling';
32
+ import * as pipes from 'aws-cdk-lib/aws-pipes';
32
33
  /**
33
34
  * @category cdk-utils.app-config-manager
34
35
  * @subcategory Properties
@@ -660,6 +661,24 @@ export interface EksClusterProps extends eks.ClusterProps {
660
661
  export interface RuleProps extends events.CfnRuleProps {
661
662
  input?: string;
662
663
  }
664
+ /**
665
+ * @category cdk-utils.sfn-manager
666
+ * @subcategory Properties
667
+ */
668
+ export interface SfnMapProps extends sfn.MapProps {
669
+ }
670
+ /**
671
+ }
672
+ * @category cdk-utils.event-manager
673
+ * @subcategory Properties
674
+ */
675
+ export interface SqsToSfnPipeProps extends pipes.CfnPipeProps {
676
+ pipeFilterPattern?: any;
677
+ sqsBatchSize?: number;
678
+ sqsMaximumBatchingWindowInSeconds?: number;
679
+ sfnInvocationType?: string;
680
+ sfnInputTemplate?: string;
681
+ }
663
682
  /**
664
683
  * @category cdk-utils.event-manager
665
684
  * @subcategory Properties
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.57.0",
3
+ "version": "8.59.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -6,6 +6,9 @@ import * as common from '../../common'
6
6
  import * as types from '../../types'
7
7
  import * as utils from '../../utils'
8
8
  import * as cdk from 'aws-cdk-lib'
9
+ import * as pipes from 'aws-cdk-lib/aws-pipes'
10
+ import * as sqs from 'aws-cdk-lib/aws-sqs'
11
+ import * as sfn from 'aws-cdk-lib/aws-stepfunctions'
9
12
 
10
13
  /**
11
14
  * @stability stable
@@ -185,4 +188,64 @@ export class EventManager {
185
188
 
186
189
  return eventRule
187
190
  }
191
+
192
+ /**
193
+ * @summary Method to create an eventbridge pipe with sqs queue as source and step function as target
194
+ * @param {string} id scoped id of the resource
195
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
196
+ * @param props the props for the pipe
197
+ * @param sourceQueue the source sqs queue
198
+ * @param targetStepFunction the target step function
199
+ */
200
+ public createSqsToSfnCfnPipe(
201
+ id: string,
202
+ scope: common.CommonConstruct,
203
+ props: types.SqsToSfnPipeProps,
204
+ sourceQueue: sqs.IQueue,
205
+ targetStepFunction: sfn.IStateMachine
206
+ ) {
207
+ const pipeRole = scope.iamManager.createRoleForSqsToSfnPipe(
208
+ `${id}-role`,
209
+ scope,
210
+ sourceQueue.queueArn,
211
+ targetStepFunction.stateMachineArn
212
+ )
213
+
214
+ const pipe = new pipes.CfnPipe(scope, `${id}`, {
215
+ ...props,
216
+ name: `${props.name}-${scope.props.stage}`,
217
+ description: '',
218
+ source: sourceQueue.queueArn,
219
+ sourceParameters: {
220
+ filterCriteria: props.pipeFilterPattern
221
+ ? {
222
+ filters: [
223
+ {
224
+ pattern: JSON.stringify(props.pipeFilterPattern),
225
+ },
226
+ ],
227
+ }
228
+ : undefined,
229
+ sqsQueueParameters: {
230
+ batchSize: props.sqsBatchSize,
231
+ maximumBatchingWindowInSeconds: props.sqsMaximumBatchingWindowInSeconds,
232
+ },
233
+ },
234
+ target: targetStepFunction.stateMachineArn,
235
+ targetParameters: {
236
+ inputTemplate: props.sfnInputTemplate,
237
+ stepFunctionStateMachineParameters: {
238
+ invocationType: props.sfnInvocationType ?? 'FIRE_AND_FORGET',
239
+ },
240
+ },
241
+ enrichment: props.enrichment,
242
+ enrichmentParameters: props.enrichmentParameters,
243
+ roleArn: pipeRole.roleArn,
244
+ })
245
+
246
+ utils.createCfnOutput(`${id}-pipeArn`, scope, pipe.attrArn)
247
+ utils.createCfnOutput(`${id}-pipeName`, scope, pipe.name)
248
+
249
+ return pipe
250
+ }
188
251
  }
@@ -56,6 +56,30 @@ export class IamManager {
56
56
  })
57
57
  }
58
58
 
59
+ /**
60
+ * @summary Method to create iam statement to start stepfunction execution
61
+ * @param {string[]} resourceArns list of ARNs to allow access to
62
+ */
63
+ public statementForStartExecution(resourceArns?: string[]) {
64
+ return new iam.PolicyStatement({
65
+ effect: iam.Effect.ALLOW,
66
+ actions: ['states:StartExecution'],
67
+ resources: resourceArns ?? ['*'],
68
+ })
69
+ }
70
+
71
+ /**
72
+ * @summary Method to create iam statement to poll queue
73
+ * @param {string[]} resourceArns list of ARNs to allow access to
74
+ */
75
+ public statementForPollQueue(resourceArns?: string[]) {
76
+ return new iam.PolicyStatement({
77
+ effect: iam.Effect.ALLOW,
78
+ actions: ['sqs:ReceiveMessage', 'sqs:DeleteMessage', 'sqs:GetQueueAttributes'],
79
+ resources: resourceArns ?? ['*'],
80
+ })
81
+ }
82
+
59
83
  /**
60
84
  * @summary Method to create iam statement to invoke lambda function
61
85
  * @param {string[]} resourceArns list of ARNs to allow access to
@@ -508,6 +532,34 @@ export class IamManager {
508
532
  return role
509
533
  }
510
534
 
535
+ /**
536
+ * @summary Method to create iam statement for sqs to step function pipe
537
+ * @param {string} id scoped id of the resource
538
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
539
+ * @param {string} queueArn the arn of the sqs queue
540
+ * @param {string} stepFunctionArn the arn of the step function
541
+ */
542
+ public createRoleForSqsToSfnPipe(
543
+ id: string,
544
+ scope: common.CommonConstruct,
545
+ queueArn: string,
546
+ stepFunctionArn: string
547
+ ) {
548
+ const role = new iam.Role(scope, `${id}`, {
549
+ assumedBy: new iam.ServicePrincipal('pipes.amazonaws.com'),
550
+ description: `Role for ${id} Pipe`,
551
+ roleName: `${id}-${scope.props.stage}`,
552
+ })
553
+
554
+ role.addToPolicy(this.statementForPollQueue([queueArn]))
555
+ role.addToPolicy(this.statementForStartExecution([stepFunctionArn]))
556
+
557
+ utils.createCfnOutput(`${id}Arn`, scope, role.roleArn)
558
+ utils.createCfnOutput(`${id}Name`, scope, role.roleName)
559
+
560
+ return role
561
+ }
562
+
511
563
  /**
512
564
  * @summary Method to create iam policy for sqs
513
565
  * @param {string} id scoped id of the resource
@@ -10,6 +10,7 @@ import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks'
10
10
  import * as common from '../../common'
11
11
  import * as types from '../../types'
12
12
  import * as utils from '../../utils'
13
+ import { SfnMapProps } from '../../types'
13
14
 
14
15
  /**
15
16
  * @stability stable
@@ -402,6 +403,16 @@ export class SfnManager {
402
403
  return step
403
404
  }
404
405
 
406
+ /**
407
+ * @summary Method to create a step function map state
408
+ * @param {string} id scoped id of the resource
409
+ * @param {common.CommonConstruct} scope scope in which this resource is defined
410
+ * @param {types.SfnMapProps} props props for the map state
411
+ */
412
+ public createMapState(id: string, scope: common.CommonConstruct, props: types.SfnMapProps) {
413
+ return new sfn.Map(scope, `${id}`, props)
414
+ }
415
+
405
416
  /**
406
417
  * @summary Method to create a state machine
407
418
  * @param {string} id scoped id of the resource
@@ -29,6 +29,7 @@ import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks'
29
29
  import * as wafv2 from 'aws-cdk-lib/aws-wafv2'
30
30
  import * as types from '../index'
31
31
  import * as appAutoscaling from 'aws-cdk-lib/aws-applicationautoscaling'
32
+ import * as pipes from 'aws-cdk-lib/aws-pipes'
32
33
 
33
34
  /**
34
35
  * @category cdk-utils.app-config-manager
@@ -706,6 +707,25 @@ export interface RuleProps extends events.CfnRuleProps {
706
707
  input?: string
707
708
  }
708
709
 
710
+ /**
711
+ * @category cdk-utils.sfn-manager
712
+ * @subcategory Properties
713
+ */
714
+ export interface SfnMapProps extends sfn.MapProps {}
715
+
716
+ /**
717
+ }
718
+ * @category cdk-utils.event-manager
719
+ * @subcategory Properties
720
+ */
721
+ export interface SqsToSfnPipeProps extends pipes.CfnPipeProps {
722
+ pipeFilterPattern?: any
723
+ sqsBatchSize?: number
724
+ sqsMaximumBatchingWindowInSeconds?: number
725
+ sfnInvocationType?: string
726
+ sfnInputTemplate?: string
727
+ }
728
+
709
729
  /**
710
730
  * @category cdk-utils.event-manager
711
731
  * @subcategory Properties