@gradientedge/cdk-utils 4.11.4 → 4.13.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/common/construct.d.ts +3 -2
- package/dist/src/lib/common/construct.js +6 -4
- package/dist/src/lib/construct/api-to-eventbridge-target/main.js +1 -1
- package/dist/src/lib/construct/graphql-api-lambda/main.js +1 -1
- package/dist/src/lib/construct/site-with-ecs-backend/main.js +5 -4
- package/dist/src/lib/construct/static-site/main.js +1 -1
- package/dist/src/lib/manager/aws/event-manager.js +2 -0
- package/dist/src/lib/manager/aws/iam-manager.d.ts +13 -0
- package/dist/src/lib/manager/aws/iam-manager.js +32 -0
- package/dist/src/lib/manager/aws/index.d.ts +1 -0
- package/dist/src/lib/manager/aws/index.js +1 -0
- package/dist/src/lib/manager/aws/sfn-manager.d.ts +92 -0
- package/dist/src/lib/manager/aws/sfn-manager.js +198 -0
- package/dist/src/lib/types/aws/index.d.ts +57 -0
- package/package.json +12 -12
- package/src/lib/common/construct.ts +6 -4
- package/src/lib/construct/api-to-eventbridge-target/main.ts +1 -1
- package/src/lib/construct/graphql-api-lambda/main.ts +1 -1
- package/src/lib/construct/site-with-ecs-backend/main.ts +5 -4
- package/src/lib/construct/static-site/main.ts +1 -1
- package/src/lib/manager/aws/event-manager.ts +2 -0
- package/src/lib/manager/aws/iam-manager.ts +45 -0
- package/src/lib/manager/aws/index.ts +1 -0
- package/src/lib/manager/aws/sfn-manager.ts +197 -0
- package/src/lib/types/aws/index.ts +64 -0
|
@@ -40,11 +40,12 @@ export declare class CommonConstruct extends Construct {
|
|
|
40
40
|
route53Manager: aws.Route53Manager;
|
|
41
41
|
s3Manager: aws.S3Manager;
|
|
42
42
|
secretsManager: aws.SecretsManager;
|
|
43
|
+
sfnManager: aws.SfnManager;
|
|
43
44
|
snsManager: aws.SnsManager;
|
|
44
|
-
|
|
45
|
+
sqsManager: aws.SqsManager;
|
|
46
|
+
ssmManager: aws.SsmManager;
|
|
45
47
|
vpcManager: aws.VpcManager;
|
|
46
48
|
wafManager: aws.WafManager;
|
|
47
|
-
sqsManager: aws.SqsManager;
|
|
48
49
|
fullyQualifiedDomainName: string;
|
|
49
50
|
constructor(parent: Construct, id: string, props: types.CommonStackProps);
|
|
50
51
|
/**
|
|
@@ -65,11 +65,12 @@ class CommonConstruct extends constructs_1.Construct {
|
|
|
65
65
|
route53Manager;
|
|
66
66
|
s3Manager;
|
|
67
67
|
secretsManager;
|
|
68
|
+
sfnManager;
|
|
68
69
|
snsManager;
|
|
69
|
-
|
|
70
|
+
sqsManager;
|
|
71
|
+
ssmManager;
|
|
70
72
|
vpcManager;
|
|
71
73
|
wafManager;
|
|
72
|
-
sqsManager;
|
|
73
74
|
fullyQualifiedDomainName;
|
|
74
75
|
constructor(parent, id, props) {
|
|
75
76
|
super(parent, id);
|
|
@@ -94,11 +95,12 @@ class CommonConstruct extends constructs_1.Construct {
|
|
|
94
95
|
this.route53Manager = new aws.Route53Manager();
|
|
95
96
|
this.s3Manager = new aws.S3Manager();
|
|
96
97
|
this.secretsManager = new aws.SecretsManager();
|
|
98
|
+
this.sfnManager = new aws.SfnManager();
|
|
97
99
|
this.snsManager = new aws.SnsManager();
|
|
98
|
-
this.
|
|
100
|
+
this.sqsManager = new aws.SqsManager();
|
|
101
|
+
this.ssmManager = new aws.SsmManager();
|
|
99
102
|
this.vpcManager = new aws.VpcManager();
|
|
100
103
|
this.wafManager = new aws.WafManager();
|
|
101
|
-
this.sqsManager = new aws.SqsManager();
|
|
102
104
|
this.determineFullyQualifiedDomain();
|
|
103
105
|
}
|
|
104
106
|
/**
|
|
@@ -141,7 +141,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
141
141
|
if (this.props.api.certificate.useExistingCertificate &&
|
|
142
142
|
this.props.api.certificate.certificateSsmName &&
|
|
143
143
|
this.props.api.certificate.certificateRegion) {
|
|
144
|
-
this.props.api.certificate.certificateArn = this.
|
|
144
|
+
this.props.api.certificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-param`, this, this.props.api.certificate.certificateSsmName, this.props.api.certificate.certificateRegion);
|
|
145
145
|
}
|
|
146
146
|
this.apiDestinedRestApi.certificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.api.certificate);
|
|
147
147
|
}
|
|
@@ -110,7 +110,7 @@ class GraphQLApiLambda extends common_1.CommonConstruct {
|
|
|
110
110
|
if (this.props.graphQLApiCertificate.useExistingCertificate &&
|
|
111
111
|
this.props.graphQLApiCertificate.certificateSsmName &&
|
|
112
112
|
this.props.graphQLApiCertificate.certificateRegion) {
|
|
113
|
-
this.props.graphQLApiCertificate.certificateArn = this.
|
|
113
|
+
this.props.graphQLApiCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-param`, this, this.props.graphQLApiCertificate.certificateSsmName, this.props.graphQLApiCertificate.certificateRegion);
|
|
114
114
|
}
|
|
115
115
|
this.graphQLApiCertificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.graphQLApiCertificate);
|
|
116
116
|
}
|
|
@@ -127,7 +127,7 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
|
|
|
127
127
|
if (this.props.siteCertificate.useExistingCertificate &&
|
|
128
128
|
this.props.siteCertificate.certificateSsmName &&
|
|
129
129
|
this.props.siteCertificate.certificateRegion) {
|
|
130
|
-
this.props.siteCertificate.certificateArn = this.
|
|
130
|
+
this.props.siteCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-parameter`, this, this.props.siteCertificate.certificateSsmName, this.props.siteCertificate.certificateRegion);
|
|
131
131
|
}
|
|
132
132
|
this.siteCertificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.siteCertificate);
|
|
133
133
|
}
|
|
@@ -147,9 +147,10 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
|
|
|
147
147
|
? `${this.props.siteSubDomain}-internal.${this.fullyQualifiedDomainName}`
|
|
148
148
|
: `${this.props.siteSubDomain}-internal-${this.props.stage}.${this.fullyQualifiedDomainName}`;
|
|
149
149
|
/* the external domain name exposed to CloudFront */
|
|
150
|
-
this.siteExternalDomainName =
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
this.siteExternalDomainName =
|
|
151
|
+
this.isProductionStage() || this.props.skipStageForARecords
|
|
152
|
+
? `${this.props.siteSubDomain}.${this.fullyQualifiedDomainName}`
|
|
153
|
+
: `${this.props.siteSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`;
|
|
153
154
|
this.siteDomainNames = [this.siteExternalDomainName];
|
|
154
155
|
}
|
|
155
156
|
/**
|
|
@@ -98,7 +98,7 @@ class StaticSite extends common_1.CommonConstruct {
|
|
|
98
98
|
if (this.props.siteCertificate.useExistingCertificate &&
|
|
99
99
|
this.props.siteCertificate.certificateSsmName &&
|
|
100
100
|
this.props.siteCertificate.certificateRegion) {
|
|
101
|
-
this.props.siteCertificate.certificateArn = this.
|
|
101
|
+
this.props.siteCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-param`, this, this.props.siteCertificate.certificateSsmName, this.props.siteCertificate.certificateRegion);
|
|
102
102
|
}
|
|
103
103
|
this.siteCertificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.siteCertificate);
|
|
104
104
|
}
|
|
@@ -81,6 +81,8 @@ class EventManager {
|
|
|
81
81
|
description: props.description,
|
|
82
82
|
ruleName: `${props.ruleName}-${scope.props.stage}`,
|
|
83
83
|
eventPattern: props.eventPattern,
|
|
84
|
+
enabled: props.enabled,
|
|
85
|
+
schedule: props.schedule,
|
|
84
86
|
});
|
|
85
87
|
if (targets && targets.length > 0) {
|
|
86
88
|
targets.forEach(target => {
|
|
@@ -36,6 +36,11 @@ export declare class IamManager {
|
|
|
36
36
|
* @summary Method to create iam statement to put events
|
|
37
37
|
*/
|
|
38
38
|
statementForPutEvents(): cdk.aws_iam.PolicyStatement;
|
|
39
|
+
/**
|
|
40
|
+
* @summary Method to create iam statement to invoke lambda function
|
|
41
|
+
* @param {string[]} resourceArns list of ARNs to allow access to
|
|
42
|
+
*/
|
|
43
|
+
statementForInvokeLambda(resourceArns?: string[]): cdk.aws_iam.PolicyStatement;
|
|
39
44
|
/**
|
|
40
45
|
* @summary Method to create iam statement to read app config
|
|
41
46
|
*/
|
|
@@ -153,6 +158,14 @@ export declare class IamManager {
|
|
|
153
158
|
* @param {iam.ServicePrincipal} servicePrinicpal
|
|
154
159
|
*/
|
|
155
160
|
createRoleForLambda(id: string, scope: common.CommonConstruct, policy: iam.PolicyDocument, servicePrinicpal?: iam.ServicePrincipal): cdk.aws_iam.Role;
|
|
161
|
+
/**
|
|
162
|
+
* @summary Method to create iam statement for step function execution
|
|
163
|
+
* @param {string} id scoped id of the resource
|
|
164
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
165
|
+
* @param {iam.PolicyDocument} policy
|
|
166
|
+
* @param {iam.ServicePrincipal} servicePrinicpal
|
|
167
|
+
*/
|
|
168
|
+
createRoleForStepFunction(id: string, scope: common.CommonConstruct, policy: iam.PolicyDocument, servicePrinicpal?: iam.ServicePrincipal): cdk.aws_iam.Role;
|
|
156
169
|
/**
|
|
157
170
|
* @summary Method to create iam policy for sqs
|
|
158
171
|
* @param {string} id scoped id of the resource
|
|
@@ -69,6 +69,17 @@ class IamManager {
|
|
|
69
69
|
resources: ['*'],
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* @summary Method to create iam statement to invoke lambda function
|
|
74
|
+
* @param {string[]} resourceArns list of ARNs to allow access to
|
|
75
|
+
*/
|
|
76
|
+
statementForInvokeLambda(resourceArns) {
|
|
77
|
+
return new iam.PolicyStatement({
|
|
78
|
+
effect: iam.Effect.ALLOW,
|
|
79
|
+
actions: ['lambda:InvokeFunction'],
|
|
80
|
+
resources: resourceArns ?? ['*'],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
72
83
|
/**
|
|
73
84
|
* @summary Method to create iam statement to read app config
|
|
74
85
|
*/
|
|
@@ -380,6 +391,27 @@ class IamManager {
|
|
|
380
391
|
utils.createCfnOutput(`${id}Name`, scope, role.roleName);
|
|
381
392
|
return role;
|
|
382
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* @summary Method to create iam statement for step function execution
|
|
396
|
+
* @param {string} id scoped id of the resource
|
|
397
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
398
|
+
* @param {iam.PolicyDocument} policy
|
|
399
|
+
* @param {iam.ServicePrincipal} servicePrinicpal
|
|
400
|
+
*/
|
|
401
|
+
createRoleForStepFunction(id, scope, policy, servicePrinicpal) {
|
|
402
|
+
const role = new iam.Role(scope, `${id}`, {
|
|
403
|
+
assumedBy: servicePrinicpal ?? new iam.ServicePrincipal('states.amazonaws.com'),
|
|
404
|
+
description: `Role for ${id} Lambda function`,
|
|
405
|
+
inlinePolicies: { policy },
|
|
406
|
+
managedPolicies: [
|
|
407
|
+
iam.ManagedPolicy.fromManagedPolicyArn(scope, `${id}-AWSLambdaBasicExecutionRole`, 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'),
|
|
408
|
+
],
|
|
409
|
+
roleName: `${id}-${scope.props.stage}`,
|
|
410
|
+
});
|
|
411
|
+
utils.createCfnOutput(`${id}Arn`, scope, role.roleArn);
|
|
412
|
+
utils.createCfnOutput(`${id}Name`, scope, role.roleName);
|
|
413
|
+
return role;
|
|
414
|
+
}
|
|
383
415
|
/**
|
|
384
416
|
* @summary Method to create iam policy for sqs
|
|
385
417
|
* @param {string} id scoped id of the resource
|
|
@@ -18,6 +18,7 @@ export * from './log-manager';
|
|
|
18
18
|
export * from './route53-manager';
|
|
19
19
|
export * from './s3-manager';
|
|
20
20
|
export * from './secrets-manager';
|
|
21
|
+
export * from './sfn-manager';
|
|
21
22
|
export * from './sns-manager';
|
|
22
23
|
export * from './sqs-manager';
|
|
23
24
|
export * from './ssm-manager';
|
|
@@ -34,6 +34,7 @@ __exportStar(require("./log-manager"), exports);
|
|
|
34
34
|
__exportStar(require("./route53-manager"), exports);
|
|
35
35
|
__exportStar(require("./s3-manager"), exports);
|
|
36
36
|
__exportStar(require("./secrets-manager"), exports);
|
|
37
|
+
__exportStar(require("./sfn-manager"), exports);
|
|
37
38
|
__exportStar(require("./sns-manager"), exports);
|
|
38
39
|
__exportStar(require("./sqs-manager"), exports);
|
|
39
40
|
__exportStar(require("./ssm-manager"), exports);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as apig from 'aws-cdk-lib/aws-apigateway';
|
|
2
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
3
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
4
|
+
import * as logs from 'aws-cdk-lib/aws-logs';
|
|
5
|
+
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
|
|
6
|
+
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
|
|
7
|
+
import * as common from '../../common';
|
|
8
|
+
import * as types from '../../types';
|
|
9
|
+
import { SfnStateMachineProps } from '../../types';
|
|
10
|
+
/**
|
|
11
|
+
* @stability stable
|
|
12
|
+
* @category cdk-utils.step-functions-manager
|
|
13
|
+
* @subcategory Construct
|
|
14
|
+
* @classdesc Provides operations on AWS Step Functions Service.
|
|
15
|
+
* - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
|
|
16
|
+
* - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
|
|
17
|
+
* @example
|
|
18
|
+
* import * as common from '@gradientedge/cdk-utils'
|
|
19
|
+
*
|
|
20
|
+
* class CustomConstruct extends common.common.CommonConstruct {
|
|
21
|
+
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
22
|
+
* super(parent, id, props)
|
|
23
|
+
* this.props = props
|
|
24
|
+
* this.sfnManager.createSuccessStep('MyStep', this, myStepProps)
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* @see [CDK Step Functions Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions-readme.html}
|
|
29
|
+
*/
|
|
30
|
+
export declare class SfnManager {
|
|
31
|
+
/**
|
|
32
|
+
* @summary Method to create a success step
|
|
33
|
+
* @param {string} id scoped id of the resource
|
|
34
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
35
|
+
* @param {types.SfnSucceedProps} props
|
|
36
|
+
*/
|
|
37
|
+
createSuccessStep(id: string, scope: common.CommonConstruct, props: types.SfnSucceedProps): sfn.Succeed;
|
|
38
|
+
/**
|
|
39
|
+
* @summary Method to create a failure step
|
|
40
|
+
* @param {string} id scoped id of the resource
|
|
41
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
42
|
+
* @param {types.SfnFailProps} props
|
|
43
|
+
*/
|
|
44
|
+
createFailStep(id: string, scope: common.CommonConstruct, props: types.SfnFailProps): sfn.Fail;
|
|
45
|
+
/**
|
|
46
|
+
* @summary Method to create a pass step
|
|
47
|
+
* @param {string} id scoped id of the resource
|
|
48
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
49
|
+
* @param {types.SfnPassProps} props
|
|
50
|
+
*/
|
|
51
|
+
createPassStep(id: string, scope: common.CommonConstruct, props: types.SfnPassProps): sfn.Pass;
|
|
52
|
+
/**
|
|
53
|
+
* @summary Method to create a parallel step
|
|
54
|
+
* @param {string} id scoped id of the resource
|
|
55
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
56
|
+
* @param {types.SfnParallelProps} props
|
|
57
|
+
*/
|
|
58
|
+
createParallelStep(id: string, scope: common.CommonConstruct, props: types.SfnParallelProps): sfn.Parallel;
|
|
59
|
+
/**
|
|
60
|
+
* @summary Method to create a choice step
|
|
61
|
+
* @param {string} id scoped id of the resource
|
|
62
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
63
|
+
* @param {types.SfnChoiceProps} props
|
|
64
|
+
*/
|
|
65
|
+
createChoiceStep(id: string, scope: common.CommonConstruct, props: types.SfnChoiceProps): sfn.Choice;
|
|
66
|
+
/**
|
|
67
|
+
* @summary Method to create a lambda invoke step
|
|
68
|
+
* @param {string} id scoped id of the resource
|
|
69
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
70
|
+
* @param {types.SfnLambdaInvokeProps} props
|
|
71
|
+
* @param {lambda.IFunction} lambdaFunction
|
|
72
|
+
*/
|
|
73
|
+
createLambdaStep(id: string, scope: common.CommonConstruct, props: types.SfnLambdaInvokeProps, lambdaFunction: lambda.IFunction): tasks.LambdaInvoke;
|
|
74
|
+
/**
|
|
75
|
+
* @summary Method to create a API Gateway invoke step
|
|
76
|
+
* @param {string} id scoped id of the resource
|
|
77
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
78
|
+
* @param {types.SfnLambdaInvokeProps} props
|
|
79
|
+
* @param {apig.IRestApi} api
|
|
80
|
+
*/
|
|
81
|
+
createApiStep(id: string, scope: common.CommonConstruct, props: types.SfnCallApiGatewayRestApiEndpointProps, api: apig.IRestApi): tasks.CallApiGatewayRestApiEndpoint;
|
|
82
|
+
/**
|
|
83
|
+
* @summary Method to create a state machine
|
|
84
|
+
* @param {string} id scoped id of the resource
|
|
85
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
86
|
+
* @param {types.SfnStateMachineProps} props
|
|
87
|
+
* @param {sfn.IChainable} definition
|
|
88
|
+
* @param {logs.ILogGroup} logGroup
|
|
89
|
+
* @param {iam.IRole} role
|
|
90
|
+
*/
|
|
91
|
+
createStateMachine(id: string, scope: common.CommonConstruct, props: SfnStateMachineProps, definition: sfn.IChainable, logGroup: logs.ILogGroup, role?: iam.IRole): sfn.StateMachine;
|
|
92
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.SfnManager = void 0;
|
|
27
|
+
const sfn = __importStar(require("aws-cdk-lib/aws-stepfunctions"));
|
|
28
|
+
const tasks = __importStar(require("aws-cdk-lib/aws-stepfunctions-tasks"));
|
|
29
|
+
const utils = __importStar(require("../../utils"));
|
|
30
|
+
/**
|
|
31
|
+
* @stability stable
|
|
32
|
+
* @category cdk-utils.step-functions-manager
|
|
33
|
+
* @subcategory Construct
|
|
34
|
+
* @classdesc Provides operations on AWS Step Functions Service.
|
|
35
|
+
* - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
|
|
36
|
+
* - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
|
|
37
|
+
* @example
|
|
38
|
+
* import * as common from '@gradientedge/cdk-utils'
|
|
39
|
+
*
|
|
40
|
+
* class CustomConstruct extends common.common.CommonConstruct {
|
|
41
|
+
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
42
|
+
* super(parent, id, props)
|
|
43
|
+
* this.props = props
|
|
44
|
+
* this.sfnManager.createSuccessStep('MyStep', this, myStepProps)
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* @see [CDK Step Functions Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions-readme.html}
|
|
49
|
+
*/
|
|
50
|
+
class SfnManager {
|
|
51
|
+
/**
|
|
52
|
+
* @summary Method to create a success step
|
|
53
|
+
* @param {string} id scoped id of the resource
|
|
54
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
55
|
+
* @param {types.SfnSucceedProps} props
|
|
56
|
+
*/
|
|
57
|
+
createSuccessStep(id, scope, props) {
|
|
58
|
+
if (!props)
|
|
59
|
+
throw 'Step props undefined';
|
|
60
|
+
return new sfn.Succeed(scope, `${props.name}`, {
|
|
61
|
+
...props,
|
|
62
|
+
...{
|
|
63
|
+
comment: `Succeed step for ${props.name} - ${scope.props.stage} stage`,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @summary Method to create a failure step
|
|
69
|
+
* @param {string} id scoped id of the resource
|
|
70
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
71
|
+
* @param {types.SfnFailProps} props
|
|
72
|
+
*/
|
|
73
|
+
createFailStep(id, scope, props) {
|
|
74
|
+
if (!props)
|
|
75
|
+
throw 'Step props undefined';
|
|
76
|
+
return new sfn.Fail(scope, `${props.name}`, {
|
|
77
|
+
...props,
|
|
78
|
+
...{
|
|
79
|
+
comment: `Fail step for ${props.name} - ${scope.props.stage} stage`,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @summary Method to create a pass step
|
|
85
|
+
* @param {string} id scoped id of the resource
|
|
86
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
87
|
+
* @param {types.SfnPassProps} props
|
|
88
|
+
*/
|
|
89
|
+
createPassStep(id, scope, props) {
|
|
90
|
+
if (!props)
|
|
91
|
+
throw 'Step props undefined';
|
|
92
|
+
return new sfn.Pass(scope, `${props.name}`, {
|
|
93
|
+
...props,
|
|
94
|
+
...{
|
|
95
|
+
comment: `Pass step for ${props.name} - ${scope.props.stage} stage`,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @summary Method to create a parallel step
|
|
101
|
+
* @param {string} id scoped id of the resource
|
|
102
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
103
|
+
* @param {types.SfnParallelProps} props
|
|
104
|
+
*/
|
|
105
|
+
createParallelStep(id, scope, props) {
|
|
106
|
+
if (!props)
|
|
107
|
+
throw 'Step props undefined';
|
|
108
|
+
return new sfn.Parallel(scope, `${props.name}`, {
|
|
109
|
+
...props,
|
|
110
|
+
...{
|
|
111
|
+
comment: `Parallel step for ${props.name} - ${scope.props.stage} stage`,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @summary Method to create a choice step
|
|
117
|
+
* @param {string} id scoped id of the resource
|
|
118
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
119
|
+
* @param {types.SfnChoiceProps} props
|
|
120
|
+
*/
|
|
121
|
+
createChoiceStep(id, scope, props) {
|
|
122
|
+
if (!props)
|
|
123
|
+
throw 'Step props undefined';
|
|
124
|
+
return new sfn.Choice(scope, `${props.name}`, {
|
|
125
|
+
...props,
|
|
126
|
+
...{
|
|
127
|
+
comment: `Choice step for ${props.name} - ${scope.props.stage} stage`,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @summary Method to create a lambda invoke step
|
|
133
|
+
* @param {string} id scoped id of the resource
|
|
134
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
135
|
+
* @param {types.SfnLambdaInvokeProps} props
|
|
136
|
+
* @param {lambda.IFunction} lambdaFunction
|
|
137
|
+
*/
|
|
138
|
+
createLambdaStep(id, scope, props, lambdaFunction) {
|
|
139
|
+
if (!props)
|
|
140
|
+
throw 'Step props undefined';
|
|
141
|
+
return new tasks.LambdaInvoke(scope, `${props.name}`, {
|
|
142
|
+
...props,
|
|
143
|
+
...{
|
|
144
|
+
lambdaFunction,
|
|
145
|
+
comment: `Lambda step for ${props.name} - ${scope.props.stage} stage`,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* @summary Method to create a API Gateway invoke step
|
|
151
|
+
* @param {string} id scoped id of the resource
|
|
152
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
153
|
+
* @param {types.SfnLambdaInvokeProps} props
|
|
154
|
+
* @param {apig.IRestApi} api
|
|
155
|
+
*/
|
|
156
|
+
createApiStep(id, scope, props, api) {
|
|
157
|
+
if (!props)
|
|
158
|
+
throw 'Step props undefined';
|
|
159
|
+
return new tasks.CallApiGatewayRestApiEndpoint(scope, `${props.name}`, {
|
|
160
|
+
...props,
|
|
161
|
+
...{
|
|
162
|
+
api,
|
|
163
|
+
stageName: scope.props.stage,
|
|
164
|
+
comment: `API step for ${props.name} - ${scope.props.stage} stage`,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @summary Method to create a state machine
|
|
170
|
+
* @param {string} id scoped id of the resource
|
|
171
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
172
|
+
* @param {types.SfnStateMachineProps} props
|
|
173
|
+
* @param {sfn.IChainable} definition
|
|
174
|
+
* @param {logs.ILogGroup} logGroup
|
|
175
|
+
* @param {iam.IRole} role
|
|
176
|
+
*/
|
|
177
|
+
createStateMachine(id, scope, props, definition, logGroup, role) {
|
|
178
|
+
if (!props)
|
|
179
|
+
throw 'State Machine props undefined';
|
|
180
|
+
const stateMachine = new sfn.StateMachine(scope, `${id}`, {
|
|
181
|
+
stateMachineName: `${props.stateMachineName}-${scope.props.stage}`,
|
|
182
|
+
definition,
|
|
183
|
+
role,
|
|
184
|
+
stateMachineType: props.stateMachineType,
|
|
185
|
+
logs: {
|
|
186
|
+
destination: logGroup,
|
|
187
|
+
includeExecutionData: props.logs?.includeExecutionData ?? true,
|
|
188
|
+
level: props.logs?.level ?? sfn.LogLevel.ALL,
|
|
189
|
+
},
|
|
190
|
+
tracingEnabled: props.tracingEnabled,
|
|
191
|
+
timeout: props.timeout,
|
|
192
|
+
});
|
|
193
|
+
utils.createCfnOutput(`${id}-stateMachineName`, scope, stateMachine.stateMachineName);
|
|
194
|
+
utils.createCfnOutput(`${id}-stateMachineArn`, scope, stateMachine.stateMachineArn);
|
|
195
|
+
return stateMachine;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.SfnManager = SfnManager;
|
|
@@ -23,6 +23,8 @@ import * as s3 from 'aws-cdk-lib/aws-s3';
|
|
|
23
23
|
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
|
|
24
24
|
import * as sns from 'aws-cdk-lib/aws-sns';
|
|
25
25
|
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
26
|
+
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
|
|
27
|
+
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
|
|
26
28
|
import * as wafv2 from 'aws-cdk-lib/aws-wafv2';
|
|
27
29
|
import * as types from '../index';
|
|
28
30
|
/**
|
|
@@ -111,6 +113,61 @@ export interface HealthCheck extends elb.HealthCheck {
|
|
|
111
113
|
*/
|
|
112
114
|
export interface KmsKeyProps extends kms.KeyProps {
|
|
113
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* @category cdk-utils.step-functions-manager
|
|
118
|
+
* @subcategory Properties
|
|
119
|
+
*/
|
|
120
|
+
export interface SfnSucceedProps extends sfn.SucceedProps {
|
|
121
|
+
name: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @category cdk-utils.step-functions-manager
|
|
125
|
+
* @subcategory Properties
|
|
126
|
+
*/
|
|
127
|
+
export interface SfnFailProps extends sfn.FailProps {
|
|
128
|
+
name: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @category cdk-utils.step-functions-manager
|
|
132
|
+
* @subcategory Properties
|
|
133
|
+
*/
|
|
134
|
+
export interface SfnPassProps extends sfn.PassProps {
|
|
135
|
+
name: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @category cdk-utils.step-functions-manager
|
|
139
|
+
* @subcategory Properties
|
|
140
|
+
*/
|
|
141
|
+
export interface SfnParallelProps extends sfn.ParallelProps {
|
|
142
|
+
name: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @category cdk-utils.step-functions-manager
|
|
146
|
+
* @subcategory Properties
|
|
147
|
+
*/
|
|
148
|
+
export interface SfnChoiceProps extends sfn.ChoiceProps {
|
|
149
|
+
name: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @category cdk-utils.step-functions-manager
|
|
153
|
+
* @subcategory Properties
|
|
154
|
+
*/
|
|
155
|
+
export interface SfnLambdaInvokeProps extends tasks.LambdaInvokeProps {
|
|
156
|
+
name: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @category cdk-utils.step-functions-manager
|
|
160
|
+
* @subcategory Properties
|
|
161
|
+
*/
|
|
162
|
+
export interface SfnCallApiGatewayRestApiEndpointProps extends tasks.CallApiGatewayRestApiEndpointProps {
|
|
163
|
+
name: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @category cdk-utils.step-functions-manager
|
|
167
|
+
* @subcategory Properties
|
|
168
|
+
*/
|
|
169
|
+
export interface SfnStateMachineProps extends sfn.StateMachineProps {
|
|
170
|
+
}
|
|
114
171
|
/**
|
|
115
172
|
* @category cdk-utils.lambda-manager
|
|
116
173
|
* @subcategory Types
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -45,31 +45,31 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@aws-cdk/aws-lambda-python-alpha": "2.
|
|
49
|
-
"@types/lodash": "^4.14.
|
|
48
|
+
"@aws-cdk/aws-lambda-python-alpha": "2.16.0-alpha.0",
|
|
49
|
+
"@types/lodash": "^4.14.180",
|
|
50
50
|
"@types/node": "^17.0.21",
|
|
51
51
|
"app-root-path": "^3.0.0",
|
|
52
|
-
"aws-cdk-lib": "^2.
|
|
53
|
-
"aws-sdk": "^2.
|
|
54
|
-
"constructs": "^10.0.
|
|
52
|
+
"aws-cdk-lib": "^2.16.0",
|
|
53
|
+
"aws-sdk": "^2.1093.0",
|
|
54
|
+
"constructs": "^10.0.88",
|
|
55
55
|
"lodash": "^4.17.21",
|
|
56
56
|
"moment": "^2.29.1",
|
|
57
57
|
"nconf": "^0.11.3",
|
|
58
58
|
"pluralize": "^8.0.0",
|
|
59
|
-
"ts-node": "^10.
|
|
59
|
+
"ts-node": "^10.7.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
63
63
|
"@types/jest": "^27.4.1",
|
|
64
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
65
|
-
"@typescript-eslint/parser": "^5.
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
|
65
|
+
"@typescript-eslint/parser": "^5.15.0",
|
|
66
66
|
"aws-cdk": "*",
|
|
67
67
|
"babel-eslint": "^10.1.0",
|
|
68
68
|
"better-docs": "^2.7.2",
|
|
69
69
|
"codecov": "^3.8.3",
|
|
70
70
|
"commitizen": "^4.2.4",
|
|
71
71
|
"dotenv": "^16.0.0",
|
|
72
|
-
"eslint": "^8.
|
|
72
|
+
"eslint": "^8.11.0",
|
|
73
73
|
"eslint-config-prettier": "^8.5.0",
|
|
74
74
|
"eslint-plugin-import": "^2.25.4",
|
|
75
75
|
"husky": "^7.0.4",
|
|
@@ -85,11 +85,11 @@
|
|
|
85
85
|
"rimraf": "^3.0.2",
|
|
86
86
|
"semantic-release": "^19.0.2",
|
|
87
87
|
"ts-jest": "^27.1.3",
|
|
88
|
-
"ts-node": "^10.
|
|
88
|
+
"ts-node": "^10.7.0",
|
|
89
89
|
"typescript": "4.6.2"
|
|
90
90
|
},
|
|
91
91
|
"optionalDependencies": {
|
|
92
|
-
"@babel/core": "^7.17.
|
|
92
|
+
"@babel/core": "^7.17.7",
|
|
93
93
|
"prop-types": "^15.8.1",
|
|
94
94
|
"react": "^17.0.2",
|
|
95
95
|
"react-dom": "^17.0.2"
|
|
@@ -42,11 +42,12 @@ export class CommonConstruct extends Construct {
|
|
|
42
42
|
route53Manager: aws.Route53Manager
|
|
43
43
|
s3Manager: aws.S3Manager
|
|
44
44
|
secretsManager: aws.SecretsManager
|
|
45
|
+
sfnManager: aws.SfnManager
|
|
45
46
|
snsManager: aws.SnsManager
|
|
46
|
-
|
|
47
|
+
sqsManager: aws.SqsManager
|
|
48
|
+
ssmManager: aws.SsmManager
|
|
47
49
|
vpcManager: aws.VpcManager
|
|
48
50
|
wafManager: aws.WafManager
|
|
49
|
-
sqsManager: aws.SqsManager
|
|
50
51
|
|
|
51
52
|
fullyQualifiedDomainName: string
|
|
52
53
|
|
|
@@ -73,11 +74,12 @@ export class CommonConstruct extends Construct {
|
|
|
73
74
|
this.route53Manager = new aws.Route53Manager()
|
|
74
75
|
this.s3Manager = new aws.S3Manager()
|
|
75
76
|
this.secretsManager = new aws.SecretsManager()
|
|
77
|
+
this.sfnManager = new aws.SfnManager()
|
|
76
78
|
this.snsManager = new aws.SnsManager()
|
|
77
|
-
this.
|
|
79
|
+
this.sqsManager = new aws.SqsManager()
|
|
80
|
+
this.ssmManager = new aws.SsmManager()
|
|
78
81
|
this.vpcManager = new aws.VpcManager()
|
|
79
82
|
this.wafManager = new aws.WafManager()
|
|
80
|
-
this.sqsManager = new aws.SqsManager()
|
|
81
83
|
|
|
82
84
|
this.determineFullyQualifiedDomain()
|
|
83
85
|
}
|
|
@@ -141,7 +141,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
141
141
|
this.props.api.certificate.certificateSsmName &&
|
|
142
142
|
this.props.api.certificate.certificateRegion
|
|
143
143
|
) {
|
|
144
|
-
this.props.api.certificate.certificateArn = this.
|
|
144
|
+
this.props.api.certificate.certificateArn = this.ssmManager.readStringParameterFromRegion(
|
|
145
145
|
`${this.id}-certificate-param`,
|
|
146
146
|
this,
|
|
147
147
|
this.props.api.certificate.certificateSsmName,
|
|
@@ -104,7 +104,7 @@ export class GraphQLApiLambda extends CommonConstruct {
|
|
|
104
104
|
this.props.graphQLApiCertificate.certificateSsmName &&
|
|
105
105
|
this.props.graphQLApiCertificate.certificateRegion
|
|
106
106
|
) {
|
|
107
|
-
this.props.graphQLApiCertificate.certificateArn = this.
|
|
107
|
+
this.props.graphQLApiCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(
|
|
108
108
|
`${this.id}-certificate-param`,
|
|
109
109
|
this,
|
|
110
110
|
this.props.graphQLApiCertificate.certificateSsmName,
|
|
@@ -123,7 +123,7 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
123
123
|
this.props.siteCertificate.certificateSsmName &&
|
|
124
124
|
this.props.siteCertificate.certificateRegion
|
|
125
125
|
) {
|
|
126
|
-
this.props.siteCertificate.certificateArn = this.
|
|
126
|
+
this.props.siteCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(
|
|
127
127
|
`${this.id}-certificate-parameter`,
|
|
128
128
|
this,
|
|
129
129
|
this.props.siteCertificate.certificateSsmName,
|
|
@@ -155,9 +155,10 @@ export class SiteWithEcsBackend extends CommonConstruct {
|
|
|
155
155
|
: `${this.props.siteSubDomain}-internal-${this.props.stage}.${this.fullyQualifiedDomainName}`
|
|
156
156
|
|
|
157
157
|
/* the external domain name exposed to CloudFront */
|
|
158
|
-
this.siteExternalDomainName =
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
this.siteExternalDomainName =
|
|
159
|
+
this.isProductionStage() || this.props.skipStageForARecords
|
|
160
|
+
? `${this.props.siteSubDomain}.${this.fullyQualifiedDomainName}`
|
|
161
|
+
: `${this.props.siteSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`
|
|
161
162
|
|
|
162
163
|
this.siteDomainNames = [this.siteExternalDomainName]
|
|
163
164
|
}
|
|
@@ -90,7 +90,7 @@ export class StaticSite extends CommonConstruct {
|
|
|
90
90
|
this.props.siteCertificate.certificateSsmName &&
|
|
91
91
|
this.props.siteCertificate.certificateRegion
|
|
92
92
|
) {
|
|
93
|
-
this.props.siteCertificate.certificateArn = this.
|
|
93
|
+
this.props.siteCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(
|
|
94
94
|
`${this.id}-certificate-param`,
|
|
95
95
|
this,
|
|
96
96
|
this.props.siteCertificate.certificateSsmName,
|
|
@@ -52,6 +52,18 @@ export class IamManager {
|
|
|
52
52
|
})
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @summary Method to create iam statement to invoke lambda function
|
|
57
|
+
* @param {string[]} resourceArns list of ARNs to allow access to
|
|
58
|
+
*/
|
|
59
|
+
public statementForInvokeLambda(resourceArns?: string[]) {
|
|
60
|
+
return new iam.PolicyStatement({
|
|
61
|
+
effect: iam.Effect.ALLOW,
|
|
62
|
+
actions: ['lambda:InvokeFunction'],
|
|
63
|
+
resources: resourceArns ?? ['*'],
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
/**
|
|
56
68
|
* @summary Method to create iam statement to read app config
|
|
57
69
|
*/
|
|
@@ -415,6 +427,39 @@ export class IamManager {
|
|
|
415
427
|
return role
|
|
416
428
|
}
|
|
417
429
|
|
|
430
|
+
/**
|
|
431
|
+
* @summary Method to create iam statement for step function execution
|
|
432
|
+
* @param {string} id scoped id of the resource
|
|
433
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
434
|
+
* @param {iam.PolicyDocument} policy
|
|
435
|
+
* @param {iam.ServicePrincipal} servicePrinicpal
|
|
436
|
+
*/
|
|
437
|
+
public createRoleForStepFunction(
|
|
438
|
+
id: string,
|
|
439
|
+
scope: common.CommonConstruct,
|
|
440
|
+
policy: iam.PolicyDocument,
|
|
441
|
+
servicePrinicpal?: iam.ServicePrincipal
|
|
442
|
+
) {
|
|
443
|
+
const role = new iam.Role(scope, `${id}`, {
|
|
444
|
+
assumedBy: servicePrinicpal ?? new iam.ServicePrincipal('states.amazonaws.com'),
|
|
445
|
+
description: `Role for ${id} Lambda function`,
|
|
446
|
+
inlinePolicies: { policy },
|
|
447
|
+
managedPolicies: [
|
|
448
|
+
iam.ManagedPolicy.fromManagedPolicyArn(
|
|
449
|
+
scope,
|
|
450
|
+
`${id}-AWSLambdaBasicExecutionRole`,
|
|
451
|
+
'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
|
|
452
|
+
),
|
|
453
|
+
],
|
|
454
|
+
roleName: `${id}-${scope.props.stage}`,
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
utils.createCfnOutput(`${id}Arn`, scope, role.roleArn)
|
|
458
|
+
utils.createCfnOutput(`${id}Name`, scope, role.roleName)
|
|
459
|
+
|
|
460
|
+
return role
|
|
461
|
+
}
|
|
462
|
+
|
|
418
463
|
/**
|
|
419
464
|
* @summary Method to create iam policy for sqs
|
|
420
465
|
* @param {string} id scoped id of the resource
|
|
@@ -18,6 +18,7 @@ export * from './log-manager'
|
|
|
18
18
|
export * from './route53-manager'
|
|
19
19
|
export * from './s3-manager'
|
|
20
20
|
export * from './secrets-manager'
|
|
21
|
+
export * from './sfn-manager'
|
|
21
22
|
export * from './sns-manager'
|
|
22
23
|
export * from './sqs-manager'
|
|
23
24
|
export * from './ssm-manager'
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import * as apig from 'aws-cdk-lib/aws-apigateway'
|
|
2
|
+
import * as iam from 'aws-cdk-lib/aws-iam'
|
|
3
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda'
|
|
4
|
+
import * as logs from 'aws-cdk-lib/aws-logs'
|
|
5
|
+
import * as sfn from 'aws-cdk-lib/aws-stepfunctions'
|
|
6
|
+
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks'
|
|
7
|
+
import * as common from '../../common'
|
|
8
|
+
import * as types from '../../types'
|
|
9
|
+
import { SfnStateMachineProps } from '../../types'
|
|
10
|
+
import * as utils from '../../utils'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @stability stable
|
|
14
|
+
* @category cdk-utils.step-functions-manager
|
|
15
|
+
* @subcategory Construct
|
|
16
|
+
* @classdesc Provides operations on AWS Step Functions Service.
|
|
17
|
+
* - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
|
|
18
|
+
* - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
|
|
19
|
+
* @example
|
|
20
|
+
* import * as common from '@gradientedge/cdk-utils'
|
|
21
|
+
*
|
|
22
|
+
* class CustomConstruct extends common.common.CommonConstruct {
|
|
23
|
+
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
24
|
+
* super(parent, id, props)
|
|
25
|
+
* this.props = props
|
|
26
|
+
* this.sfnManager.createSuccessStep('MyStep', this, myStepProps)
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @see [CDK Step Functions Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions-readme.html}
|
|
31
|
+
*/
|
|
32
|
+
export class SfnManager {
|
|
33
|
+
/**
|
|
34
|
+
* @summary Method to create a success step
|
|
35
|
+
* @param {string} id scoped id of the resource
|
|
36
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
37
|
+
* @param {types.SfnSucceedProps} props
|
|
38
|
+
*/
|
|
39
|
+
public createSuccessStep(id: string, scope: common.CommonConstruct, props: types.SfnSucceedProps) {
|
|
40
|
+
if (!props) throw 'Step props undefined'
|
|
41
|
+
return new sfn.Succeed(scope, `${props.name}`, {
|
|
42
|
+
...props,
|
|
43
|
+
...{
|
|
44
|
+
comment: `Succeed step for ${props.name} - ${scope.props.stage} stage`,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @summary Method to create a failure step
|
|
51
|
+
* @param {string} id scoped id of the resource
|
|
52
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
53
|
+
* @param {types.SfnFailProps} props
|
|
54
|
+
*/
|
|
55
|
+
public createFailStep(id: string, scope: common.CommonConstruct, props: types.SfnFailProps) {
|
|
56
|
+
if (!props) throw 'Step props undefined'
|
|
57
|
+
return new sfn.Fail(scope, `${props.name}`, {
|
|
58
|
+
...props,
|
|
59
|
+
...{
|
|
60
|
+
comment: `Fail step for ${props.name} - ${scope.props.stage} stage`,
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @summary Method to create a pass step
|
|
67
|
+
* @param {string} id scoped id of the resource
|
|
68
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
69
|
+
* @param {types.SfnPassProps} props
|
|
70
|
+
*/
|
|
71
|
+
public createPassStep(id: string, scope: common.CommonConstruct, props: types.SfnPassProps) {
|
|
72
|
+
if (!props) throw 'Step props undefined'
|
|
73
|
+
return new sfn.Pass(scope, `${props.name}`, {
|
|
74
|
+
...props,
|
|
75
|
+
...{
|
|
76
|
+
comment: `Pass step for ${props.name} - ${scope.props.stage} stage`,
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @summary Method to create a parallel step
|
|
83
|
+
* @param {string} id scoped id of the resource
|
|
84
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
85
|
+
* @param {types.SfnParallelProps} props
|
|
86
|
+
*/
|
|
87
|
+
public createParallelStep(id: string, scope: common.CommonConstruct, props: types.SfnParallelProps) {
|
|
88
|
+
if (!props) throw 'Step props undefined'
|
|
89
|
+
return new sfn.Parallel(scope, `${props.name}`, {
|
|
90
|
+
...props,
|
|
91
|
+
...{
|
|
92
|
+
comment: `Parallel step for ${props.name} - ${scope.props.stage} stage`,
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @summary Method to create a choice step
|
|
99
|
+
* @param {string} id scoped id of the resource
|
|
100
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
101
|
+
* @param {types.SfnChoiceProps} props
|
|
102
|
+
*/
|
|
103
|
+
public createChoiceStep(id: string, scope: common.CommonConstruct, props: types.SfnChoiceProps) {
|
|
104
|
+
if (!props) throw 'Step props undefined'
|
|
105
|
+
return new sfn.Choice(scope, `${props.name}`, {
|
|
106
|
+
...props,
|
|
107
|
+
...{
|
|
108
|
+
comment: `Choice step for ${props.name} - ${scope.props.stage} stage`,
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @summary Method to create a lambda invoke step
|
|
115
|
+
* @param {string} id scoped id of the resource
|
|
116
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
117
|
+
* @param {types.SfnLambdaInvokeProps} props
|
|
118
|
+
* @param {lambda.IFunction} lambdaFunction
|
|
119
|
+
*/
|
|
120
|
+
public createLambdaStep(
|
|
121
|
+
id: string,
|
|
122
|
+
scope: common.CommonConstruct,
|
|
123
|
+
props: types.SfnLambdaInvokeProps,
|
|
124
|
+
lambdaFunction: lambda.IFunction
|
|
125
|
+
) {
|
|
126
|
+
if (!props) throw 'Step props undefined'
|
|
127
|
+
return new tasks.LambdaInvoke(scope, `${props.name}`, {
|
|
128
|
+
...props,
|
|
129
|
+
...{
|
|
130
|
+
lambdaFunction,
|
|
131
|
+
comment: `Lambda step for ${props.name} - ${scope.props.stage} stage`,
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @summary Method to create a API Gateway invoke step
|
|
138
|
+
* @param {string} id scoped id of the resource
|
|
139
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
140
|
+
* @param {types.SfnLambdaInvokeProps} props
|
|
141
|
+
* @param {apig.IRestApi} api
|
|
142
|
+
*/
|
|
143
|
+
public createApiStep(
|
|
144
|
+
id: string,
|
|
145
|
+
scope: common.CommonConstruct,
|
|
146
|
+
props: types.SfnCallApiGatewayRestApiEndpointProps,
|
|
147
|
+
api: apig.IRestApi
|
|
148
|
+
) {
|
|
149
|
+
if (!props) throw 'Step props undefined'
|
|
150
|
+
return new tasks.CallApiGatewayRestApiEndpoint(scope, `${props.name}`, {
|
|
151
|
+
...props,
|
|
152
|
+
...{
|
|
153
|
+
api,
|
|
154
|
+
stageName: scope.props.stage,
|
|
155
|
+
comment: `API step for ${props.name} - ${scope.props.stage} stage`,
|
|
156
|
+
},
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @summary Method to create a state machine
|
|
162
|
+
* @param {string} id scoped id of the resource
|
|
163
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
164
|
+
* @param {types.SfnStateMachineProps} props
|
|
165
|
+
* @param {sfn.IChainable} definition
|
|
166
|
+
* @param {logs.ILogGroup} logGroup
|
|
167
|
+
* @param {iam.IRole} role
|
|
168
|
+
*/
|
|
169
|
+
public createStateMachine(
|
|
170
|
+
id: string,
|
|
171
|
+
scope: common.CommonConstruct,
|
|
172
|
+
props: SfnStateMachineProps,
|
|
173
|
+
definition: sfn.IChainable,
|
|
174
|
+
logGroup: logs.ILogGroup,
|
|
175
|
+
role?: iam.IRole
|
|
176
|
+
) {
|
|
177
|
+
if (!props) throw 'State Machine props undefined'
|
|
178
|
+
const stateMachine = new sfn.StateMachine(scope, `${id}`, {
|
|
179
|
+
stateMachineName: `${props.stateMachineName}-${scope.props.stage}`,
|
|
180
|
+
definition,
|
|
181
|
+
role,
|
|
182
|
+
stateMachineType: props.stateMachineType,
|
|
183
|
+
logs: {
|
|
184
|
+
destination: logGroup,
|
|
185
|
+
includeExecutionData: props.logs?.includeExecutionData ?? true,
|
|
186
|
+
level: props.logs?.level ?? sfn.LogLevel.ALL,
|
|
187
|
+
},
|
|
188
|
+
tracingEnabled: props.tracingEnabled,
|
|
189
|
+
timeout: props.timeout,
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
utils.createCfnOutput(`${id}-stateMachineName`, scope, stateMachine.stateMachineName)
|
|
193
|
+
utils.createCfnOutput(`${id}-stateMachineArn`, scope, stateMachine.stateMachineArn)
|
|
194
|
+
|
|
195
|
+
return stateMachine
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -23,6 +23,8 @@ import * as s3 from 'aws-cdk-lib/aws-s3'
|
|
|
23
23
|
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment'
|
|
24
24
|
import * as sns from 'aws-cdk-lib/aws-sns'
|
|
25
25
|
import * as sqs from 'aws-cdk-lib/aws-sqs'
|
|
26
|
+
import * as sfn from 'aws-cdk-lib/aws-stepfunctions'
|
|
27
|
+
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks'
|
|
26
28
|
import * as wafv2 from 'aws-cdk-lib/aws-wafv2'
|
|
27
29
|
import * as types from '../index'
|
|
28
30
|
|
|
@@ -117,6 +119,68 @@ export interface HealthCheck extends elb.HealthCheck {
|
|
|
117
119
|
*/
|
|
118
120
|
export interface KmsKeyProps extends kms.KeyProps {}
|
|
119
121
|
|
|
122
|
+
/**
|
|
123
|
+
* @category cdk-utils.step-functions-manager
|
|
124
|
+
* @subcategory Properties
|
|
125
|
+
*/
|
|
126
|
+
export interface SfnSucceedProps extends sfn.SucceedProps {
|
|
127
|
+
name: string
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @category cdk-utils.step-functions-manager
|
|
132
|
+
* @subcategory Properties
|
|
133
|
+
*/
|
|
134
|
+
export interface SfnFailProps extends sfn.FailProps {
|
|
135
|
+
name: string
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @category cdk-utils.step-functions-manager
|
|
140
|
+
* @subcategory Properties
|
|
141
|
+
*/
|
|
142
|
+
export interface SfnPassProps extends sfn.PassProps {
|
|
143
|
+
name: string
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @category cdk-utils.step-functions-manager
|
|
148
|
+
* @subcategory Properties
|
|
149
|
+
*/
|
|
150
|
+
export interface SfnParallelProps extends sfn.ParallelProps {
|
|
151
|
+
name: string
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @category cdk-utils.step-functions-manager
|
|
156
|
+
* @subcategory Properties
|
|
157
|
+
*/
|
|
158
|
+
export interface SfnChoiceProps extends sfn.ChoiceProps {
|
|
159
|
+
name: string
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @category cdk-utils.step-functions-manager
|
|
164
|
+
* @subcategory Properties
|
|
165
|
+
*/
|
|
166
|
+
export interface SfnLambdaInvokeProps extends tasks.LambdaInvokeProps {
|
|
167
|
+
name: string
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @category cdk-utils.step-functions-manager
|
|
172
|
+
* @subcategory Properties
|
|
173
|
+
*/
|
|
174
|
+
export interface SfnCallApiGatewayRestApiEndpointProps extends tasks.CallApiGatewayRestApiEndpointProps {
|
|
175
|
+
name: string
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @category cdk-utils.step-functions-manager
|
|
180
|
+
* @subcategory Properties
|
|
181
|
+
*/
|
|
182
|
+
export interface SfnStateMachineProps extends sfn.StateMachineProps {}
|
|
183
|
+
|
|
120
184
|
/**
|
|
121
185
|
* @category cdk-utils.lambda-manager
|
|
122
186
|
* @subcategory Types
|