@gradientedge/cdk-utils 8.129.0 → 8.130.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.
- package/dist/src/lib/aws/services/eventbridge/main.d.ts +10 -1
- package/dist/src/lib/aws/services/eventbridge/main.js +36 -0
- package/dist/src/lib/aws/services/eventbridge/types.d.ts +8 -0
- package/dist/src/lib/aws/services/identity-access-management/main.d.ts +13 -0
- package/dist/src/lib/aws/services/identity-access-management/main.js +30 -0
- package/package.json +1 -1
- package/src/lib/aws/services/eventbridge/main.ts +52 -1
- package/src/lib/aws/services/eventbridge/types.ts +9 -0
- package/src/lib/aws/services/identity-access-management/main.ts +40 -0
|
@@ -6,7 +6,7 @@ import { CfnPipe } from 'aws-cdk-lib/aws-pipes';
|
|
|
6
6
|
import { IQueue } from 'aws-cdk-lib/aws-sqs';
|
|
7
7
|
import { IStateMachine } from 'aws-cdk-lib/aws-stepfunctions';
|
|
8
8
|
import { CommonConstruct } from '../../common';
|
|
9
|
-
import { EventBusProps, EventRuleProps, RuleProps, SqsToSfnPipeProps } from './types';
|
|
9
|
+
import { EventBusProps, EventRuleProps, RuleProps, SqsToSfnPipeProps, DynamoDbToLambdaPipeProps } from './types';
|
|
10
10
|
/**
|
|
11
11
|
* @classdesc Provides operations on AWS EventBridge.
|
|
12
12
|
* - A new instance of this class is injected into {@link CommonConstruct} constructor.
|
|
@@ -72,4 +72,13 @@ export declare class EventManager {
|
|
|
72
72
|
* @param targetStepFunction the target step function
|
|
73
73
|
*/
|
|
74
74
|
createSqsToSfnCfnPipe(id: string, scope: CommonConstruct, props: SqsToSfnPipeProps, sourceQueue: IQueue, targetStepFunction: IStateMachine): CfnPipe;
|
|
75
|
+
/**
|
|
76
|
+
* @summary Method to create an eventbridge pipe with DynamoDb stream as source and lambda function as target
|
|
77
|
+
* @param id scoped id of the resource
|
|
78
|
+
* @param scope scope in which this resource is defined
|
|
79
|
+
* @param props the props for the pipe
|
|
80
|
+
* @param dynamoDbStream the source dynamoDb stream
|
|
81
|
+
* @param targetLambdaFunction the target lambda function
|
|
82
|
+
*/
|
|
83
|
+
createDynamoDbToLambdaCfnPipe(id: string, scope: CommonConstruct, props: DynamoDbToLambdaPipeProps, sourceDynamoDbStreamArn: string, targetLambdaFunction: IFunction): CfnPipe;
|
|
75
84
|
}
|
|
@@ -194,5 +194,41 @@ class EventManager {
|
|
|
194
194
|
(0, utils_1.createCfnOutput)(`${id}-pipeName`, scope, pipe.name);
|
|
195
195
|
return pipe;
|
|
196
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* @summary Method to create an eventbridge pipe with DynamoDb stream as source and lambda function as target
|
|
199
|
+
* @param id scoped id of the resource
|
|
200
|
+
* @param scope scope in which this resource is defined
|
|
201
|
+
* @param props the props for the pipe
|
|
202
|
+
* @param dynamoDbStream the source dynamoDb stream
|
|
203
|
+
* @param targetLambdaFunction the target lambda function
|
|
204
|
+
*/
|
|
205
|
+
createDynamoDbToLambdaCfnPipe(id, scope, props, sourceDynamoDbStreamArn, targetLambdaFunction) {
|
|
206
|
+
const pipeRole = scope.iamManager.createRoleForDynamoDbToLambdaPipe(`${id}-role`, scope, sourceDynamoDbStreamArn, targetLambdaFunction.functionArn);
|
|
207
|
+
const pipe = new aws_pipes_1.CfnPipe(scope, `${id}`, {
|
|
208
|
+
...props,
|
|
209
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
210
|
+
roleArn: pipeRole.roleArn,
|
|
211
|
+
source: sourceDynamoDbStreamArn,
|
|
212
|
+
sourceParameters: {
|
|
213
|
+
filterCriteria: props.pipeFilterPattern
|
|
214
|
+
? {
|
|
215
|
+
filters: [
|
|
216
|
+
{
|
|
217
|
+
pattern: JSON.stringify(props.pipeFilterPattern),
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
}
|
|
221
|
+
: undefined,
|
|
222
|
+
dynamoDbStreamParameters: {
|
|
223
|
+
startingPosition: props.dynamoDbStartingPosition,
|
|
224
|
+
batchSize: props.dynamoDbBatchSize,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
target: targetLambdaFunction.functionArn,
|
|
228
|
+
});
|
|
229
|
+
(0, utils_1.createCfnOutput)(`${id}-pipeArn`, scope, pipe.attrArn);
|
|
230
|
+
(0, utils_1.createCfnOutput)(`${id}-pipeName`, scope, pipe.name);
|
|
231
|
+
return pipe;
|
|
232
|
+
}
|
|
197
233
|
}
|
|
198
234
|
exports.EventManager = EventManager;
|
|
@@ -25,3 +25,11 @@ export interface RuleProps extends CfnRuleProps {
|
|
|
25
25
|
*/
|
|
26
26
|
export interface EventBusProps extends EBProps {
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
}
|
|
30
|
+
*/
|
|
31
|
+
export interface DynamoDbToLambdaPipeProps extends CfnPipeProps {
|
|
32
|
+
pipeFilterPattern?: any;
|
|
33
|
+
dynamoDbBatchSize?: number;
|
|
34
|
+
dynamoDbStartingPosition: string;
|
|
35
|
+
}
|
|
@@ -176,6 +176,11 @@ export declare class IamManager {
|
|
|
176
176
|
* @param resourceArns list of ARNs to allow access to
|
|
177
177
|
*/
|
|
178
178
|
statementForWriteTableItems(resourceArns?: string[]): PolicyStatement;
|
|
179
|
+
/**
|
|
180
|
+
* @summary Method to create iam statement to poll from dynamodb table
|
|
181
|
+
* @param resourceArns list of ARNs to allow access to
|
|
182
|
+
*/
|
|
183
|
+
statementFordynamoDbStream(resourceArns?: string[]): PolicyStatement;
|
|
179
184
|
/**
|
|
180
185
|
* @summary Method to create iam statement for cloud trail
|
|
181
186
|
* @param id scoped id of the resource
|
|
@@ -239,4 +244,12 @@ export declare class IamManager {
|
|
|
239
244
|
* @param servicePrincipals
|
|
240
245
|
*/
|
|
241
246
|
createPolicyForSqsEvent(id: string, scope: CommonConstruct, sqsQueue: Queue, eventBridgeRule: IRule, servicePrincipals?: ServicePrincipal[]): PolicyDocument;
|
|
247
|
+
/**
|
|
248
|
+
* @summary Method to create iam statement for dynamoDb to lambda function pipe
|
|
249
|
+
* @param id scoped id of the resource
|
|
250
|
+
* @param scope scope in which this resource is defined
|
|
251
|
+
* @param dynamoDbStreamArn the arn of the dynamoDb Stream queue
|
|
252
|
+
* @param lambdaFunctionArn the arn of the lambda function
|
|
253
|
+
*/
|
|
254
|
+
createRoleForDynamoDbToLambdaPipe(id: string, scope: CommonConstruct, dynamoDbStreamArn: string, lambdaFunctionArn: string): Role;
|
|
242
255
|
}
|
|
@@ -388,6 +388,17 @@ class IamManager {
|
|
|
388
388
|
resources: resourceArns ?? ['*'],
|
|
389
389
|
});
|
|
390
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* @summary Method to create iam statement to poll from dynamodb table
|
|
393
|
+
* @param resourceArns list of ARNs to allow access to
|
|
394
|
+
*/
|
|
395
|
+
statementFordynamoDbStream(resourceArns) {
|
|
396
|
+
return new aws_iam_1.PolicyStatement({
|
|
397
|
+
actions: ['dynamodb:DescribeStream', 'dynamodb:GetRecords', 'dynamodb:GetShardIterator', 'dynamodb:ListStreams'],
|
|
398
|
+
effect: aws_iam_1.Effect.ALLOW,
|
|
399
|
+
resources: resourceArns ?? ['*'],
|
|
400
|
+
});
|
|
401
|
+
}
|
|
391
402
|
/**
|
|
392
403
|
* @summary Method to create iam statement for cloud trail
|
|
393
404
|
* @param id scoped id of the resource
|
|
@@ -559,5 +570,24 @@ class IamManager {
|
|
|
559
570
|
],
|
|
560
571
|
});
|
|
561
572
|
}
|
|
573
|
+
/**
|
|
574
|
+
* @summary Method to create iam statement for dynamoDb to lambda function pipe
|
|
575
|
+
* @param id scoped id of the resource
|
|
576
|
+
* @param scope scope in which this resource is defined
|
|
577
|
+
* @param dynamoDbStreamArn the arn of the dynamoDb Stream queue
|
|
578
|
+
* @param lambdaFunctionArn the arn of the lambda function
|
|
579
|
+
*/
|
|
580
|
+
createRoleForDynamoDbToLambdaPipe(id, scope, dynamoDbStreamArn, lambdaFunctionArn) {
|
|
581
|
+
const role = new aws_iam_1.Role(scope, `${id}`, {
|
|
582
|
+
assumedBy: new aws_iam_1.ServicePrincipal('pipes.amazonaws.com'),
|
|
583
|
+
description: `Role for ${id} Pipe`,
|
|
584
|
+
roleName: `${id}-${scope.props.stage}`,
|
|
585
|
+
});
|
|
586
|
+
role.addToPolicy(this.statementFordynamoDbStream([dynamoDbStreamArn]));
|
|
587
|
+
role.addToPolicy(this.statementForInvokeLambda([lambdaFunctionArn]));
|
|
588
|
+
(0, utils_1.createCfnOutput)(`${id}Arn`, scope, role.roleArn);
|
|
589
|
+
(0, utils_1.createCfnOutput)(`${id}Name`, scope, role.roleName);
|
|
590
|
+
return role;
|
|
591
|
+
}
|
|
562
592
|
}
|
|
563
593
|
exports.IamManager = IamManager;
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import { IStateMachine } from 'aws-cdk-lib/aws-stepfunctions'
|
|
|
9
9
|
import _ from 'lodash'
|
|
10
10
|
import { CommonConstruct } from '../../common'
|
|
11
11
|
import { createCfnOutput } from '../../utils'
|
|
12
|
-
import { EventBusProps, EventRuleProps, RuleProps, SqsToSfnPipeProps } from './types'
|
|
12
|
+
import { EventBusProps, EventRuleProps, RuleProps, SqsToSfnPipeProps, DynamoDbToLambdaPipeProps } from './types'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @classdesc Provides operations on AWS EventBridge.
|
|
@@ -246,4 +246,55 @@ export class EventManager {
|
|
|
246
246
|
|
|
247
247
|
return pipe
|
|
248
248
|
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @summary Method to create an eventbridge pipe with DynamoDb stream as source and lambda function as target
|
|
252
|
+
* @param id scoped id of the resource
|
|
253
|
+
* @param scope scope in which this resource is defined
|
|
254
|
+
* @param props the props for the pipe
|
|
255
|
+
* @param dynamoDbStream the source dynamoDb stream
|
|
256
|
+
* @param targetLambdaFunction the target lambda function
|
|
257
|
+
*/
|
|
258
|
+
public createDynamoDbToLambdaCfnPipe(
|
|
259
|
+
id: string,
|
|
260
|
+
scope: CommonConstruct,
|
|
261
|
+
props: DynamoDbToLambdaPipeProps,
|
|
262
|
+
sourceDynamoDbStreamArn: string,
|
|
263
|
+
targetLambdaFunction: IFunction
|
|
264
|
+
) {
|
|
265
|
+
const pipeRole = scope.iamManager.createRoleForDynamoDbToLambdaPipe(
|
|
266
|
+
`${id}-role`,
|
|
267
|
+
scope,
|
|
268
|
+
sourceDynamoDbStreamArn,
|
|
269
|
+
targetLambdaFunction.functionArn
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
const pipe = new CfnPipe(scope, `${id}`, {
|
|
273
|
+
...props,
|
|
274
|
+
name: `${props.name}-${scope.props.stage}`,
|
|
275
|
+
roleArn: pipeRole.roleArn,
|
|
276
|
+
source: sourceDynamoDbStreamArn,
|
|
277
|
+
sourceParameters: {
|
|
278
|
+
filterCriteria: props.pipeFilterPattern
|
|
279
|
+
? {
|
|
280
|
+
filters: [
|
|
281
|
+
{
|
|
282
|
+
pattern: JSON.stringify(props.pipeFilterPattern),
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
}
|
|
286
|
+
: undefined,
|
|
287
|
+
dynamoDbStreamParameters: {
|
|
288
|
+
startingPosition: props.dynamoDbStartingPosition,
|
|
289
|
+
batchSize: props.dynamoDbBatchSize,
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
target: targetLambdaFunction.functionArn,
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
createCfnOutput(`${id}-pipeArn`, scope, pipe.attrArn)
|
|
296
|
+
createCfnOutput(`${id}-pipeName`, scope, pipe.name)
|
|
297
|
+
|
|
298
|
+
return pipe
|
|
299
|
+
}
|
|
249
300
|
}
|
|
@@ -28,3 +28,12 @@ export interface RuleProps extends CfnRuleProps {
|
|
|
28
28
|
/**
|
|
29
29
|
*/
|
|
30
30
|
export interface EventBusProps extends EBProps {}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
}
|
|
34
|
+
*/
|
|
35
|
+
export interface DynamoDbToLambdaPipeProps extends CfnPipeProps {
|
|
36
|
+
pipeFilterPattern?: any
|
|
37
|
+
dynamoDbBatchSize?: number
|
|
38
|
+
dynamoDbStartingPosition: string
|
|
39
|
+
}
|
|
@@ -432,6 +432,18 @@ export class IamManager {
|
|
|
432
432
|
})
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
+
/**
|
|
436
|
+
* @summary Method to create iam statement to poll from dynamodb table
|
|
437
|
+
* @param resourceArns list of ARNs to allow access to
|
|
438
|
+
*/
|
|
439
|
+
public statementFordynamoDbStream(resourceArns?: string[]) {
|
|
440
|
+
return new PolicyStatement({
|
|
441
|
+
actions: ['dynamodb:DescribeStream', 'dynamodb:GetRecords', 'dynamodb:GetShardIterator', 'dynamodb:ListStreams'],
|
|
442
|
+
effect: Effect.ALLOW,
|
|
443
|
+
resources: resourceArns ?? ['*'],
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
|
|
435
447
|
/**
|
|
436
448
|
* @summary Method to create iam statement for cloud trail
|
|
437
449
|
* @param id scoped id of the resource
|
|
@@ -659,4 +671,32 @@ export class IamManager {
|
|
|
659
671
|
],
|
|
660
672
|
})
|
|
661
673
|
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* @summary Method to create iam statement for dynamoDb to lambda function pipe
|
|
677
|
+
* @param id scoped id of the resource
|
|
678
|
+
* @param scope scope in which this resource is defined
|
|
679
|
+
* @param dynamoDbStreamArn the arn of the dynamoDb Stream queue
|
|
680
|
+
* @param lambdaFunctionArn the arn of the lambda function
|
|
681
|
+
*/
|
|
682
|
+
public createRoleForDynamoDbToLambdaPipe(
|
|
683
|
+
id: string,
|
|
684
|
+
scope: CommonConstruct,
|
|
685
|
+
dynamoDbStreamArn: string,
|
|
686
|
+
lambdaFunctionArn: string
|
|
687
|
+
) {
|
|
688
|
+
const role = new Role(scope, `${id}`, {
|
|
689
|
+
assumedBy: new ServicePrincipal('pipes.amazonaws.com'),
|
|
690
|
+
description: `Role for ${id} Pipe`,
|
|
691
|
+
roleName: `${id}-${scope.props.stage}`,
|
|
692
|
+
})
|
|
693
|
+
|
|
694
|
+
role.addToPolicy(this.statementFordynamoDbStream([dynamoDbStreamArn]))
|
|
695
|
+
role.addToPolicy(this.statementForInvokeLambda([lambdaFunctionArn]))
|
|
696
|
+
|
|
697
|
+
createCfnOutput(`${id}Arn`, scope, role.roleArn)
|
|
698
|
+
createCfnOutput(`${id}Name`, scope, role.roleName)
|
|
699
|
+
|
|
700
|
+
return role
|
|
701
|
+
}
|
|
662
702
|
}
|