@gradientedge/cdk-utils 4.10.1 → 4.11.2
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 +1 -0
- package/dist/src/lib/common/construct.js +2 -0
- package/dist/src/lib/common/stack.d.ts +1 -0
- package/dist/src/lib/common/stack.js +1 -0
- 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 +1 -1
- package/dist/src/lib/construct/static-site/main.js +1 -4
- package/dist/src/lib/manager/aws/event-manager.js +1 -1
- package/dist/src/lib/manager/aws/iam-manager.d.ts +9 -0
- package/dist/src/lib/manager/aws/iam-manager.js +24 -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/route53-manager.d.ts +4 -2
- package/dist/src/lib/manager/aws/route53-manager.js +9 -4
- package/dist/src/lib/manager/aws/sqs-manager.d.ts +34 -0
- package/dist/src/lib/manager/aws/sqs-manager.js +84 -0
- package/dist/src/lib/types/aws/index.d.ts +13 -0
- package/package.json +1 -1
- package/src/lib/common/construct.ts +3 -0
- package/src/lib/common/stack.ts +1 -0
- package/src/lib/construct/api-to-eventbridge-target/main.ts +2 -1
- package/src/lib/construct/graphql-api-lambda/main.ts +2 -1
- package/src/lib/construct/site-with-ecs-backend/main.ts +2 -1
- package/src/lib/construct/static-site/main.ts +2 -11
- package/src/lib/manager/aws/event-manager.ts +2 -1
- package/src/lib/manager/aws/iam-manager.ts +34 -0
- package/src/lib/manager/aws/index.ts +1 -0
- package/src/lib/manager/aws/route53-manager.ts +12 -4
- package/src/lib/manager/aws/sqs-manager.ts +67 -0
- package/src/lib/types/aws/index.ts +16 -1
|
@@ -44,6 +44,7 @@ export declare class CommonConstruct extends Construct {
|
|
|
44
44
|
ssMManager: aws.SsmManager;
|
|
45
45
|
vpcManager: aws.VpcManager;
|
|
46
46
|
wafManager: aws.WafManager;
|
|
47
|
+
sqsManager: aws.SqsManager;
|
|
47
48
|
fullyQualifiedDomainName: string;
|
|
48
49
|
constructor(parent: Construct, id: string, props: types.CommonStackProps);
|
|
49
50
|
/**
|
|
@@ -69,6 +69,7 @@ class CommonConstruct extends constructs_1.Construct {
|
|
|
69
69
|
ssMManager;
|
|
70
70
|
vpcManager;
|
|
71
71
|
wafManager;
|
|
72
|
+
sqsManager;
|
|
72
73
|
fullyQualifiedDomainName;
|
|
73
74
|
constructor(parent, id, props) {
|
|
74
75
|
super(parent, id);
|
|
@@ -97,6 +98,7 @@ class CommonConstruct extends constructs_1.Construct {
|
|
|
97
98
|
this.ssMManager = new aws.SsmManager();
|
|
98
99
|
this.vpcManager = new aws.VpcManager();
|
|
99
100
|
this.wafManager = new aws.WafManager();
|
|
101
|
+
this.sqsManager = new aws.SqsManager();
|
|
100
102
|
this.determineFullyQualifiedDomain();
|
|
101
103
|
}
|
|
102
104
|
/**
|
|
@@ -72,6 +72,7 @@ class CommonStack extends cdk.Stack {
|
|
|
72
72
|
domainName: this.node.tryGetContext('domainName'),
|
|
73
73
|
subDomain: this.node.tryGetContext('subDomain'),
|
|
74
74
|
extraContexts: this.node.tryGetContext('extraContexts'),
|
|
75
|
+
skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
78
|
/**
|
|
@@ -617,7 +617,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
617
617
|
createApiRouteAssets() {
|
|
618
618
|
if (this.props.api.useExisting)
|
|
619
619
|
return;
|
|
620
|
-
this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.apiDestinedRestApi.domain, this.apiDestinedRestApi.hostedZone);
|
|
620
|
+
this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.apiDestinedRestApi.domain, this.apiDestinedRestApi.hostedZone, this.props.skipStageForARecords);
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
623
|
exports.ApiToEventBridgeTarget = ApiToEventBridgeTarget;
|
|
@@ -206,7 +206,7 @@ class GraphQLApiLambda extends common_1.CommonConstruct {
|
|
|
206
206
|
* @protected
|
|
207
207
|
*/
|
|
208
208
|
createApiRouteAssets() {
|
|
209
|
-
this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.graphQLApiDomain, this.graphQLApiHostedZone);
|
|
209
|
+
this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.graphQLApiDomain, this.graphQLApiHostedZone, this.props.skipStageForARecords);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
exports.GraphQLApiLambda = GraphQLApiLambda;
|
|
@@ -316,7 +316,7 @@ class SiteWithEcsBackend extends common_1.CommonConstruct {
|
|
|
316
316
|
* @protected
|
|
317
317
|
*/
|
|
318
318
|
createNetworkMappings() {
|
|
319
|
-
this.route53Manager.createCloudFrontTargetARecord(`${this.id}-a-record`, this, this.siteDistribution, this.siteHostedZone, this.props.siteRecordName);
|
|
319
|
+
this.route53Manager.createCloudFrontTargetARecord(`${this.id}-a-record`, this, this.siteDistribution, this.siteHostedZone, this.props.siteRecordName, this.props.skipStageForARecords);
|
|
320
320
|
}
|
|
321
321
|
/**
|
|
322
322
|
* Method to invalidation the cloudfront distribution cache after a deployment
|
|
@@ -156,10 +156,7 @@ class StaticSite extends common_1.CommonConstruct {
|
|
|
156
156
|
* @protected
|
|
157
157
|
*/
|
|
158
158
|
createSiteRouteAssets() {
|
|
159
|
-
this.siteARecord = this.route53Manager.createCloudFrontTargetARecord(`${this.id}-domain-a-record`, this, this.siteDistribution, this.siteHostedZone, this.props.siteRecordName);
|
|
160
|
-
if (!this.isProductionStage() && this.props.siteCreateAltARecord) {
|
|
161
|
-
this.siteARecordAlt = this.route53Manager.createCloudFrontTargetARecordV2(`${this.id}-domain-a-record-alt`, this, this.siteDistribution, this.siteHostedZone, this.props.siteRecordName);
|
|
162
|
-
}
|
|
159
|
+
this.siteARecord = this.route53Manager.createCloudFrontTargetARecord(`${this.id}-domain-a-record`, this, this.siteDistribution, this.siteHostedZone, this.props.siteRecordName, this.props.skipStageForARecords);
|
|
163
160
|
}
|
|
164
161
|
/**
|
|
165
162
|
* @summary Method to deploy the static assets into s3 bucket for static site
|
|
@@ -111,7 +111,7 @@ class EventManager {
|
|
|
111
111
|
scheduleExpression: scheduleExpression,
|
|
112
112
|
name: `${props.name}-${scope.props.stage}`,
|
|
113
113
|
state: props.state,
|
|
114
|
-
targets: [{ arn: lambdaFunction.functionArn, id: `${id}-${scope.props.stage}
|
|
114
|
+
targets: [{ arn: lambdaFunction.functionArn, id: `${id}-${scope.props.stage}`, input: props.input ?? undefined }],
|
|
115
115
|
});
|
|
116
116
|
new lambda.CfnPermission(scope, `${id}LambdaPermission`, {
|
|
117
117
|
action: 'lambda:InvokeFunction',
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as cdk from 'aws-cdk-lib';
|
|
2
2
|
import * as ecs from 'aws-cdk-lib/aws-ecs';
|
|
3
|
+
import * as events from 'aws-cdk-lib/aws-events';
|
|
3
4
|
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
4
5
|
import * as logs from 'aws-cdk-lib/aws-logs';
|
|
5
6
|
import * as s3 from 'aws-cdk-lib/aws-s3';
|
|
7
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
6
8
|
import * as common from '../../common';
|
|
7
9
|
/**
|
|
8
10
|
* @stability stable
|
|
@@ -151,4 +153,11 @@ export declare class IamManager {
|
|
|
151
153
|
* @param {iam.ServicePrincipal} servicePrinicpal
|
|
152
154
|
*/
|
|
153
155
|
createRoleForLambda(id: string, scope: common.CommonConstruct, policy: iam.PolicyDocument, servicePrinicpal?: iam.ServicePrincipal): cdk.aws_iam.Role;
|
|
156
|
+
/**
|
|
157
|
+
* @summary Method to create iam policy for sqs
|
|
158
|
+
* @param {string} id scoped id of the resource
|
|
159
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
160
|
+
* @param {iam.ServicePrincipal} servicePrinicpal
|
|
161
|
+
*/
|
|
162
|
+
createPolicyForSqsEvent(id: string, scope: common.CommonConstruct, sqsQueue: sqs.Queue, eventBridgeRule: events.IRule, servicePrincipals?: iam.ServicePrincipal[]): cdk.aws_iam.PolicyDocument;
|
|
154
163
|
}
|
|
@@ -380,5 +380,29 @@ class IamManager {
|
|
|
380
380
|
utils.createCfnOutput(`${id}Name`, scope, role.roleName);
|
|
381
381
|
return role;
|
|
382
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* @summary Method to create iam policy for sqs
|
|
385
|
+
* @param {string} id scoped id of the resource
|
|
386
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
387
|
+
* @param {iam.ServicePrincipal} servicePrinicpal
|
|
388
|
+
*/
|
|
389
|
+
createPolicyForSqsEvent(id, scope, sqsQueue, eventBridgeRule, servicePrincipals) {
|
|
390
|
+
const policy = new iam.PolicyDocument({
|
|
391
|
+
statements: [
|
|
392
|
+
new iam.PolicyStatement({
|
|
393
|
+
actions: ['sqs:*'],
|
|
394
|
+
effect: iam.Effect.ALLOW,
|
|
395
|
+
conditions: {
|
|
396
|
+
ArnEquals: {
|
|
397
|
+
'aws:SourceArn': eventBridgeRule,
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
principals: servicePrincipals ?? [new iam.ServicePrincipal('events.amazonaws.com')],
|
|
401
|
+
resources: [sqsQueue.queueArn],
|
|
402
|
+
}),
|
|
403
|
+
],
|
|
404
|
+
});
|
|
405
|
+
return policy;
|
|
406
|
+
}
|
|
383
407
|
}
|
|
384
408
|
exports.IamManager = IamManager;
|
|
@@ -19,6 +19,7 @@ export * from './route53-manager';
|
|
|
19
19
|
export * from './s3-manager';
|
|
20
20
|
export * from './secrets-manager';
|
|
21
21
|
export * from './sns-manager';
|
|
22
|
+
export * from './sqs-manager';
|
|
22
23
|
export * from './ssm-manager';
|
|
23
24
|
export * from './vpc-manager';
|
|
24
25
|
export * from './waf-manager';
|
|
@@ -35,6 +35,7 @@ __exportStar(require("./route53-manager"), exports);
|
|
|
35
35
|
__exportStar(require("./s3-manager"), exports);
|
|
36
36
|
__exportStar(require("./secrets-manager"), exports);
|
|
37
37
|
__exportStar(require("./sns-manager"), exports);
|
|
38
|
+
__exportStar(require("./sqs-manager"), exports);
|
|
38
39
|
__exportStar(require("./ssm-manager"), exports);
|
|
39
40
|
__exportStar(require("./vpc-manager"), exports);
|
|
40
41
|
__exportStar(require("./waf-manager"), exports);
|
|
@@ -45,8 +45,9 @@ export declare class Route53Manager {
|
|
|
45
45
|
* @param {cloudfront.IDistribution} distribution
|
|
46
46
|
* @param {route53.IHostedZone} hostedZone
|
|
47
47
|
* @param {string} recordName
|
|
48
|
+
* @param skipStageFromRecord
|
|
48
49
|
*/
|
|
49
|
-
createCloudFrontTargetARecord(id: string, scope: common.CommonConstruct, distribution?: cloudfront.IDistribution, hostedZone?: route53.IHostedZone, recordName?: string): route53.ARecord;
|
|
50
|
+
createCloudFrontTargetARecord(id: string, scope: common.CommonConstruct, distribution?: cloudfront.IDistribution, hostedZone?: route53.IHostedZone, recordName?: string, skipStageFromRecord?: boolean): route53.ARecord;
|
|
50
51
|
/**
|
|
51
52
|
* @summary Method to create a-record for cloudfront target
|
|
52
53
|
* @param {string} id scoped id of the resource
|
|
@@ -63,6 +64,7 @@ export declare class Route53Manager {
|
|
|
63
64
|
* @param recordName
|
|
64
65
|
* @param apiDomain
|
|
65
66
|
* @param hostedZone
|
|
67
|
+
* @param skipStageFromRecord
|
|
66
68
|
*/
|
|
67
|
-
createApiGatewayARecord(id: string, scope: common.CommonConstruct, recordName: string, apiDomain: apig.DomainName, hostedZone: route53.IHostedZone): route53.ARecord;
|
|
69
|
+
createApiGatewayARecord(id: string, scope: common.CommonConstruct, recordName: string, apiDomain: apig.DomainName, hostedZone: route53.IHostedZone, skipStageFromRecord?: boolean): route53.ARecord;
|
|
68
70
|
}
|
|
@@ -103,14 +103,17 @@ class Route53Manager {
|
|
|
103
103
|
* @param {cloudfront.IDistribution} distribution
|
|
104
104
|
* @param {route53.IHostedZone} hostedZone
|
|
105
105
|
* @param {string} recordName
|
|
106
|
+
* @param skipStageFromRecord
|
|
106
107
|
*/
|
|
107
|
-
createCloudFrontTargetARecord(id, scope, distribution, hostedZone, recordName) {
|
|
108
|
+
createCloudFrontTargetARecord(id, scope, distribution, hostedZone, recordName, skipStageFromRecord) {
|
|
108
109
|
if (!distribution)
|
|
109
110
|
throw `Distribution undefined`;
|
|
110
111
|
if (!hostedZone)
|
|
111
112
|
throw `HostedZone undefined`;
|
|
112
113
|
const aRecord = new route53.ARecord(scope, `${id}`, {
|
|
113
|
-
recordName: recordName && scope.isProductionStage()
|
|
114
|
+
recordName: (recordName && scope.isProductionStage()) || skipStageFromRecord
|
|
115
|
+
? `${recordName}`
|
|
116
|
+
: `${recordName}-${scope.props.stage}`,
|
|
114
117
|
target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(distribution)),
|
|
115
118
|
zone: hostedZone,
|
|
116
119
|
});
|
|
@@ -145,11 +148,13 @@ class Route53Manager {
|
|
|
145
148
|
* @param recordName
|
|
146
149
|
* @param apiDomain
|
|
147
150
|
* @param hostedZone
|
|
151
|
+
* @param skipStageFromRecord
|
|
148
152
|
*/
|
|
149
|
-
createApiGatewayARecord(id, scope, recordName, apiDomain, hostedZone) {
|
|
153
|
+
createApiGatewayARecord(id, scope, recordName, apiDomain, hostedZone, skipStageFromRecord) {
|
|
150
154
|
let apiRecordName = '';
|
|
151
155
|
if (recordName && recordName !== '')
|
|
152
|
-
apiRecordName =
|
|
156
|
+
apiRecordName =
|
|
157
|
+
scope.isProductionStage() || skipStageFromRecord ? `${recordName}` : `${recordName}-${scope.props.stage}`;
|
|
153
158
|
const apiARecord = new route53.ARecord(scope, `${id}`, {
|
|
154
159
|
recordName: apiRecordName,
|
|
155
160
|
target: route53.RecordTarget.fromAlias(new route53Targets.ApiGatewayDomain(apiDomain)),
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as cdk from 'aws-cdk-lib';
|
|
2
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
3
|
+
import * as common from '../../common';
|
|
4
|
+
import * as types from '../../types';
|
|
5
|
+
/**
|
|
6
|
+
* @stability stable
|
|
7
|
+
* @category cdk-utils.sqs-manager
|
|
8
|
+
* @subcategory Construct
|
|
9
|
+
* @classdesc Provides operations on AWS Simple Queue Service.
|
|
10
|
+
* - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
|
|
11
|
+
* - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
|
|
12
|
+
* @example
|
|
13
|
+
* import * as common from '@gradientedge/cdk-utils'
|
|
14
|
+
*
|
|
15
|
+
* class CustomConstruct extends common.common.CommonConstruct {
|
|
16
|
+
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
17
|
+
* super(parent, id, props)
|
|
18
|
+
* this.props = props
|
|
19
|
+
* this.sqsManager.createSqsQueue('MySqs', this)
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* @see [CDK Simple Queue Service Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs-readme.html}
|
|
24
|
+
*/
|
|
25
|
+
export declare class SqsManager {
|
|
26
|
+
/**
|
|
27
|
+
* @summary Method to create a lambda queue service
|
|
28
|
+
* @param {string} id scoped id of the resource
|
|
29
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
30
|
+
* @param {types.QueueProps} props
|
|
31
|
+
* @param {sqs.deadLetterQueue} deadLetterQueue
|
|
32
|
+
*/
|
|
33
|
+
createQueueService(id: string, scope: common.CommonConstruct, props: types.QueueProps, deadLetterQueue?: sqs.DeadLetterQueue): cdk.aws_sqs.Queue;
|
|
34
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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.SqsManager = void 0;
|
|
27
|
+
const cdk = __importStar(require("aws-cdk-lib"));
|
|
28
|
+
const sqs = __importStar(require("aws-cdk-lib/aws-sqs"));
|
|
29
|
+
const utils = __importStar(require("../../utils"));
|
|
30
|
+
/**
|
|
31
|
+
* @stability stable
|
|
32
|
+
* @category cdk-utils.sqs-manager
|
|
33
|
+
* @subcategory Construct
|
|
34
|
+
* @classdesc Provides operations on AWS Simple Queue 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.sqsManager.createSqsQueue('MySqs', this)
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* @see [CDK Simple Queue Service Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs-readme.html}
|
|
49
|
+
*/
|
|
50
|
+
class SqsManager {
|
|
51
|
+
/**
|
|
52
|
+
* @summary Method to create a lambda queue service
|
|
53
|
+
* @param {string} id scoped id of the resource
|
|
54
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
55
|
+
* @param {types.QueueProps} props
|
|
56
|
+
* @param {sqs.deadLetterQueue} deadLetterQueue
|
|
57
|
+
*/
|
|
58
|
+
createQueueService(id, scope, props, deadLetterQueue) {
|
|
59
|
+
if (!props)
|
|
60
|
+
throw `Queue props undefined`;
|
|
61
|
+
const queue = new sqs.Queue(scope, id, {
|
|
62
|
+
queueName: props.queueName,
|
|
63
|
+
visibilityTimeout: cdk.Duration.seconds(props.visibilityTimeoutInSecs),
|
|
64
|
+
receiveMessageWaitTime: cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs),
|
|
65
|
+
contentBasedDeduplication: props.contentBasedDeduplication,
|
|
66
|
+
dataKeyReuse: cdk.Duration.seconds(props.dataKeyReuseInSecs),
|
|
67
|
+
deadLetterQueue: deadLetterQueue,
|
|
68
|
+
deduplicationScope: props.deduplicationScope,
|
|
69
|
+
deliveryDelay: cdk.Duration.seconds(props.deliveryDelayInSecs),
|
|
70
|
+
encryption: props.encryption,
|
|
71
|
+
encryptionMasterKey: props.encryptionMasterKey,
|
|
72
|
+
fifo: props.fifo,
|
|
73
|
+
fifoThroughputLimit: props.fifoThroughputLimit,
|
|
74
|
+
maxMessageSizeBytes: props.maxMessageSizeBytes,
|
|
75
|
+
removalPolicy: props.removalPolicy,
|
|
76
|
+
retentionPeriod: props.retentionPeriod,
|
|
77
|
+
});
|
|
78
|
+
utils.createCfnOutput(`${id}-queueArn`, scope, queue.queueArn);
|
|
79
|
+
utils.createCfnOutput(`${id}-queueName`, scope, queue.queueName);
|
|
80
|
+
utils.createCfnOutput(`${id}-queueUrl`, scope, queue.queueUrl);
|
|
81
|
+
return queue;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.SqsManager = SqsManager;
|
|
@@ -22,6 +22,7 @@ import * as route53 from 'aws-cdk-lib/aws-route53';
|
|
|
22
22
|
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
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
25
26
|
import * as wafv2 from 'aws-cdk-lib/aws-wafv2';
|
|
26
27
|
import * as types from '../index';
|
|
27
28
|
/**
|
|
@@ -48,6 +49,7 @@ export interface CommonStackProps extends cdk.StackProps {
|
|
|
48
49
|
subDomain?: string;
|
|
49
50
|
extraContexts?: string[];
|
|
50
51
|
stageContextPath?: string;
|
|
52
|
+
skipStageForARecords: boolean;
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* @category cdk-utils.site-with-ecs-backend
|
|
@@ -413,6 +415,7 @@ export interface EksClusterProps extends eks.ClusterProps {
|
|
|
413
415
|
* @subcategory Properties
|
|
414
416
|
*/
|
|
415
417
|
export interface RuleProps extends events.CfnRuleProps {
|
|
418
|
+
input?: string;
|
|
416
419
|
}
|
|
417
420
|
/**
|
|
418
421
|
* @category cdk-utils.event-manager
|
|
@@ -510,4 +513,14 @@ export interface WafWebACLProps extends wafv2.CfnWebACLProps {
|
|
|
510
513
|
*/
|
|
511
514
|
export interface ElastiCacheProps extends elasticache.CfnCacheClusterProps {
|
|
512
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* @category cdk-utils.sqs-manager
|
|
518
|
+
* @subcategory Properties
|
|
519
|
+
*/
|
|
520
|
+
export interface QueueProps extends sqs.QueueProps {
|
|
521
|
+
visibilityTimeoutInSecs: number;
|
|
522
|
+
receiveMessageWaitTimeInSecs: number;
|
|
523
|
+
dataKeyReuseInSecs: number;
|
|
524
|
+
deliveryDelayInSecs: number;
|
|
525
|
+
}
|
|
513
526
|
export {};
|
package/package.json
CHANGED
|
@@ -46,6 +46,8 @@ export class CommonConstruct extends Construct {
|
|
|
46
46
|
ssMManager: aws.SsmManager
|
|
47
47
|
vpcManager: aws.VpcManager
|
|
48
48
|
wafManager: aws.WafManager
|
|
49
|
+
sqsManager: aws.SqsManager
|
|
50
|
+
|
|
49
51
|
fullyQualifiedDomainName: string
|
|
50
52
|
|
|
51
53
|
constructor(parent: Construct, id: string, props: types.CommonStackProps) {
|
|
@@ -75,6 +77,7 @@ export class CommonConstruct extends Construct {
|
|
|
75
77
|
this.ssMManager = new aws.SsmManager()
|
|
76
78
|
this.vpcManager = new aws.VpcManager()
|
|
77
79
|
this.wafManager = new aws.WafManager()
|
|
80
|
+
this.sqsManager = new aws.SqsManager()
|
|
78
81
|
|
|
79
82
|
this.determineFullyQualifiedDomain()
|
|
80
83
|
}
|
package/src/lib/common/stack.ts
CHANGED
|
@@ -55,6 +55,7 @@ export class CommonStack extends cdk.Stack {
|
|
|
55
55
|
domainName: this.node.tryGetContext('domainName'),
|
|
56
56
|
subDomain: this.node.tryGetContext('subDomain'),
|
|
57
57
|
extraContexts: this.node.tryGetContext('extraContexts'),
|
|
58
|
+
skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -687,7 +687,8 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
687
687
|
this,
|
|
688
688
|
this.props.apiSubDomain,
|
|
689
689
|
this.apiDestinedRestApi.domain,
|
|
690
|
-
this.apiDestinedRestApi.hostedZone
|
|
690
|
+
this.apiDestinedRestApi.hostedZone,
|
|
691
|
+
this.props.skipStageForARecords
|
|
691
692
|
)
|
|
692
693
|
}
|
|
693
694
|
}
|
|
@@ -184,18 +184,9 @@ export class StaticSite extends CommonConstruct {
|
|
|
184
184
|
this,
|
|
185
185
|
this.siteDistribution,
|
|
186
186
|
this.siteHostedZone,
|
|
187
|
-
this.props.siteRecordName
|
|
187
|
+
this.props.siteRecordName,
|
|
188
|
+
this.props.skipStageForARecords
|
|
188
189
|
)
|
|
189
|
-
|
|
190
|
-
if (!this.isProductionStage() && this.props.siteCreateAltARecord) {
|
|
191
|
-
this.siteARecordAlt = this.route53Manager.createCloudFrontTargetARecordV2(
|
|
192
|
-
`${this.id}-domain-a-record-alt`,
|
|
193
|
-
this,
|
|
194
|
-
this.siteDistribution,
|
|
195
|
-
this.siteHostedZone,
|
|
196
|
-
this.props.siteRecordName
|
|
197
|
-
)
|
|
198
|
-
}
|
|
199
190
|
}
|
|
200
191
|
|
|
201
192
|
/**
|
|
@@ -81,6 +81,7 @@ export class EventManager {
|
|
|
81
81
|
|
|
82
82
|
return rule
|
|
83
83
|
}
|
|
84
|
+
|
|
84
85
|
/**
|
|
85
86
|
* @summary Method to create an eventbridge rule with lambda target
|
|
86
87
|
* @param {string} id scoped id of the resource
|
|
@@ -109,7 +110,7 @@ export class EventManager {
|
|
|
109
110
|
scheduleExpression: scheduleExpression,
|
|
110
111
|
name: `${props.name}-${scope.props.stage}`,
|
|
111
112
|
state: props.state,
|
|
112
|
-
targets: [{ arn: lambdaFunction.functionArn, id: `${id}-${scope.props.stage}
|
|
113
|
+
targets: [{ arn: lambdaFunction.functionArn, id: `${id}-${scope.props.stage}`, input: props.input ?? undefined }],
|
|
113
114
|
})
|
|
114
115
|
|
|
115
116
|
new lambda.CfnPermission(scope, `${id}LambdaPermission`, {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as cdk from 'aws-cdk-lib'
|
|
2
2
|
import * as ecs from 'aws-cdk-lib/aws-ecs'
|
|
3
|
+
import * as events from 'aws-cdk-lib/aws-events'
|
|
3
4
|
import * as iam from 'aws-cdk-lib/aws-iam'
|
|
4
5
|
import * as logs from 'aws-cdk-lib/aws-logs'
|
|
5
6
|
import * as s3 from 'aws-cdk-lib/aws-s3'
|
|
7
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs'
|
|
6
8
|
import * as common from '../../common'
|
|
7
9
|
import * as utils from '../../utils'
|
|
8
10
|
|
|
@@ -412,4 +414,36 @@ export class IamManager {
|
|
|
412
414
|
|
|
413
415
|
return role
|
|
414
416
|
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* @summary Method to create iam policy for sqs
|
|
420
|
+
* @param {string} id scoped id of the resource
|
|
421
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
422
|
+
* @param {iam.ServicePrincipal} servicePrinicpal
|
|
423
|
+
*/
|
|
424
|
+
public createPolicyForSqsEvent(
|
|
425
|
+
id: string,
|
|
426
|
+
scope: common.CommonConstruct,
|
|
427
|
+
sqsQueue: sqs.Queue,
|
|
428
|
+
eventBridgeRule: events.IRule,
|
|
429
|
+
servicePrincipals?: iam.ServicePrincipal[]
|
|
430
|
+
) {
|
|
431
|
+
const policy = new iam.PolicyDocument({
|
|
432
|
+
statements: [
|
|
433
|
+
new iam.PolicyStatement({
|
|
434
|
+
actions: ['sqs:*'],
|
|
435
|
+
effect: iam.Effect.ALLOW,
|
|
436
|
+
conditions: {
|
|
437
|
+
ArnEquals: {
|
|
438
|
+
'aws:SourceArn': eventBridgeRule,
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
principals: servicePrincipals ?? [new iam.ServicePrincipal('events.amazonaws.com')],
|
|
442
|
+
resources: [sqsQueue.queueArn],
|
|
443
|
+
}),
|
|
444
|
+
],
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
return policy
|
|
448
|
+
}
|
|
415
449
|
}
|
|
@@ -19,6 +19,7 @@ export * from './route53-manager'
|
|
|
19
19
|
export * from './s3-manager'
|
|
20
20
|
export * from './secrets-manager'
|
|
21
21
|
export * from './sns-manager'
|
|
22
|
+
export * from './sqs-manager'
|
|
22
23
|
export * from './ssm-manager'
|
|
23
24
|
export * from './vpc-manager'
|
|
24
25
|
export * from './waf-manager'
|
|
@@ -92,19 +92,24 @@ export class Route53Manager {
|
|
|
92
92
|
* @param {cloudfront.IDistribution} distribution
|
|
93
93
|
* @param {route53.IHostedZone} hostedZone
|
|
94
94
|
* @param {string} recordName
|
|
95
|
+
* @param skipStageFromRecord
|
|
95
96
|
*/
|
|
96
97
|
public createCloudFrontTargetARecord(
|
|
97
98
|
id: string,
|
|
98
99
|
scope: common.CommonConstruct,
|
|
99
100
|
distribution?: cloudfront.IDistribution,
|
|
100
101
|
hostedZone?: route53.IHostedZone,
|
|
101
|
-
recordName?: string
|
|
102
|
+
recordName?: string,
|
|
103
|
+
skipStageFromRecord?: boolean
|
|
102
104
|
) {
|
|
103
105
|
if (!distribution) throw `Distribution undefined`
|
|
104
106
|
if (!hostedZone) throw `HostedZone undefined`
|
|
105
107
|
|
|
106
108
|
const aRecord = new route53.ARecord(scope, `${id}`, {
|
|
107
|
-
recordName:
|
|
109
|
+
recordName:
|
|
110
|
+
(recordName && scope.isProductionStage()) || skipStageFromRecord
|
|
111
|
+
? `${recordName}`
|
|
112
|
+
: `${recordName}-${scope.props.stage}`,
|
|
108
113
|
target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(distribution)),
|
|
109
114
|
zone: hostedZone,
|
|
110
115
|
})
|
|
@@ -150,17 +155,20 @@ export class Route53Manager {
|
|
|
150
155
|
* @param recordName
|
|
151
156
|
* @param apiDomain
|
|
152
157
|
* @param hostedZone
|
|
158
|
+
* @param skipStageFromRecord
|
|
153
159
|
*/
|
|
154
160
|
public createApiGatewayARecord(
|
|
155
161
|
id: string,
|
|
156
162
|
scope: common.CommonConstruct,
|
|
157
163
|
recordName: string,
|
|
158
164
|
apiDomain: apig.DomainName,
|
|
159
|
-
hostedZone: route53.IHostedZone
|
|
165
|
+
hostedZone: route53.IHostedZone,
|
|
166
|
+
skipStageFromRecord?: boolean
|
|
160
167
|
) {
|
|
161
168
|
let apiRecordName = ''
|
|
162
169
|
if (recordName && recordName !== '')
|
|
163
|
-
apiRecordName =
|
|
170
|
+
apiRecordName =
|
|
171
|
+
scope.isProductionStage() || skipStageFromRecord ? `${recordName}` : `${recordName}-${scope.props.stage}`
|
|
164
172
|
|
|
165
173
|
const apiARecord = new route53.ARecord(scope, `${id}`, {
|
|
166
174
|
recordName: apiRecordName,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as cdk from 'aws-cdk-lib'
|
|
2
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs'
|
|
3
|
+
import * as common from '../../common'
|
|
4
|
+
import * as types from '../../types'
|
|
5
|
+
import * as utils from '../../utils'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @stability stable
|
|
9
|
+
* @category cdk-utils.sqs-manager
|
|
10
|
+
* @subcategory Construct
|
|
11
|
+
* @classdesc Provides operations on AWS Simple Queue Service.
|
|
12
|
+
* - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
|
|
13
|
+
* - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
|
|
14
|
+
* @example
|
|
15
|
+
* import * as common from '@gradientedge/cdk-utils'
|
|
16
|
+
*
|
|
17
|
+
* class CustomConstruct extends common.common.CommonConstruct {
|
|
18
|
+
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
19
|
+
* super(parent, id, props)
|
|
20
|
+
* this.props = props
|
|
21
|
+
* this.sqsManager.createSqsQueue('MySqs', this)
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* @see [CDK Simple Queue Service Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs-readme.html}
|
|
26
|
+
*/
|
|
27
|
+
export class SqsManager {
|
|
28
|
+
/**
|
|
29
|
+
* @summary Method to create a lambda queue service
|
|
30
|
+
* @param {string} id scoped id of the resource
|
|
31
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
32
|
+
* @param {types.QueueProps} props
|
|
33
|
+
* @param {sqs.deadLetterQueue} deadLetterQueue
|
|
34
|
+
*/
|
|
35
|
+
public createQueueService(
|
|
36
|
+
id: string,
|
|
37
|
+
scope: common.CommonConstruct,
|
|
38
|
+
props: types.QueueProps,
|
|
39
|
+
deadLetterQueue?: sqs.DeadLetterQueue
|
|
40
|
+
) {
|
|
41
|
+
if (!props) throw `Queue props undefined`
|
|
42
|
+
|
|
43
|
+
const queue = new sqs.Queue(scope, id, {
|
|
44
|
+
queueName: props.queueName,
|
|
45
|
+
visibilityTimeout: cdk.Duration.seconds(props.visibilityTimeoutInSecs),
|
|
46
|
+
receiveMessageWaitTime: cdk.Duration.seconds(props.receiveMessageWaitTimeInSecs),
|
|
47
|
+
contentBasedDeduplication: props.contentBasedDeduplication,
|
|
48
|
+
dataKeyReuse: cdk.Duration.seconds(props.dataKeyReuseInSecs),
|
|
49
|
+
deadLetterQueue: deadLetterQueue,
|
|
50
|
+
deduplicationScope: props.deduplicationScope,
|
|
51
|
+
deliveryDelay: cdk.Duration.seconds(props.deliveryDelayInSecs),
|
|
52
|
+
encryption: props.encryption,
|
|
53
|
+
encryptionMasterKey: props.encryptionMasterKey,
|
|
54
|
+
fifo: props.fifo,
|
|
55
|
+
fifoThroughputLimit: props.fifoThroughputLimit,
|
|
56
|
+
maxMessageSizeBytes: props.maxMessageSizeBytes,
|
|
57
|
+
removalPolicy: props.removalPolicy,
|
|
58
|
+
retentionPeriod: props.retentionPeriod,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
utils.createCfnOutput(`${id}-queueArn`, scope, queue.queueArn)
|
|
62
|
+
utils.createCfnOutput(`${id}-queueName`, scope, queue.queueName)
|
|
63
|
+
utils.createCfnOutput(`${id}-queueUrl`, scope, queue.queueUrl)
|
|
64
|
+
|
|
65
|
+
return queue
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -22,6 +22,7 @@ import * as route53 from 'aws-cdk-lib/aws-route53'
|
|
|
22
22
|
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
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs'
|
|
25
26
|
import * as wafv2 from 'aws-cdk-lib/aws-wafv2'
|
|
26
27
|
import * as types from '../index'
|
|
27
28
|
|
|
@@ -50,6 +51,7 @@ export interface CommonStackProps extends cdk.StackProps {
|
|
|
50
51
|
subDomain?: string
|
|
51
52
|
extraContexts?: string[]
|
|
52
53
|
stageContextPath?: string
|
|
54
|
+
skipStageForARecords: boolean
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -437,7 +439,9 @@ export interface EksClusterProps extends eks.ClusterProps {
|
|
|
437
439
|
* @category cdk-utils.event-manager
|
|
438
440
|
* @subcategory Properties
|
|
439
441
|
*/
|
|
440
|
-
export interface RuleProps extends events.CfnRuleProps {
|
|
442
|
+
export interface RuleProps extends events.CfnRuleProps {
|
|
443
|
+
input?: string
|
|
444
|
+
}
|
|
441
445
|
|
|
442
446
|
/**
|
|
443
447
|
* @category cdk-utils.event-manager
|
|
@@ -540,3 +544,14 @@ export interface WafWebACLProps extends wafv2.CfnWebACLProps {}
|
|
|
540
544
|
* @category Compute
|
|
541
545
|
*/
|
|
542
546
|
export interface ElastiCacheProps extends elasticache.CfnCacheClusterProps {}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* @category cdk-utils.sqs-manager
|
|
550
|
+
* @subcategory Properties
|
|
551
|
+
*/
|
|
552
|
+
export interface QueueProps extends sqs.QueueProps {
|
|
553
|
+
visibilityTimeoutInSecs: number
|
|
554
|
+
receiveMessageWaitTimeInSecs: number
|
|
555
|
+
dataKeyReuseInSecs: number
|
|
556
|
+
deliveryDelayInSecs: number
|
|
557
|
+
}
|