@gradientedge/cdk-utils 8.153.0 → 8.155.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 (35) hide show
  1. package/dist/src/lib/aws/construct/event-handler/handler.d.ts +29 -0
  2. package/dist/src/lib/aws/construct/event-handler/handler.js +25 -0
  3. package/dist/src/lib/aws/construct/event-handler/index.d.ts +3 -0
  4. package/dist/src/lib/aws/construct/event-handler/index.js +19 -0
  5. package/dist/src/lib/aws/construct/event-handler/main.d.ts +91 -0
  6. package/dist/src/lib/aws/construct/event-handler/main.js +198 -0
  7. package/dist/src/lib/aws/construct/event-handler/types.d.ts +42 -0
  8. package/dist/src/lib/aws/construct/event-handler/types.js +2 -0
  9. package/dist/src/lib/aws/construct/index.d.ts +2 -0
  10. package/dist/src/lib/aws/construct/index.js +2 -0
  11. package/dist/src/lib/aws/construct/piped-event-handler/index.d.ts +2 -0
  12. package/dist/src/lib/aws/construct/piped-event-handler/index.js +18 -0
  13. package/dist/src/lib/aws/construct/piped-event-handler/main.d.ts +38 -0
  14. package/dist/src/lib/aws/construct/piped-event-handler/main.js +69 -0
  15. package/dist/src/lib/aws/construct/piped-event-handler/types.d.ts +9 -0
  16. package/dist/src/lib/aws/construct/piped-event-handler/types.js +2 -0
  17. package/dist/src/lib/aws/services/eventbridge/main.d.ts +10 -1
  18. package/dist/src/lib/aws/services/eventbridge/main.js +36 -0
  19. package/dist/src/lib/aws/services/eventbridge/types.d.ts +7 -1
  20. package/dist/src/lib/aws/services/identity-access-management/main.d.ts +8 -0
  21. package/dist/src/lib/aws/services/identity-access-management/main.js +19 -0
  22. package/dist/src/lib/aws/services/lambda/types.d.ts +4 -0
  23. package/package.json +18 -18
  24. package/src/lib/aws/construct/event-handler/handler.ts +30 -0
  25. package/src/lib/aws/construct/event-handler/index.ts +3 -0
  26. package/src/lib/aws/construct/event-handler/main.ts +243 -0
  27. package/src/lib/aws/construct/event-handler/types.ts +44 -0
  28. package/src/lib/aws/construct/index.ts +2 -0
  29. package/src/lib/aws/construct/piped-event-handler/index.ts +2 -0
  30. package/src/lib/aws/construct/piped-event-handler/main.ts +81 -0
  31. package/src/lib/aws/construct/piped-event-handler/types.ts +10 -0
  32. package/src/lib/aws/services/eventbridge/main.ts +59 -1
  33. package/src/lib/aws/services/eventbridge/types.ts +8 -1
  34. package/src/lib/aws/services/identity-access-management/main.ts +23 -0
  35. package/src/lib/aws/services/lambda/types.ts +5 -0
@@ -0,0 +1,29 @@
1
+ import { Archive, IEventBus, IRuleTarget, Rule } from 'aws-cdk-lib/aws-events';
2
+ import { CloudWatchLogGroup, EcsTask, LambdaFunction, SfnStateMachine, SqsQueue } from 'aws-cdk-lib/aws-events-targets';
3
+ import { PolicyDocument, Role } from 'aws-cdk-lib/aws-iam';
4
+ import { IFunction } from 'aws-cdk-lib/aws-lambda';
5
+ import { LogGroup } from 'aws-cdk-lib/aws-logs';
6
+ import { Queue } from 'aws-cdk-lib/aws-sqs';
7
+ import { Chain, Map, StateMachine } from 'aws-cdk-lib/aws-stepfunctions';
8
+ import { EventHandlerType } from './types';
9
+ export declare class Handler implements EventHandlerType {
10
+ archive: Archive;
11
+ ecsTargets: EcsTask[];
12
+ eventBus: IEventBus;
13
+ eventWorkflowDefinition: Chain;
14
+ lambdaFunctions: IFunction[];
15
+ lambdaTargets: LambdaFunction[];
16
+ logTargets: CloudWatchLogGroup[];
17
+ queue: Queue;
18
+ rule: Rule;
19
+ rulePattern: any;
20
+ sqsTargets: SqsQueue[];
21
+ stepFunctionTargets: SfnStateMachine[];
22
+ targets: IRuleTarget[];
23
+ workflow: StateMachine;
24
+ workflowDefinition: Chain;
25
+ workflowLogGroup: LogGroup;
26
+ workflowMapState: Map;
27
+ workflowPolicy: PolicyDocument;
28
+ workflowRole: Role;
29
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Handler = void 0;
4
+ class Handler {
5
+ archive;
6
+ ecsTargets = [];
7
+ eventBus;
8
+ eventWorkflowDefinition;
9
+ lambdaFunctions = [];
10
+ lambdaTargets = [];
11
+ logTargets = [];
12
+ queue;
13
+ rule;
14
+ rulePattern;
15
+ sqsTargets = [];
16
+ stepFunctionTargets = [];
17
+ targets = [];
18
+ workflow;
19
+ workflowDefinition;
20
+ workflowLogGroup;
21
+ workflowMapState;
22
+ workflowPolicy;
23
+ workflowRole;
24
+ }
25
+ exports.Handler = Handler;
@@ -0,0 +1,3 @@
1
+ export * from './handler';
2
+ export * from './main';
3
+ export * from './types';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./handler"), exports);
18
+ __exportStar(require("./main"), exports);
19
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,91 @@
1
+ import { ISecurityGroup, IVpc } from 'aws-cdk-lib/aws-ec2';
2
+ import { Construct } from 'constructs';
3
+ import { CommonConstruct } from '../../common';
4
+ import { Handler } from './handler';
5
+ import { EventHandlerProps } from './types';
6
+ /**
7
+ * @classdesc Provides a construct to create and deploy an EventBridge Event Handler
8
+ * @example
9
+ * import { EventHandler, EventHandlerProps } '@gradientedge/cdk-utils'
10
+ * import { Construct } from 'constructs'
11
+ *
12
+ * class CustomConstruct extends EventHandler {
13
+ * constructor(parent: Construct, id: string, props: EventHandlerProps) {
14
+ * super(parent, id, props)
15
+ * this.props = props
16
+ * this.id = id
17
+ * this.initResources()
18
+ * }
19
+ * }
20
+ */
21
+ export declare class EventHandler extends CommonConstruct {
22
+ props: EventHandlerProps;
23
+ id: string;
24
+ handler: Handler;
25
+ provisionTarget: boolean;
26
+ securityGroup: ISecurityGroup;
27
+ useMapState: boolean;
28
+ vpc: IVpc;
29
+ constructor(parent: Construct, id: string, props: EventHandlerProps);
30
+ protected initResources(): void;
31
+ /**
32
+ * @summary Method to resolve common vpc or create a new one.
33
+ */
34
+ protected resolveVpc(): void;
35
+ /**
36
+ * @summary Method to resolve the exported security group.
37
+ */
38
+ protected resolveSecurityGroup(): void;
39
+ /**
40
+ * @summary Method to create sqs event source if queue targets are defined.
41
+ */
42
+ protected createSQSEventSource(): void;
43
+ /**
44
+ * @summary Method to create the event rule pattern.
45
+ */
46
+ protected createEventRulePattern(): void;
47
+ /**
48
+ * @summary Method to create the event rule targets.
49
+ */
50
+ protected createEventRuleTargets(): void;
51
+ /**
52
+ * @summary Method to resolve the event bus name or use the default bus.
53
+ */
54
+ protected resolveEventBus(): void;
55
+ /**
56
+ * @summary Method to create an event archive if the event rule is not a scheduled one.
57
+ */
58
+ protected createEventArchive(): void;
59
+ /**
60
+ * @summary Method to create the event rule.
61
+ */
62
+ protected createEventRule(): void;
63
+ /**
64
+ * @summary Method to create the workflow steps.
65
+ */
66
+ protected createWorkflowSteps(): void;
67
+ /**
68
+ * @summary Method to create the workflow definition.
69
+ */
70
+ protected createWorkflowDefinition(): void;
71
+ /**
72
+ * @summary Method to create the workflow policy.
73
+ */
74
+ protected createWorkflowPolicy(): void;
75
+ /**
76
+ * @summary Method to create the workflow role.
77
+ */
78
+ protected createWorkflowRole(): void;
79
+ /**
80
+ * @summary Method to create the workflow log group.
81
+ */
82
+ protected createWorkflowLogGroup(): void;
83
+ /**
84
+ * @summary Method to create the workflow state machine.
85
+ */
86
+ protected createWorkflowStateMachine(): void;
87
+ /**
88
+ * @summary Method to create the workflow.
89
+ */
90
+ protected createWorkflow(): void;
91
+ }
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EventHandler = void 0;
7
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
8
+ const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
9
+ const aws_events_1 = require("aws-cdk-lib/aws-events");
10
+ const aws_events_targets_1 = require("aws-cdk-lib/aws-events-targets");
11
+ const aws_sqs_1 = require("aws-cdk-lib/aws-sqs");
12
+ const aws_stepfunctions_1 = require("aws-cdk-lib/aws-stepfunctions");
13
+ const lodash_1 = __importDefault(require("lodash"));
14
+ const common_1 = require("../../common");
15
+ const handler_1 = require("./handler");
16
+ /**
17
+ * @classdesc Provides a construct to create and deploy an EventBridge Event Handler
18
+ * @example
19
+ * import { EventHandler, EventHandlerProps } '@gradientedge/cdk-utils'
20
+ * import { Construct } from 'constructs'
21
+ *
22
+ * class CustomConstruct extends EventHandler {
23
+ * constructor(parent: Construct, id: string, props: EventHandlerProps) {
24
+ * super(parent, id, props)
25
+ * this.props = props
26
+ * this.id = id
27
+ * this.initResources()
28
+ * }
29
+ * }
30
+ */
31
+ class EventHandler extends common_1.CommonConstruct {
32
+ props;
33
+ id;
34
+ handler;
35
+ provisionTarget = true;
36
+ securityGroup;
37
+ useMapState;
38
+ vpc;
39
+ constructor(parent, id, props) {
40
+ super(parent, id, props);
41
+ this.props = props;
42
+ this.id = id;
43
+ this.handler = new handler_1.Handler();
44
+ }
45
+ initResources() {
46
+ this.createSQSEventSource();
47
+ this.createWorkflow();
48
+ this.createEventRulePattern();
49
+ this.createEventRuleTargets();
50
+ this.resolveEventBus();
51
+ this.createEventArchive();
52
+ this.createEventRule();
53
+ }
54
+ /**
55
+ * @summary Method to resolve common vpc or create a new one.
56
+ */
57
+ resolveVpc() {
58
+ if (this.props.useExistingVpc) {
59
+ this.vpc = this.vpcManager.retrieveCommonVpc(`${this.id}-vpc`, this, this.props.vpcName);
60
+ }
61
+ else {
62
+ this.vpc = this.vpcManager.createCommonVpc(this, this.props.vpc, this.props.vpc.vpcName);
63
+ }
64
+ }
65
+ /**
66
+ * @summary Method to resolve the exported security group.
67
+ */
68
+ resolveSecurityGroup() {
69
+ if (this.props.securityGroupExportName) {
70
+ this.securityGroup = aws_ec2_1.SecurityGroup.fromSecurityGroupId(this, `${this.id}-security-group`, aws_cdk_lib_1.Fn.importValue(this.props.securityGroupExportName));
71
+ }
72
+ }
73
+ /**
74
+ * @summary Method to create sqs event source if queue targets are defined.
75
+ */
76
+ createSQSEventSource() {
77
+ if (!this.props.eventSqs)
78
+ return;
79
+ this.handler.queue = this.sqsManager.createQueue(`${this.id}-sqs-queue`, this, this.props.eventSqs);
80
+ const sqsPolicyDocument = this.iamManager.createPolicyForSqsEvent(`${this.id}-sqs-policy-document`, this, this.handler.queue, this.handler.rule);
81
+ new aws_sqs_1.CfnQueuePolicy(this, `${this.id}-sqs-queue-policy`, {
82
+ policyDocument: sqsPolicyDocument.toJSON(),
83
+ queues: [this.handler.queue.queueUrl],
84
+ });
85
+ this.handler.sqsTargets = [new aws_events_targets_1.SqsQueue(this.handler.queue)];
86
+ }
87
+ /**
88
+ * @summary Method to create the event rule pattern.
89
+ */
90
+ createEventRulePattern() {
91
+ this.handler.rulePattern = this.props.eventRule.eventPattern;
92
+ }
93
+ /**
94
+ * @summary Method to create the event rule targets.
95
+ */
96
+ createEventRuleTargets() {
97
+ this.handler.targets = [
98
+ ...this.handler.stepFunctionTargets,
99
+ ...this.handler.lambdaTargets,
100
+ ...this.handler.sqsTargets,
101
+ ...this.handler.ecsTargets,
102
+ ...this.handler.logTargets,
103
+ ];
104
+ }
105
+ /**
106
+ * @summary Method to resolve the event bus name or use the default bus.
107
+ */
108
+ resolveEventBus() {
109
+ this.handler.eventBus = aws_events_1.EventBus.fromEventBusName(this, `${this.id}-bus`, this.props.eventBusName ?? 'default');
110
+ }
111
+ /**
112
+ * @summary Method to create an event archive if the event rule is not a scheduled one.
113
+ */
114
+ createEventArchive() {
115
+ /* do not enable for scheduled events */
116
+ if (this.props.eventRule.schedule || this.props.eventRuleSchedule || !this.props.eventRuleArchiveEnabled)
117
+ return;
118
+ this.handler.archive = new aws_events_1.Archive(this, `${this.id}-archive`, {
119
+ archiveName: `${this.props.eventRule.ruleName}-${this.props.stage}`.replace(`${this.node.tryGetContext('stackName')}-`, ''),
120
+ description: `Archive of events for ${this.props.eventRule.ruleName}`,
121
+ eventPattern: this.handler.rulePattern,
122
+ retention: aws_cdk_lib_1.Duration.days(this.props.eventRetentionInDays ?? 7),
123
+ sourceEventBus: this.handler.eventBus,
124
+ });
125
+ }
126
+ /**
127
+ * @summary Method to create the event rule.
128
+ */
129
+ createEventRule() {
130
+ let schedule;
131
+ if (this.props.eventRuleSchedule) {
132
+ schedule = aws_events_1.Schedule.expression(this.props.eventRuleSchedule);
133
+ }
134
+ this.handler.rule = this.eventManager.createRule(`${this.id}-rule`, this, {
135
+ ...this.props.eventRule,
136
+ eventPattern: this.handler.rulePattern,
137
+ schedule: schedule,
138
+ }, this.props.eventBusName ? this.handler.eventBus : undefined, this.handler.targets);
139
+ }
140
+ /**
141
+ * @summary Method to create the workflow steps.
142
+ */
143
+ createWorkflowSteps() { }
144
+ /**
145
+ * @summary Method to create the workflow definition.
146
+ */
147
+ createWorkflowDefinition() {
148
+ if (this.useMapState) {
149
+ this.handler.workflowMapState = new aws_stepfunctions_1.Map(this, `Map Iterator`, {
150
+ ...this.props.workflowMapState,
151
+ itemsPath: aws_stepfunctions_1.JsonPath.entirePayload,
152
+ });
153
+ }
154
+ this.handler.workflowDefinition = this.handler.eventWorkflowDefinition;
155
+ if (this.useMapState) {
156
+ this.handler.workflowMapState.itemProcessor(this.handler.workflowDefinition);
157
+ }
158
+ }
159
+ /**
160
+ * @summary Method to create the workflow policy.
161
+ */
162
+ createWorkflowPolicy() { }
163
+ /**
164
+ * @summary Method to create the workflow role.
165
+ */
166
+ createWorkflowRole() {
167
+ this.handler.workflowRole = this.iamManager.createRoleForStepFunction(`${this.id}-workflow-role`, this, this.handler.workflowPolicy);
168
+ }
169
+ /**
170
+ * @summary Method to create the workflow log group.
171
+ */
172
+ createWorkflowLogGroup() {
173
+ this.handler.workflowLogGroup = this.logManager.createLogGroup(`${this.id}-workflow-log`, this, this.props.workflowLog);
174
+ }
175
+ /**
176
+ * @summary Method to create the workflow state machine.
177
+ */
178
+ createWorkflowStateMachine() {
179
+ this.handler.workflow = this.sfnManager.createStateMachine(`${this.id}-workflow`, this, this.props.workflow, this.useMapState ? this.handler.workflowMapState : this.handler.workflowDefinition, this.handler.workflowLogGroup, this.handler.workflowRole);
180
+ }
181
+ /**
182
+ * @summary Method to create the workflow.
183
+ */
184
+ createWorkflow() {
185
+ if (lodash_1.default.isEmpty(this.props.workflow))
186
+ return;
187
+ this.createWorkflowSteps();
188
+ this.createWorkflowDefinition();
189
+ this.createWorkflowPolicy();
190
+ this.createWorkflowRole();
191
+ this.createWorkflowLogGroup();
192
+ this.createWorkflowStateMachine();
193
+ if (this.provisionTarget) {
194
+ this.handler.stepFunctionTargets = [new aws_events_targets_1.SfnStateMachine(this.handler.workflow)];
195
+ }
196
+ }
197
+ }
198
+ exports.EventHandler = EventHandler;
@@ -0,0 +1,42 @@
1
+ import { Archive, IEventBus, IRuleTarget, Rule } from 'aws-cdk-lib/aws-events';
2
+ import { CloudWatchLogGroup, EcsTask, LambdaFunction, SfnStateMachine, SqsQueue } from 'aws-cdk-lib/aws-events-targets';
3
+ import { PolicyDocument, Role } from 'aws-cdk-lib/aws-iam';
4
+ import { LogGroup } from 'aws-cdk-lib/aws-logs';
5
+ import { Queue } from 'aws-cdk-lib/aws-sqs';
6
+ import { Chain, Map, StateMachine } from 'aws-cdk-lib/aws-stepfunctions';
7
+ import { CommonStackProps } from '../../common';
8
+ import { EventRuleProps, LogProps, QueueProps, SfnMapProps, SfnStateMachineProps, VpcProps } from '../../services';
9
+ export interface EventHandlerProps extends CommonStackProps {
10
+ eventBusName: string;
11
+ eventRetentionInDays: number;
12
+ eventRule: EventRuleProps;
13
+ eventRuleArchiveEnabled: boolean;
14
+ eventRuleSchedule: string;
15
+ eventSqs: QueueProps;
16
+ securityGroupExportName: string;
17
+ useExistingVpc: boolean;
18
+ vpc: VpcProps;
19
+ vpcName: string;
20
+ workflow: SfnStateMachineProps;
21
+ workflowLog: LogProps;
22
+ workflowMapState: SfnMapProps;
23
+ }
24
+ export interface EventHandlerType {
25
+ archive: Archive;
26
+ ecsTargets: EcsTask[];
27
+ eventBus: IEventBus;
28
+ lambdaTargets: LambdaFunction[];
29
+ logTargets: CloudWatchLogGroup[];
30
+ queue: Queue;
31
+ rule: Rule;
32
+ rulePattern: any;
33
+ sqsTargets: SqsQueue[];
34
+ stepFunctionTargets: SfnStateMachine[];
35
+ targets: IRuleTarget[];
36
+ workflow: StateMachine;
37
+ workflowDefinition: Chain;
38
+ workflowLogGroup: LogGroup;
39
+ workflowMapState: Map;
40
+ workflowPolicy: PolicyDocument;
41
+ workflowRole: Role;
42
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,9 +3,11 @@ export * from './api-to-eventbridge-target';
3
3
  export * from './api-to-eventbridge-target-with-sns';
4
4
  export * from './api-to-lambda-target';
5
5
  export * from './application-configuration';
6
+ export * from './event-handler';
6
7
  export * from './graphql-api-lambda';
7
8
  export * from './graphql-api-lambda-with-cache';
8
9
  export * from './lambda-with-iam-access';
10
+ export * from './piped-event-handler';
9
11
  export * from './rest-api-lambda';
10
12
  export * from './rest-api-lambda-with-cache';
11
13
  export * from './site-with-ecs-backend';
@@ -19,9 +19,11 @@ __exportStar(require("./api-to-eventbridge-target"), exports);
19
19
  __exportStar(require("./api-to-eventbridge-target-with-sns"), exports);
20
20
  __exportStar(require("./api-to-lambda-target"), exports);
21
21
  __exportStar(require("./application-configuration"), exports);
22
+ __exportStar(require("./event-handler"), exports);
22
23
  __exportStar(require("./graphql-api-lambda"), exports);
23
24
  __exportStar(require("./graphql-api-lambda-with-cache"), exports);
24
25
  __exportStar(require("./lambda-with-iam-access"), exports);
26
+ __exportStar(require("./piped-event-handler"), exports);
25
27
  __exportStar(require("./rest-api-lambda"), exports);
26
28
  __exportStar(require("./rest-api-lambda-with-cache"), exports);
27
29
  __exportStar(require("./site-with-ecs-backend"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './main';
2
+ export * from './types';
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./main"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,38 @@
1
+ import { IQueue } from 'aws-cdk-lib/aws-sqs';
2
+ import { Construct } from 'constructs';
3
+ import { EventHandler } from '../event-handler';
4
+ import { PipedEventHandlerProps } from './types';
5
+ /**
6
+ * @classdesc Provides a construct to create and deploy an EventBridge Piped Event Handler
7
+ * @example
8
+ * import { PipedEventHandler, PipedEventHandlerProps } '@gradientedge/cdk-utils'
9
+ * import { Construct } from 'constructs'
10
+ *
11
+ * class CustomConstruct extends PipedEventHandler {
12
+ * constructor(parent: Construct, id: string, props: PipedEventHandlerProps) {
13
+ * super(parent, id, props)
14
+ * this.props = props
15
+ * this.id = id
16
+ * this.initResources()
17
+ * }
18
+ * }
19
+ */
20
+ export declare class PipedEventHandler extends EventHandler {
21
+ props: PipedEventHandlerProps;
22
+ pipedDlq: IQueue;
23
+ pipedQueue: IQueue;
24
+ protected constructor(parent: Construct, id: string, props: PipedEventHandlerProps);
25
+ protected initResources(): void;
26
+ /**
27
+ * @summary Method to create the piped queue and dlq.
28
+ */
29
+ protected createPipedQueue(): void;
30
+ /**
31
+ * @summary Method to create the SQS to SFN pipe.
32
+ */
33
+ protected createSqsToSfnPipe(): void;
34
+ /**
35
+ * @summary Method to create the SQS to Lambda pipe.
36
+ */
37
+ protected createSqsToLambdaPipe(): void;
38
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PipedEventHandler = void 0;
7
+ const aws_events_targets_1 = require("aws-cdk-lib/aws-events-targets");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const event_handler_1 = require("../event-handler");
10
+ /**
11
+ * @classdesc Provides a construct to create and deploy an EventBridge Piped Event Handler
12
+ * @example
13
+ * import { PipedEventHandler, PipedEventHandlerProps } '@gradientedge/cdk-utils'
14
+ * import { Construct } from 'constructs'
15
+ *
16
+ * class CustomConstruct extends PipedEventHandler {
17
+ * constructor(parent: Construct, id: string, props: PipedEventHandlerProps) {
18
+ * super(parent, id, props)
19
+ * this.props = props
20
+ * this.id = id
21
+ * this.initResources()
22
+ * }
23
+ * }
24
+ */
25
+ class PipedEventHandler extends event_handler_1.EventHandler {
26
+ props;
27
+ pipedDlq;
28
+ pipedQueue;
29
+ constructor(parent, id, props) {
30
+ super(parent, id, props);
31
+ this.props = props;
32
+ this.id = id;
33
+ this.useMapState = true;
34
+ this.provisionTarget = false;
35
+ }
36
+ initResources() {
37
+ this.createPipedQueue();
38
+ this.handler.sqsTargets = [new aws_events_targets_1.SqsQueue(this.pipedQueue)];
39
+ super.initResources();
40
+ this.createSqsToSfnPipe();
41
+ this.createSqsToLambdaPipe();
42
+ }
43
+ /**
44
+ * @summary Method to create the piped queue and dlq.
45
+ */
46
+ createPipedQueue() {
47
+ this.pipedDlq = this.sqsManager.createQueue(`${this.id}-pipe-queue-dlq`, this, this.props.pipedDlq);
48
+ this.pipedQueue = this.sqsManager.createQueue(`${this.id}-pipe-queue`, this, this.props.pipedQueue, this.pipedDlq);
49
+ }
50
+ /**
51
+ * @summary Method to create the SQS to SFN pipe.
52
+ */
53
+ createSqsToSfnPipe() {
54
+ if (lodash_1.default.isEmpty(this.props.sqsToSfnPipe) || !this.handler.workflow)
55
+ return;
56
+ this.eventManager.createSqsToSfnCfnPipe(`${this.id}-pipe-sfn`, this, this.props.sqsToSfnPipe, this.pipedQueue, this.handler.workflow);
57
+ }
58
+ /**
59
+ * @summary Method to create the SQS to Lambda pipe.
60
+ */
61
+ createSqsToLambdaPipe() {
62
+ if (lodash_1.default.isEmpty(this.props.sqsToLambdaPipe) || lodash_1.default.isEmpty(this.handler.lambdaFunctions))
63
+ return;
64
+ lodash_1.default.forEach(this.handler.lambdaFunctions, (lambdaFunction, index) => {
65
+ this.eventManager.createSqsToLambdaCfnPipe(`${this.id}-pipe-lambda-${index}`, this, this.props.sqsToLambdaPipe, this.pipedQueue, lambdaFunction);
66
+ });
67
+ }
68
+ }
69
+ exports.PipedEventHandler = PipedEventHandler;
@@ -0,0 +1,9 @@
1
+ import { QueueProps } from 'aws-cdk-lib/aws-sqs';
2
+ import { SqsToLambdaPipeProps, SqsToSfnPipeProps } from '../../services';
3
+ import { EventHandlerProps } from '../event-handler';
4
+ export interface PipedEventHandlerProps extends EventHandlerProps {
5
+ pipedDlq: QueueProps;
6
+ pipedQueue: QueueProps;
7
+ sqsToLambdaPipe: SqsToLambdaPipeProps;
8
+ sqsToSfnPipe: SqsToSfnPipeProps;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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, DynamoDbToLambdaPipeProps } from './types';
9
+ import { DynamoDbToLambdaPipeProps, EventBusProps, EventRuleProps, RuleProps, SqsToLambdaPipeProps, SqsToSfnPipeProps } 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,6 +72,15 @@ 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 sqs queue 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 sourceQueue the source sqs queue
81
+ * @param targetLambdaFunction the target lambda function
82
+ */
83
+ createSqsToLambdaCfnPipe(id: string, scope: CommonConstruct, props: SqsToLambdaPipeProps, sourceQueue: IQueue, targetLambdaFunction: IFunction): CfnPipe;
75
84
  /**
76
85
  * @summary Method to create an eventbridge pipe with DynamoDb stream as source and lambda function as target
77
86
  * @param id scoped id of the resource
@@ -194,6 +194,42 @@ 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 sqs queue 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 sourceQueue the source sqs queue
203
+ * @param targetLambdaFunction the target lambda function
204
+ */
205
+ createSqsToLambdaCfnPipe(id, scope, props, sourceQueue, targetLambdaFunction) {
206
+ const pipeRole = scope.iamManager.createRoleForSqsToLambdaPipe(`${id}-role`, scope, sourceQueue.queueArn, 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: sourceQueue.queueArn,
212
+ sourceParameters: {
213
+ filterCriteria: props.pipeFilterPattern
214
+ ? {
215
+ filters: [
216
+ {
217
+ pattern: JSON.stringify(props.pipeFilterPattern),
218
+ },
219
+ ],
220
+ }
221
+ : undefined,
222
+ sqsQueueParameters: {
223
+ batchSize: props.sqsBatchSize,
224
+ maximumBatchingWindowInSeconds: props.sqsMaximumBatchingWindowInSeconds,
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
  * @summary Method to create an eventbridge pipe with DynamoDb stream as source and lambda function as target
199
235
  * @param id scoped id of the resource