@gradientedge/cdk-utils-aws 1.0.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/LICENSE +21 -0
- package/dist/src/common/construct.d.ts +85 -0
- package/dist/src/common/construct.js +125 -0
- package/dist/src/common/index.d.ts +4 -0
- package/dist/src/common/index.js +4 -0
- package/dist/src/common/resource-name-formatter.d.ts +13 -0
- package/dist/src/common/resource-name-formatter.js +30 -0
- package/dist/src/common/stack.d.ts +62 -0
- package/dist/src/common/stack.js +139 -0
- package/dist/src/common/types.d.ts +30 -0
- package/dist/src/common/types.js +1 -0
- package/dist/src/construct/api-to-any-target/index.d.ts +3 -0
- package/dist/src/construct/api-to-any-target/index.js +3 -0
- package/dist/src/construct/api-to-any-target/main.d.ts +47 -0
- package/dist/src/construct/api-to-any-target/main.js +154 -0
- package/dist/src/construct/api-to-any-target/target.d.ts +23 -0
- package/dist/src/construct/api-to-any-target/target.js +14 -0
- package/dist/src/construct/api-to-any-target/types.d.ts +60 -0
- package/dist/src/construct/api-to-any-target/types.js +1 -0
- package/dist/src/construct/api-to-eventbridge-target/api.d.ts +34 -0
- package/dist/src/construct/api-to-eventbridge-target/api.js +23 -0
- package/dist/src/construct/api-to-eventbridge-target/event.d.ts +15 -0
- package/dist/src/construct/api-to-eventbridge-target/event.js +12 -0
- package/dist/src/construct/api-to-eventbridge-target/index.d.ts +4 -0
- package/dist/src/construct/api-to-eventbridge-target/index.js +4 -0
- package/dist/src/construct/api-to-eventbridge-target/main.d.ts +121 -0
- package/dist/src/construct/api-to-eventbridge-target/main.js +442 -0
- package/dist/src/construct/api-to-eventbridge-target/types.d.ts +100 -0
- package/dist/src/construct/api-to-eventbridge-target/types.js +1 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.d.ts +16 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.js +12 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/index.d.ts +3 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/index.js +3 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/main.d.ts +159 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/main.js +547 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/types.d.ts +22 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/types.js +1 -0
- package/dist/src/construct/api-to-lambda-target/api.d.ts +35 -0
- package/dist/src/construct/api-to-lambda-target/api.js +24 -0
- package/dist/src/construct/api-to-lambda-target/index.d.ts +3 -0
- package/dist/src/construct/api-to-lambda-target/index.js +3 -0
- package/dist/src/construct/api-to-lambda-target/main.d.ts +70 -0
- package/dist/src/construct/api-to-lambda-target/main.js +218 -0
- package/dist/src/construct/api-to-lambda-target/types.d.ts +62 -0
- package/dist/src/construct/api-to-lambda-target/types.js +1 -0
- package/dist/src/construct/application-configuration/index.d.ts +2 -0
- package/dist/src/construct/application-configuration/index.js +2 -0
- package/dist/src/construct/application-configuration/main.d.ts +23 -0
- package/dist/src/construct/application-configuration/main.js +79 -0
- package/dist/src/construct/application-configuration/types.d.ts +6 -0
- package/dist/src/construct/application-configuration/types.js +1 -0
- package/dist/src/construct/event-handler/handler.d.ts +29 -0
- package/dist/src/construct/event-handler/handler.js +21 -0
- package/dist/src/construct/event-handler/index.d.ts +3 -0
- package/dist/src/construct/event-handler/index.js +3 -0
- package/dist/src/construct/event-handler/main.d.ts +91 -0
- package/dist/src/construct/event-handler/main.js +196 -0
- package/dist/src/construct/event-handler/types.d.ts +41 -0
- package/dist/src/construct/event-handler/types.js +1 -0
- package/dist/src/construct/index.d.ts +14 -0
- package/dist/src/construct/index.js +14 -0
- package/dist/src/construct/lambda-with-iam-access/index.d.ts +2 -0
- package/dist/src/construct/lambda-with-iam-access/index.js +2 -0
- package/dist/src/construct/lambda-with-iam-access/main.d.ts +78 -0
- package/dist/src/construct/lambda-with-iam-access/main.js +182 -0
- package/dist/src/construct/lambda-with-iam-access/types.d.ts +20 -0
- package/dist/src/construct/lambda-with-iam-access/types.js +1 -0
- package/dist/src/construct/piped-event-handler/index.d.ts +2 -0
- package/dist/src/construct/piped-event-handler/index.js +2 -0
- package/dist/src/construct/piped-event-handler/main.d.ts +38 -0
- package/dist/src/construct/piped-event-handler/main.js +62 -0
- package/dist/src/construct/piped-event-handler/types.d.ts +9 -0
- package/dist/src/construct/piped-event-handler/types.js +1 -0
- package/dist/src/construct/rest-api-lambda/index.d.ts +2 -0
- package/dist/src/construct/rest-api-lambda/index.js +2 -0
- package/dist/src/construct/rest-api-lambda/main.d.ts +96 -0
- package/dist/src/construct/rest-api-lambda/main.js +170 -0
- package/dist/src/construct/rest-api-lambda/types.d.ts +23 -0
- package/dist/src/construct/rest-api-lambda/types.js +1 -0
- package/dist/src/construct/rest-api-lambda-with-cache/index.d.ts +2 -0
- package/dist/src/construct/rest-api-lambda-with-cache/index.js +2 -0
- package/dist/src/construct/rest-api-lambda-with-cache/main.d.ts +56 -0
- package/dist/src/construct/rest-api-lambda-with-cache/main.js +118 -0
- package/dist/src/construct/rest-api-lambda-with-cache/types.d.ts +11 -0
- package/dist/src/construct/rest-api-lambda-with-cache/types.js +1 -0
- package/dist/src/construct/site-with-ecs-backend/constants.d.ts +4 -0
- package/dist/src/construct/site-with-ecs-backend/constants.js +5 -0
- package/dist/src/construct/site-with-ecs-backend/index.d.ts +3 -0
- package/dist/src/construct/site-with-ecs-backend/index.js +3 -0
- package/dist/src/construct/site-with-ecs-backend/main.d.ts +154 -0
- package/dist/src/construct/site-with-ecs-backend/main.js +437 -0
- package/dist/src/construct/site-with-ecs-backend/types.d.ts +49 -0
- package/dist/src/construct/site-with-ecs-backend/types.js +1 -0
- package/dist/src/construct/site-with-lambda-backend/constants.d.ts +5 -0
- package/dist/src/construct/site-with-lambda-backend/constants.js +6 -0
- package/dist/src/construct/site-with-lambda-backend/index.d.ts +3 -0
- package/dist/src/construct/site-with-lambda-backend/index.js +3 -0
- package/dist/src/construct/site-with-lambda-backend/main.d.ts +116 -0
- package/dist/src/construct/site-with-lambda-backend/main.js +316 -0
- package/dist/src/construct/site-with-lambda-backend/types.d.ts +45 -0
- package/dist/src/construct/site-with-lambda-backend/types.js +1 -0
- package/dist/src/construct/static-asset-deployment/index.d.ts +2 -0
- package/dist/src/construct/static-asset-deployment/index.js +2 -0
- package/dist/src/construct/static-asset-deployment/main.d.ts +41 -0
- package/dist/src/construct/static-asset-deployment/main.js +113 -0
- package/dist/src/construct/static-asset-deployment/types.d.ts +41 -0
- package/dist/src/construct/static-asset-deployment/types.js +1 -0
- package/dist/src/construct/static-site/index.d.ts +2 -0
- package/dist/src/construct/static-site/index.js +2 -0
- package/dist/src/construct/static-site/main.d.ts +84 -0
- package/dist/src/construct/static-site/main.js +136 -0
- package/dist/src/construct/static-site/types.d.ts +30 -0
- package/dist/src/construct/static-site/types.js +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +5 -0
- package/dist/src/services/api-gateway/index.d.ts +2 -0
- package/dist/src/services/api-gateway/index.js +2 -0
- package/dist/src/services/api-gateway/main.d.ts +68 -0
- package/dist/src/services/api-gateway/main.js +173 -0
- package/dist/src/services/api-gateway/types.d.ts +10 -0
- package/dist/src/services/api-gateway/types.js +1 -0
- package/dist/src/services/appconfig/constants.d.ts +12 -0
- package/dist/src/services/appconfig/constants.js +51 -0
- package/dist/src/services/appconfig/index.d.ts +3 -0
- package/dist/src/services/appconfig/index.js +3 -0
- package/dist/src/services/appconfig/main.d.ts +63 -0
- package/dist/src/services/appconfig/main.js +119 -0
- package/dist/src/services/appconfig/types.d.ts +17 -0
- package/dist/src/services/appconfig/types.js +1 -0
- package/dist/src/services/certificate-manager/index.d.ts +2 -0
- package/dist/src/services/certificate-manager/index.js +2 -0
- package/dist/src/services/certificate-manager/main.d.ts +41 -0
- package/dist/src/services/certificate-manager/main.js +62 -0
- package/dist/src/services/certificate-manager/types.d.ts +11 -0
- package/dist/src/services/certificate-manager/types.js +1 -0
- package/dist/src/services/cloudfront/index.d.ts +2 -0
- package/dist/src/services/cloudfront/index.js +2 -0
- package/dist/src/services/cloudfront/main.d.ts +96 -0
- package/dist/src/services/cloudfront/main.js +233 -0
- package/dist/src/services/cloudfront/types.d.ts +13 -0
- package/dist/src/services/cloudfront/types.js +1 -0
- package/dist/src/services/cloudtrail/index.d.ts +2 -0
- package/dist/src/services/cloudtrail/index.js +2 -0
- package/dist/src/services/cloudtrail/main.d.ts +44 -0
- package/dist/src/services/cloudtrail/main.js +71 -0
- package/dist/src/services/cloudtrail/types.d.ts +5 -0
- package/dist/src/services/cloudtrail/types.js +1 -0
- package/dist/src/services/cloudwatch/index.d.ts +3 -0
- package/dist/src/services/cloudwatch/index.js +3 -0
- package/dist/src/services/cloudwatch/logs.d.ts +47 -0
- package/dist/src/services/cloudwatch/logs.js +98 -0
- package/dist/src/services/cloudwatch/main.d.ts +207 -0
- package/dist/src/services/cloudwatch/main.js +552 -0
- package/dist/src/services/cloudwatch/types.d.ts +89 -0
- package/dist/src/services/cloudwatch/types.js +1 -0
- package/dist/src/services/codebuild/index.d.ts +1 -0
- package/dist/src/services/codebuild/index.js +1 -0
- package/dist/src/services/codebuild/main.d.ts +36 -0
- package/dist/src/services/codebuild/main.js +67 -0
- package/dist/src/services/constants.d.ts +4 -0
- package/dist/src/services/constants.js +5 -0
- package/dist/src/services/dynamodb/index.d.ts +2 -0
- package/dist/src/services/dynamodb/index.js +2 -0
- package/dist/src/services/dynamodb/main.d.ts +35 -0
- package/dist/src/services/dynamodb/main.js +72 -0
- package/dist/src/services/dynamodb/types.d.ts +10 -0
- package/dist/src/services/dynamodb/types.js +1 -0
- package/dist/src/services/elastic-container-registry/index.d.ts +1 -0
- package/dist/src/services/elastic-container-registry/index.js +1 -0
- package/dist/src/services/elastic-container-registry/main.d.ts +27 -0
- package/dist/src/services/elastic-container-registry/main.js +33 -0
- package/dist/src/services/elastic-container-service/index.d.ts +2 -0
- package/dist/src/services/elastic-container-service/index.js +2 -0
- package/dist/src/services/elastic-container-service/main.d.ts +56 -0
- package/dist/src/services/elastic-container-service/main.js +149 -0
- package/dist/src/services/elastic-container-service/types.d.ts +45 -0
- package/dist/src/services/elastic-container-service/types.js +1 -0
- package/dist/src/services/elastic-file-system/index.d.ts +2 -0
- package/dist/src/services/elastic-file-system/index.js +2 -0
- package/dist/src/services/elastic-file-system/main.d.ts +42 -0
- package/dist/src/services/elastic-file-system/main.js +76 -0
- package/dist/src/services/elastic-file-system/types.d.ts +15 -0
- package/dist/src/services/elastic-file-system/types.js +1 -0
- package/dist/src/services/elastic-kubernetes-service/index.d.ts +2 -0
- package/dist/src/services/elastic-kubernetes-service/index.js +2 -0
- package/dist/src/services/elastic-kubernetes-service/main.d.ts +32 -0
- package/dist/src/services/elastic-kubernetes-service/main.js +85 -0
- package/dist/src/services/elastic-kubernetes-service/types.d.ts +7 -0
- package/dist/src/services/elastic-kubernetes-service/types.js +1 -0
- package/dist/src/services/elasticache/index.d.ts +2 -0
- package/dist/src/services/elasticache/index.js +2 -0
- package/dist/src/services/elasticache/main.d.ts +47 -0
- package/dist/src/services/elasticache/main.js +90 -0
- package/dist/src/services/elasticache/types.d.ts +9 -0
- package/dist/src/services/elasticache/types.js +1 -0
- package/dist/src/services/eventbridge/index.d.ts +3 -0
- package/dist/src/services/eventbridge/index.js +3 -0
- package/dist/src/services/eventbridge/main.d.ts +93 -0
- package/dist/src/services/eventbridge/main.js +295 -0
- package/dist/src/services/eventbridge/target.d.ts +57 -0
- package/dist/src/services/eventbridge/target.js +61 -0
- package/dist/src/services/eventbridge/types.d.ts +43 -0
- package/dist/src/services/eventbridge/types.js +1 -0
- package/dist/src/services/evidently/index.d.ts +2 -0
- package/dist/src/services/evidently/index.js +2 -0
- package/dist/src/services/evidently/main.d.ts +56 -0
- package/dist/src/services/evidently/main.js +114 -0
- package/dist/src/services/evidently/types.d.ts +21 -0
- package/dist/src/services/evidently/types.js +1 -0
- package/dist/src/services/identity-access-management/index.d.ts +1 -0
- package/dist/src/services/identity-access-management/index.js +1 -0
- package/dist/src/services/identity-access-management/main.d.ts +263 -0
- package/dist/src/services/identity-access-management/main.js +609 -0
- package/dist/src/services/index.d.ts +28 -0
- package/dist/src/services/index.js +28 -0
- package/dist/src/services/key-management-service/index.d.ts +2 -0
- package/dist/src/services/key-management-service/index.js +2 -0
- package/dist/src/services/key-management-service/main.d.ts +28 -0
- package/dist/src/services/key-management-service/main.js +39 -0
- package/dist/src/services/key-management-service/types.d.ts +5 -0
- package/dist/src/services/key-management-service/types.js +1 -0
- package/dist/src/services/lambda/index.d.ts +2 -0
- package/dist/src/services/lambda/index.js +2 -0
- package/dist/src/services/lambda/main.d.ts +89 -0
- package/dist/src/services/lambda/main.js +232 -0
- package/dist/src/services/lambda/types.d.ts +54 -0
- package/dist/src/services/lambda/types.js +1 -0
- package/dist/src/services/route53/index.d.ts +2 -0
- package/dist/src/services/route53/index.js +2 -0
- package/dist/src/services/route53/main.d.ts +66 -0
- package/dist/src/services/route53/main.js +136 -0
- package/dist/src/services/route53/types.d.ts +6 -0
- package/dist/src/services/route53/types.js +1 -0
- package/dist/src/services/secrets-manager/index.d.ts +2 -0
- package/dist/src/services/secrets-manager/index.js +2 -0
- package/dist/src/services/secrets-manager/main.d.ts +43 -0
- package/dist/src/services/secrets-manager/main.js +71 -0
- package/dist/src/services/secrets-manager/types.d.ts +3 -0
- package/dist/src/services/secrets-manager/types.js +1 -0
- package/dist/src/services/simple-notification-service/index.d.ts +2 -0
- package/dist/src/services/simple-notification-service/index.js +2 -0
- package/dist/src/services/simple-notification-service/main.d.ts +38 -0
- package/dist/src/services/simple-notification-service/main.js +68 -0
- package/dist/src/services/simple-notification-service/types.d.ts +5 -0
- package/dist/src/services/simple-notification-service/types.js +1 -0
- package/dist/src/services/simple-queue-service/index.d.ts +2 -0
- package/dist/src/services/simple-queue-service/index.js +2 -0
- package/dist/src/services/simple-queue-service/main.d.ts +45 -0
- package/dist/src/services/simple-queue-service/main.js +101 -0
- package/dist/src/services/simple-queue-service/types.d.ts +15 -0
- package/dist/src/services/simple-queue-service/types.js +1 -0
- package/dist/src/services/simple-storage-service/index.d.ts +2 -0
- package/dist/src/services/simple-storage-service/index.js +2 -0
- package/dist/src/services/simple-storage-service/main.d.ts +79 -0
- package/dist/src/services/simple-storage-service/main.js +191 -0
- package/dist/src/services/simple-storage-service/types.d.ts +25 -0
- package/dist/src/services/simple-storage-service/types.js +1 -0
- package/dist/src/services/step-function/index.d.ts +2 -0
- package/dist/src/services/step-function/index.js +2 -0
- package/dist/src/services/step-function/main.d.ts +161 -0
- package/dist/src/services/step-function/main.js +380 -0
- package/dist/src/services/step-function/types.d.ts +88 -0
- package/dist/src/services/step-function/types.js +1 -0
- package/dist/src/services/systems-manager/index.d.ts +2 -0
- package/dist/src/services/systems-manager/index.js +2 -0
- package/dist/src/services/systems-manager/main.d.ts +55 -0
- package/dist/src/services/systems-manager/main.js +97 -0
- package/dist/src/services/systems-manager/types.d.ts +9 -0
- package/dist/src/services/systems-manager/types.js +1 -0
- package/dist/src/services/virtual-private-cloud/index.d.ts +2 -0
- package/dist/src/services/virtual-private-cloud/index.js +2 -0
- package/dist/src/services/virtual-private-cloud/ipv6.d.ts +7 -0
- package/dist/src/services/virtual-private-cloud/ipv6.js +38 -0
- package/dist/src/services/virtual-private-cloud/main.d.ts +43 -0
- package/dist/src/services/virtual-private-cloud/main.js +87 -0
- package/dist/src/services/virtual-private-cloud/types.d.ts +4 -0
- package/dist/src/services/virtual-private-cloud/types.js +1 -0
- package/dist/src/services/web-application-firewall/index.d.ts +2 -0
- package/dist/src/services/web-application-firewall/index.js +2 -0
- package/dist/src/services/web-application-firewall/main.d.ts +35 -0
- package/dist/src/services/web-application-firewall/main.js +61 -0
- package/dist/src/services/web-application-firewall/types.d.ts +9 -0
- package/dist/src/services/web-application-firewall/types.js +1 -0
- package/dist/src/types/index.d.ts +6 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/utils/index.d.ts +45 -0
- package/dist/src/utils/index.js +61 -0
- package/package.json +44 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Duration, Fn } from 'aws-cdk-lib';
|
|
2
|
+
import { SecurityGroup } from 'aws-cdk-lib/aws-ec2';
|
|
3
|
+
import { Archive, EventBus, Schedule } from 'aws-cdk-lib/aws-events';
|
|
4
|
+
import { SfnStateMachine, SqsQueue } from 'aws-cdk-lib/aws-events-targets';
|
|
5
|
+
import { CfnQueuePolicy } from 'aws-cdk-lib/aws-sqs';
|
|
6
|
+
import { JsonPath, Map } from 'aws-cdk-lib/aws-stepfunctions';
|
|
7
|
+
import _ from 'lodash';
|
|
8
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
9
|
+
import { Handler } from './handler.js';
|
|
10
|
+
/**
|
|
11
|
+
* @classdesc Provides a construct to create and deploy an EventBridge Event Handler
|
|
12
|
+
* @example
|
|
13
|
+
* import { EventHandler, EventHandlerProps } '@gradientedge/cdk-utils'
|
|
14
|
+
* import { Construct } from 'constructs'
|
|
15
|
+
*
|
|
16
|
+
* class CustomConstruct extends EventHandler {
|
|
17
|
+
* constructor(parent: Construct, id: string, props: EventHandlerProps) {
|
|
18
|
+
* super(parent, id, props)
|
|
19
|
+
* this.props = props
|
|
20
|
+
* this.id = id
|
|
21
|
+
* this.initResources()
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
export class EventHandler extends CommonConstruct {
|
|
26
|
+
props;
|
|
27
|
+
id;
|
|
28
|
+
handler;
|
|
29
|
+
provisionTarget = true;
|
|
30
|
+
securityGroup;
|
|
31
|
+
useMapState;
|
|
32
|
+
vpc;
|
|
33
|
+
constructor(parent, id, props) {
|
|
34
|
+
super(parent, id, props);
|
|
35
|
+
this.props = props;
|
|
36
|
+
this.id = id;
|
|
37
|
+
this.handler = new Handler();
|
|
38
|
+
}
|
|
39
|
+
initResources() {
|
|
40
|
+
this.createSQSEventSource();
|
|
41
|
+
this.createWorkflow();
|
|
42
|
+
this.createEventRulePattern();
|
|
43
|
+
this.createEventRuleTargets();
|
|
44
|
+
this.resolveEventBus();
|
|
45
|
+
this.createEventArchive();
|
|
46
|
+
this.createEventRule();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @summary Method to resolve common vpc or create a new one.
|
|
50
|
+
*/
|
|
51
|
+
resolveVpc() {
|
|
52
|
+
if (this.props.vpcName) {
|
|
53
|
+
this.vpc = this.vpcManager.retrieveCommonVpc(`${this.id}-vpc`, this, this.props.vpcName);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @summary Method to resolve the exported security group.
|
|
58
|
+
*/
|
|
59
|
+
resolveSecurityGroup() {
|
|
60
|
+
if (this.props.securityGroupExportName) {
|
|
61
|
+
this.securityGroup = SecurityGroup.fromSecurityGroupId(this, `${this.id}-security-group`, Fn.importValue(this.props.securityGroupExportName));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @summary Method to create sqs event source if queue targets are defined.
|
|
66
|
+
*/
|
|
67
|
+
createSQSEventSource() {
|
|
68
|
+
if (!this.props.eventSqs)
|
|
69
|
+
return;
|
|
70
|
+
this.handler.queue = this.sqsManager.createQueue(`${this.id}-sqs-queue`, this, this.props.eventSqs);
|
|
71
|
+
const sqsPolicyDocument = this.iamManager.createPolicyForSqsEvent(`${this.id}-sqs-policy-document`, this, this.handler.queue, this.handler.rule);
|
|
72
|
+
new CfnQueuePolicy(this, `${this.id}-sqs-queue-policy`, {
|
|
73
|
+
policyDocument: sqsPolicyDocument.toJSON(),
|
|
74
|
+
queues: [this.handler.queue.queueUrl],
|
|
75
|
+
});
|
|
76
|
+
this.handler.sqsTargets = [new SqsQueue(this.handler.queue)];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @summary Method to create the event rule pattern.
|
|
80
|
+
*/
|
|
81
|
+
createEventRulePattern() {
|
|
82
|
+
if (!this.props.eventRule)
|
|
83
|
+
return;
|
|
84
|
+
this.handler.rulePattern = this.props.eventRule.eventPattern;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @summary Method to create the event rule targets.
|
|
88
|
+
*/
|
|
89
|
+
createEventRuleTargets() {
|
|
90
|
+
this.handler.targets = [
|
|
91
|
+
...this.handler.stepFunctionTargets,
|
|
92
|
+
...this.handler.lambdaTargets,
|
|
93
|
+
...this.handler.sqsTargets,
|
|
94
|
+
...this.handler.ecsTargets,
|
|
95
|
+
...this.handler.logTargets,
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @summary Method to resolve the event bus name or use the default bus.
|
|
100
|
+
*/
|
|
101
|
+
resolveEventBus() {
|
|
102
|
+
this.handler.eventBus = EventBus.fromEventBusName(this, `${this.id}-bus`, this.resourceNameFormatter.format(this.props.eventBusName, this.props.resourceNameOptions?.eventbridgeBus) ??
|
|
103
|
+
'default');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @summary Method to create an event archive if the event rule is not a scheduled one.
|
|
107
|
+
*/
|
|
108
|
+
createEventArchive() {
|
|
109
|
+
/* do not enable for scheduled events */
|
|
110
|
+
if (!this.props.eventRule ||
|
|
111
|
+
this.props.eventRule.schedule ||
|
|
112
|
+
this.props.eventRuleSchedule ||
|
|
113
|
+
!this.props.eventRuleArchiveEnabled)
|
|
114
|
+
return;
|
|
115
|
+
this.handler.archive = new Archive(this, `${this.id}-archive`, {
|
|
116
|
+
archiveName: `${this.props.eventRule.ruleName}-${this.props.stage}`.replace(`${this.node.tryGetContext('stackName')}-`, ''),
|
|
117
|
+
description: `Archive of events for ${this.props.eventRule.ruleName}`,
|
|
118
|
+
eventPattern: this.handler.rulePattern,
|
|
119
|
+
retention: Duration.days(this.props.eventRetentionInDays ?? 7),
|
|
120
|
+
sourceEventBus: this.handler.eventBus,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @summary Method to create the event rule.
|
|
125
|
+
*/
|
|
126
|
+
createEventRule() {
|
|
127
|
+
if (!this.props.eventRule)
|
|
128
|
+
return;
|
|
129
|
+
let schedule;
|
|
130
|
+
if (this.props.eventRuleSchedule) {
|
|
131
|
+
schedule = Schedule.expression(this.props.eventRuleSchedule);
|
|
132
|
+
}
|
|
133
|
+
this.handler.rule = this.eventManager.createRule(`${this.id}-rule`, this, {
|
|
134
|
+
...this.props.eventRule,
|
|
135
|
+
eventPattern: this.handler.rulePattern,
|
|
136
|
+
schedule: schedule,
|
|
137
|
+
}, this.props.eventBusName ? this.handler.eventBus : undefined, this.handler.targets);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @summary Method to create the workflow steps.
|
|
141
|
+
*/
|
|
142
|
+
createWorkflowSteps() { }
|
|
143
|
+
/**
|
|
144
|
+
* @summary Method to create the workflow definition.
|
|
145
|
+
*/
|
|
146
|
+
createWorkflowDefinition() {
|
|
147
|
+
if (this.useMapState) {
|
|
148
|
+
this.handler.workflowMapState = new Map(this, `Map Iterator`, {
|
|
149
|
+
...this.props.workflowMapState,
|
|
150
|
+
itemsPath: JsonPath.entirePayload,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
this.handler.workflowDefinition = this.handler.eventWorkflowDefinition;
|
|
154
|
+
if (this.useMapState) {
|
|
155
|
+
this.handler.workflowMapState.itemProcessor(this.handler.workflowDefinition);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @summary Method to create the workflow policy.
|
|
160
|
+
*/
|
|
161
|
+
createWorkflowPolicy() { }
|
|
162
|
+
/**
|
|
163
|
+
* @summary Method to create the workflow role.
|
|
164
|
+
*/
|
|
165
|
+
createWorkflowRole() {
|
|
166
|
+
this.handler.workflowRole = this.iamManager.createRoleForStepFunction(`${this.id}-workflow-role`, this, this.handler.workflowPolicy);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @summary Method to create the workflow log group.
|
|
170
|
+
*/
|
|
171
|
+
createWorkflowLogGroup() {
|
|
172
|
+
this.handler.workflowLogGroup = this.logManager.createLogGroup(`${this.id}-workflow-log`, this, this.props.workflowLog);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @summary Method to create the workflow state machine.
|
|
176
|
+
*/
|
|
177
|
+
createWorkflowStateMachine() {
|
|
178
|
+
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);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @summary Method to create the workflow.
|
|
182
|
+
*/
|
|
183
|
+
createWorkflow() {
|
|
184
|
+
if (_.isEmpty(this.props.workflow))
|
|
185
|
+
return;
|
|
186
|
+
this.createWorkflowSteps();
|
|
187
|
+
this.createWorkflowDefinition();
|
|
188
|
+
this.createWorkflowPolicy();
|
|
189
|
+
this.createWorkflowRole();
|
|
190
|
+
this.createWorkflowLogGroup();
|
|
191
|
+
this.createWorkflowStateMachine();
|
|
192
|
+
if (this.provisionTarget) {
|
|
193
|
+
this.handler.stepFunctionTargets = [new SfnStateMachine(this.handler.workflow)];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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/index.js';
|
|
8
|
+
import { EventRuleProps, LogProps, QueueProps, SfnMapProps, SfnStateMachineProps, VpcProps } from '../../services/index.js';
|
|
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
|
+
vpc: VpcProps;
|
|
18
|
+
vpcName?: string;
|
|
19
|
+
workflow: SfnStateMachineProps;
|
|
20
|
+
workflowLog: LogProps;
|
|
21
|
+
workflowMapState: SfnMapProps;
|
|
22
|
+
}
|
|
23
|
+
export interface EventHandlerType {
|
|
24
|
+
archive: Archive;
|
|
25
|
+
ecsTargets: EcsTask[];
|
|
26
|
+
eventBus: IEventBus;
|
|
27
|
+
lambdaTargets: LambdaFunction[];
|
|
28
|
+
logTargets: CloudWatchLogGroup[];
|
|
29
|
+
queue: Queue;
|
|
30
|
+
rule: Rule;
|
|
31
|
+
rulePattern: any;
|
|
32
|
+
sqsTargets: SqsQueue[];
|
|
33
|
+
stepFunctionTargets: SfnStateMachine[];
|
|
34
|
+
targets: IRuleTarget[];
|
|
35
|
+
workflow: StateMachine;
|
|
36
|
+
workflowDefinition: Chain;
|
|
37
|
+
workflowLogGroup: LogGroup;
|
|
38
|
+
workflowMapState: Map;
|
|
39
|
+
workflowPolicy: PolicyDocument;
|
|
40
|
+
workflowRole: Role;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './api-to-any-target/index.js';
|
|
2
|
+
export * from './api-to-eventbridge-target/index.js';
|
|
3
|
+
export * from './api-to-eventbridge-target-with-sns/index.js';
|
|
4
|
+
export * from './api-to-lambda-target/index.js';
|
|
5
|
+
export * from './application-configuration/index.js';
|
|
6
|
+
export * from './event-handler/index.js';
|
|
7
|
+
export * from './lambda-with-iam-access/index.js';
|
|
8
|
+
export * from './piped-event-handler/index.js';
|
|
9
|
+
export * from './rest-api-lambda/index.js';
|
|
10
|
+
export * from './rest-api-lambda-with-cache/index.js';
|
|
11
|
+
export * from './site-with-ecs-backend/index.js';
|
|
12
|
+
export * from './site-with-lambda-backend/index.js';
|
|
13
|
+
export * from './static-asset-deployment/index.js';
|
|
14
|
+
export * from './static-site/index.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './api-to-any-target/index.js';
|
|
2
|
+
export * from './api-to-eventbridge-target/index.js';
|
|
3
|
+
export * from './api-to-eventbridge-target-with-sns/index.js';
|
|
4
|
+
export * from './api-to-lambda-target/index.js';
|
|
5
|
+
export * from './application-configuration/index.js';
|
|
6
|
+
export * from './event-handler/index.js';
|
|
7
|
+
export * from './lambda-with-iam-access/index.js';
|
|
8
|
+
export * from './piped-event-handler/index.js';
|
|
9
|
+
export * from './rest-api-lambda/index.js';
|
|
10
|
+
export * from './rest-api-lambda-with-cache/index.js';
|
|
11
|
+
export * from './site-with-ecs-backend/index.js';
|
|
12
|
+
export * from './site-with-lambda-backend/index.js';
|
|
13
|
+
export * from './static-asset-deployment/index.js';
|
|
14
|
+
export * from './static-site/index.js';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ISecurityGroup, IVpc, SubnetSelection } from 'aws-cdk-lib/aws-ec2';
|
|
2
|
+
import { IAccessPoint } from 'aws-cdk-lib/aws-efs';
|
|
3
|
+
import { CfnAccessKey, PolicyDocument, Role, User } from 'aws-cdk-lib/aws-iam';
|
|
4
|
+
import { IFunction, ILayerVersion } from 'aws-cdk-lib/aws-lambda';
|
|
5
|
+
import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
|
|
6
|
+
import { Construct } from 'constructs';
|
|
7
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
8
|
+
import { LambdaWithIamAccessEnvironment, LambdaWithIamAccessProps } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Provides a construct to create a lambda function with IAM access
|
|
11
|
+
* @example
|
|
12
|
+
* import { LambdaWithIamAccess, LambdaWithIamAccessProps } '@gradientedge/cdk-utils'
|
|
13
|
+
* import { Construct } from 'constructs'
|
|
14
|
+
*
|
|
15
|
+
* class CustomConstruct extends LambdaWithIamAccess {
|
|
16
|
+
* constructor(parent: Construct, id: string, props: LambdaWithIamAccessProps) {
|
|
17
|
+
* super(parent, id, props)
|
|
18
|
+
* this.props = props
|
|
19
|
+
* this.id = id
|
|
20
|
+
* this.initResources()
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export declare class LambdaWithIamAccess extends CommonConstruct {
|
|
25
|
+
props: LambdaWithIamAccessProps;
|
|
26
|
+
id: string;
|
|
27
|
+
lambdaPolicy: PolicyDocument;
|
|
28
|
+
lambdaRole: Role;
|
|
29
|
+
lambdaEnvironment: LambdaWithIamAccessEnvironment;
|
|
30
|
+
lambdaLayers: ILayerVersion[];
|
|
31
|
+
lambdaFunction: IFunction;
|
|
32
|
+
lambdaIamUser: User;
|
|
33
|
+
lambdaUserAccessKey: CfnAccessKey;
|
|
34
|
+
lambdaUserAccessSecret: Secret;
|
|
35
|
+
lambdaVpc: IVpc;
|
|
36
|
+
lambdaSecurityGroups: ISecurityGroup[];
|
|
37
|
+
lambdaAccessPoint: IAccessPoint;
|
|
38
|
+
lambdaMountPath: string;
|
|
39
|
+
lambdaVpcSubnets: SubnetSelection;
|
|
40
|
+
constructor(parent: Construct, id: string, props: LambdaWithIamAccessProps);
|
|
41
|
+
/**
|
|
42
|
+
* @summary Initialise and provision resources
|
|
43
|
+
*/
|
|
44
|
+
initResources(): void;
|
|
45
|
+
protected resolveVpc(): void;
|
|
46
|
+
protected resolveSecurityGroups(): void;
|
|
47
|
+
protected resolveAccessPoint(): void;
|
|
48
|
+
protected resolveMountPath(): void;
|
|
49
|
+
protected resolveVpcSubnets(): void;
|
|
50
|
+
/**
|
|
51
|
+
* @summary Method to create iam policy for Lambda function
|
|
52
|
+
*/
|
|
53
|
+
protected createLambdaPolicy(): void;
|
|
54
|
+
/**
|
|
55
|
+
* @summary Method to create iam role for Lambda function
|
|
56
|
+
*/
|
|
57
|
+
protected createLambdaRole(): void;
|
|
58
|
+
/**
|
|
59
|
+
* @summary Method to create environment variables for Lambda function
|
|
60
|
+
*/
|
|
61
|
+
protected createLambdaEnvironment(): void;
|
|
62
|
+
/**
|
|
63
|
+
* @summary Method to create layers for Lambda function
|
|
64
|
+
*/
|
|
65
|
+
protected createLambdaLayers(): void;
|
|
66
|
+
/**
|
|
67
|
+
* @summary Method to create lambda function
|
|
68
|
+
*/
|
|
69
|
+
protected createLambdaFunction(): void;
|
|
70
|
+
/**
|
|
71
|
+
* @summary Method to create iam user for the lambda function
|
|
72
|
+
*/
|
|
73
|
+
protected createIamUserForLambdaFunction(): void;
|
|
74
|
+
/**
|
|
75
|
+
* @summary Method to create iam secret for the lambda function
|
|
76
|
+
*/
|
|
77
|
+
protected createIamSecretForLambdaFunction(): void;
|
|
78
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Fn } from 'aws-cdk-lib';
|
|
2
|
+
import { SecurityGroup } from 'aws-cdk-lib/aws-ec2';
|
|
3
|
+
import { CfnAccessKey, ManagedPolicy, Policy, PolicyDocument, PolicyStatement, User } from 'aws-cdk-lib/aws-iam';
|
|
4
|
+
import { LayerVersion } from 'aws-cdk-lib/aws-lambda';
|
|
5
|
+
import _ from 'lodash';
|
|
6
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
7
|
+
import { Architecture } from '../../services/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* @classdesc Provides a construct to create a lambda function with IAM access
|
|
10
|
+
* @example
|
|
11
|
+
* import { LambdaWithIamAccess, LambdaWithIamAccessProps } '@gradientedge/cdk-utils'
|
|
12
|
+
* import { Construct } from 'constructs'
|
|
13
|
+
*
|
|
14
|
+
* class CustomConstruct extends LambdaWithIamAccess {
|
|
15
|
+
* constructor(parent: Construct, id: string, props: LambdaWithIamAccessProps) {
|
|
16
|
+
* super(parent, id, props)
|
|
17
|
+
* this.props = props
|
|
18
|
+
* this.id = id
|
|
19
|
+
* this.initResources()
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
export class LambdaWithIamAccess extends CommonConstruct {
|
|
24
|
+
/* LambdaWithIamAccess props */
|
|
25
|
+
props;
|
|
26
|
+
id;
|
|
27
|
+
/* LambdaWithIamAccess resources */
|
|
28
|
+
lambdaPolicy;
|
|
29
|
+
lambdaRole;
|
|
30
|
+
lambdaEnvironment;
|
|
31
|
+
lambdaLayers = [];
|
|
32
|
+
lambdaFunction;
|
|
33
|
+
lambdaIamUser;
|
|
34
|
+
lambdaUserAccessKey;
|
|
35
|
+
lambdaUserAccessSecret;
|
|
36
|
+
lambdaVpc;
|
|
37
|
+
lambdaSecurityGroups;
|
|
38
|
+
lambdaAccessPoint;
|
|
39
|
+
lambdaMountPath;
|
|
40
|
+
lambdaVpcSubnets;
|
|
41
|
+
constructor(parent, id, props) {
|
|
42
|
+
super(parent, id, props);
|
|
43
|
+
this.props = props;
|
|
44
|
+
this.id = id;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @summary Initialise and provision resources
|
|
48
|
+
*/
|
|
49
|
+
initResources() {
|
|
50
|
+
this.resolveVpc();
|
|
51
|
+
this.resolveSecurityGroups();
|
|
52
|
+
this.resolveAccessPoint();
|
|
53
|
+
this.resolveMountPath();
|
|
54
|
+
this.resolveVpcSubnets();
|
|
55
|
+
this.createLambdaPolicy();
|
|
56
|
+
this.createLambdaRole();
|
|
57
|
+
this.createLambdaEnvironment();
|
|
58
|
+
this.createLambdaLayers();
|
|
59
|
+
this.createLambdaFunction();
|
|
60
|
+
this.createIamUserForLambdaFunction();
|
|
61
|
+
this.createIamSecretForLambdaFunction();
|
|
62
|
+
}
|
|
63
|
+
resolveVpc() {
|
|
64
|
+
if (this.props.vpcName) {
|
|
65
|
+
this.lambdaVpc = this.vpcManager.retrieveCommonVpc(`${this.id}-vpc`, this, this.props.vpcName);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
resolveSecurityGroups() {
|
|
69
|
+
if (this.props.securityGroupExportName) {
|
|
70
|
+
const lambdaSecurityGroup = SecurityGroup.fromSecurityGroupId(this, `${this.id}-security-group`, Fn.importValue(this.props.securityGroupExportName));
|
|
71
|
+
this.addCfnOutput(`${this.id}-sg`, lambdaSecurityGroup.securityGroupId);
|
|
72
|
+
this.lambdaSecurityGroups = [lambdaSecurityGroup];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
resolveAccessPoint() { }
|
|
76
|
+
resolveMountPath() { }
|
|
77
|
+
resolveVpcSubnets() { }
|
|
78
|
+
/**
|
|
79
|
+
* @summary Method to create iam policy for Lambda function
|
|
80
|
+
*/
|
|
81
|
+
createLambdaPolicy() {
|
|
82
|
+
this.lambdaPolicy = new PolicyDocument({
|
|
83
|
+
statements: [this.iamManager.statementForCreateAnyLogStream(), this.iamManager.statementForPutXrayTelemetry()],
|
|
84
|
+
});
|
|
85
|
+
if (this.props.configEnabled) {
|
|
86
|
+
this.lambdaPolicy.addStatements(this.iamManager.statementForReadAnyAppConfig(), this.iamManager.statementForAppConfigExecution());
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @summary Method to create iam role for Lambda function
|
|
91
|
+
*/
|
|
92
|
+
createLambdaRole() {
|
|
93
|
+
this.lambdaRole = this.iamManager.createRoleForLambda(`${this.id}-lambda-role`, this, this.lambdaPolicy);
|
|
94
|
+
if (this.props.vpcName) {
|
|
95
|
+
this.lambdaRole.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaVPCAccessExecutionRole'));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @summary Method to create environment variables for Lambda function
|
|
100
|
+
*/
|
|
101
|
+
createLambdaEnvironment() {
|
|
102
|
+
this.lambdaEnvironment = {
|
|
103
|
+
LOG_LEVEL: this.props.logLevel,
|
|
104
|
+
NODE_ENV: this.props.nodeEnv,
|
|
105
|
+
TZ: this.props.timezone,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @summary Method to create layers for Lambda function
|
|
110
|
+
*/
|
|
111
|
+
createLambdaLayers() {
|
|
112
|
+
const layers = [];
|
|
113
|
+
if (this.props.lambdaLayerSources) {
|
|
114
|
+
_.forEach(this.props.lambdaLayerSources, (source, index) => {
|
|
115
|
+
layers.push(this.lambdaManager.createLambdaLayer(`${this.id}-layer-${index}`, this, source));
|
|
116
|
+
});
|
|
117
|
+
this.lambdaLayers = layers;
|
|
118
|
+
}
|
|
119
|
+
if (this.props.configEnabled) {
|
|
120
|
+
const appConfigExtensionLayer = LayerVersion.fromLayerVersionArn(this, `${this.id}-ac-extlayer`, this.appConfigManager.getArnForAppConfigExtension(this, Architecture.ARM_64));
|
|
121
|
+
this.lambdaLayers.push(appConfigExtensionLayer);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @summary Method to create lambda function
|
|
126
|
+
*/
|
|
127
|
+
createLambdaFunction() {
|
|
128
|
+
if (this.props.lambdaInsightsVersion) {
|
|
129
|
+
_.assign(this.props.lambda, {
|
|
130
|
+
insightsVersion: this.props.lambdaInsightsVersion,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
this.lambdaFunction = this.lambdaManager.createLambdaFunction(`${this.id}-lambda`, this, this.props.lambda, this.lambdaRole, this.lambdaLayers, this.props.lambdaSource, this.props.lambdaHandler || 'index.handler', this.lambdaEnvironment, this.lambdaVpc, this.lambdaSecurityGroups, this.lambdaAccessPoint, this.lambdaMountPath, this.lambdaVpcSubnets);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @summary Method to create iam user for the lambda function
|
|
137
|
+
*/
|
|
138
|
+
createIamUserForLambdaFunction() {
|
|
139
|
+
this.lambdaIamUser = new User(this, `${this.id}-lambda-user`, {
|
|
140
|
+
userName: this.resourceNameFormatter.format(`${this.id}-user`),
|
|
141
|
+
});
|
|
142
|
+
new Policy(this, `${this.id}-lambda-user-policy`, {
|
|
143
|
+
policyName: this.resourceNameFormatter.format(`${this.id}-policy`),
|
|
144
|
+
statements: [
|
|
145
|
+
new PolicyStatement({
|
|
146
|
+
actions: ['lambda:InvokeFunction'],
|
|
147
|
+
resources: [this.lambdaFunction.functionArn, `${this.lambdaFunction.functionArn}*`],
|
|
148
|
+
}),
|
|
149
|
+
],
|
|
150
|
+
users: [this.lambdaIamUser],
|
|
151
|
+
});
|
|
152
|
+
if (this.props.lambda.lambdaAliases && !_.isEmpty(this.props.lambda.lambdaAliases)) {
|
|
153
|
+
_.forEach(this.props.lambda.lambdaAliases, (alias, index) => {
|
|
154
|
+
new Policy(this, `${this.id}-alias-user-policy`, {
|
|
155
|
+
policyName: this.resourceNameFormatter.format(`${this.id}--alias-policy-${index}`),
|
|
156
|
+
statements: [
|
|
157
|
+
new PolicyStatement({
|
|
158
|
+
actions: ['lambda:InvokeFunction'],
|
|
159
|
+
resources: [
|
|
160
|
+
`${this.lambdaFunction.functionArn}:${alias.aliasName}`,
|
|
161
|
+
`${this.lambdaFunction.functionArn}:${alias.aliasName}*`,
|
|
162
|
+
],
|
|
163
|
+
}),
|
|
164
|
+
],
|
|
165
|
+
users: [this.lambdaIamUser],
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
this.lambdaUserAccessKey = new CfnAccessKey(this, `${this.id}-access-key-${this.props.stage}`, {
|
|
170
|
+
userName: this.lambdaIamUser.userName,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* @summary Method to create iam secret for the lambda function
|
|
175
|
+
*/
|
|
176
|
+
createIamSecretForLambdaFunction() {
|
|
177
|
+
this.lambdaUserAccessSecret = this.secretsManager.createSecret(`${this.id}-lambda-user-secret-${this.props.stage}`, this, this.props.lambdaSecret);
|
|
178
|
+
const cfnSecret = this.lambdaUserAccessSecret.node.defaultChild;
|
|
179
|
+
cfnSecret.generateSecretString = undefined;
|
|
180
|
+
cfnSecret.secretString = `{ "ACCESS_KEY_ID": "${this.lambdaUserAccessKey.ref}", "ACCESS_KEY_SECRET": "${this.lambdaUserAccessKey.attrSecretAccessKey}" }`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AssetCode, LambdaInsightsVersion } from 'aws-cdk-lib/aws-lambda';
|
|
2
|
+
import { SecretProps } from 'aws-cdk-lib/aws-secretsmanager';
|
|
3
|
+
import { CommonStackProps } from '../../common/index.js';
|
|
4
|
+
import { LambdaEnvironment, LambdaProps } from '../../services/index.js';
|
|
5
|
+
export interface LambdaWithIamAccessProps extends CommonStackProps {
|
|
6
|
+
configEnabled?: boolean;
|
|
7
|
+
lambda: LambdaProps;
|
|
8
|
+
lambdaHandler?: string;
|
|
9
|
+
lambdaInsightsVersion?: LambdaInsightsVersion;
|
|
10
|
+
lambdaLayerSources: AssetCode[];
|
|
11
|
+
lambdaSecret: SecretProps;
|
|
12
|
+
lambdaSource: AssetCode;
|
|
13
|
+
logLevel: string;
|
|
14
|
+
nodeEnv: string;
|
|
15
|
+
securityGroupExportName?: string;
|
|
16
|
+
timezone: string;
|
|
17
|
+
vpcName?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface LambdaWithIamAccessEnvironment extends LambdaEnvironment {
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IQueue } from 'aws-cdk-lib/aws-sqs';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { EventHandler } from '../event-handler/index.js';
|
|
4
|
+
import { PipedEventHandlerProps } from './types.js';
|
|
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
|
+
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,62 @@
|
|
|
1
|
+
import { SqsQueue } from 'aws-cdk-lib/aws-events-targets';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { EventHandler } from '../event-handler/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* @classdesc Provides a construct to create and deploy an EventBridge Piped Event Handler
|
|
6
|
+
* @example
|
|
7
|
+
* import { PipedEventHandler, PipedEventHandlerProps } '@gradientedge/cdk-utils'
|
|
8
|
+
* import { Construct } from 'constructs'
|
|
9
|
+
*
|
|
10
|
+
* class CustomConstruct extends PipedEventHandler {
|
|
11
|
+
* constructor(parent: Construct, id: string, props: PipedEventHandlerProps) {
|
|
12
|
+
* super(parent, id, props)
|
|
13
|
+
* this.props = props
|
|
14
|
+
* this.id = id
|
|
15
|
+
* this.initResources()
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export class PipedEventHandler extends EventHandler {
|
|
20
|
+
props;
|
|
21
|
+
pipedDlq;
|
|
22
|
+
pipedQueue;
|
|
23
|
+
constructor(parent, id, props) {
|
|
24
|
+
super(parent, id, props);
|
|
25
|
+
this.props = props;
|
|
26
|
+
this.id = id;
|
|
27
|
+
this.useMapState = true;
|
|
28
|
+
this.provisionTarget = false;
|
|
29
|
+
}
|
|
30
|
+
initResources() {
|
|
31
|
+
this.createPipedQueue();
|
|
32
|
+
this.handler.sqsTargets = [new SqsQueue(this.pipedQueue)];
|
|
33
|
+
super.initResources();
|
|
34
|
+
this.createSqsToSfnPipe();
|
|
35
|
+
this.createSqsToLambdaPipe();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @summary Method to create the piped queue and dlq.
|
|
39
|
+
*/
|
|
40
|
+
createPipedQueue() {
|
|
41
|
+
this.pipedDlq = this.sqsManager.createQueue(`${this.id}-pipe-queue-dlq`, this, this.props.pipedDlq);
|
|
42
|
+
this.pipedQueue = this.sqsManager.createQueue(`${this.id}-pipe-queue`, this, this.props.pipedQueue, this.pipedDlq);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @summary Method to create the SQS to SFN pipe.
|
|
46
|
+
*/
|
|
47
|
+
createSqsToSfnPipe() {
|
|
48
|
+
if (_.isEmpty(this.props.sqsToSfnPipe) || !this.handler.workflow)
|
|
49
|
+
return;
|
|
50
|
+
this.eventManager.createSqsToSfnCfnPipe(`${this.id}-pipe-sfn`, this, this.props.sqsToSfnPipe, this.pipedQueue, this.handler.workflow);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @summary Method to create the SQS to Lambda pipe.
|
|
54
|
+
*/
|
|
55
|
+
createSqsToLambdaPipe() {
|
|
56
|
+
if (_.isEmpty(this.props.sqsToLambdaPipe) || _.isEmpty(this.handler.lambdaFunctions))
|
|
57
|
+
return;
|
|
58
|
+
_.forEach(this.handler.lambdaFunctions, (lambdaFunction, index) => {
|
|
59
|
+
this.eventManager.createSqsToLambdaCfnPipe(`${this.id}-pipe-lambda-${index}`, this, this.props.sqsToLambdaPipe, this.pipedQueue, lambdaFunction);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|