@gradientedge/cdk-utils 5.0.0 → 5.3.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/app/api-destined-function/layers/nodejs/node_modules/.yarn-integrity +1 -1
- package/app/api-destined-function/layers/nodejs/package.json +1 -1
- package/app/api-destined-function/node_modules/.yarn-integrity +1 -1
- package/app/api-destined-function/package.json +1 -1
- package/dist/src/lib/common/construct.d.ts +1 -0
- package/dist/src/lib/common/construct.js +2 -0
- package/dist/src/lib/construct/api-to-eventbridge-target/main.js +2 -3
- package/dist/src/lib/manager/aws/cloudfront-manager.js +2 -1
- package/dist/src/lib/manager/aws/event-target-manager.d.ts +60 -0
- package/dist/src/lib/manager/aws/event-target-manager.js +91 -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/lambda-manager.d.ts +1 -0
- package/dist/src/lib/manager/aws/lambda-manager.js +3 -2
- package/package.json +14 -14
- package/src/lib/common/construct.ts +2 -0
- package/src/lib/construct/api-to-eventbridge-target/main.ts +2 -3
- package/src/lib/manager/aws/cloudfront-manager.ts +2 -1
- package/src/lib/manager/aws/event-target-manager.ts +84 -0
- package/src/lib/manager/aws/index.ts +1 -0
- package/src/lib/manager/aws/lambda-manager.ts +3 -2
|
@@ -33,6 +33,7 @@ export declare class CommonConstruct extends Construct {
|
|
|
33
33
|
eksManager: aws.EksManager;
|
|
34
34
|
elasticacheManager: aws.ElastiCacheManager;
|
|
35
35
|
eventManager: aws.EventManager;
|
|
36
|
+
eventTargetManager: aws.EventTargetManager;
|
|
36
37
|
iamManager: aws.IamManager;
|
|
37
38
|
kmsManager: aws.KmsManager;
|
|
38
39
|
lambdaManager: aws.LambdaManager;
|
|
@@ -58,6 +58,7 @@ class CommonConstruct extends constructs_1.Construct {
|
|
|
58
58
|
eksManager;
|
|
59
59
|
elasticacheManager;
|
|
60
60
|
eventManager;
|
|
61
|
+
eventTargetManager;
|
|
61
62
|
iamManager;
|
|
62
63
|
kmsManager;
|
|
63
64
|
lambdaManager;
|
|
@@ -88,6 +89,7 @@ class CommonConstruct extends constructs_1.Construct {
|
|
|
88
89
|
this.eksManager = new aws.EksManager();
|
|
89
90
|
this.elasticacheManager = new aws.ElastiCacheManager();
|
|
90
91
|
this.eventManager = new aws.EventManager();
|
|
92
|
+
this.eventTargetManager = new aws.EventTargetManager();
|
|
91
93
|
this.iamManager = new aws.IamManager();
|
|
92
94
|
this.kmsManager = new aws.KmsManager();
|
|
93
95
|
this.lambdaManager = new aws.LambdaManager();
|
|
@@ -351,7 +351,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
351
351
|
'application/json': [
|
|
352
352
|
'Action=Publish',
|
|
353
353
|
`TargetArn=$util.urlEncode('${this.apiDestinedRestApi.topic.topicArn}')`,
|
|
354
|
-
'Message=$input.body',
|
|
354
|
+
'Message=$util.urlEncode($input.body)',
|
|
355
355
|
'Version=2010-03-31',
|
|
356
356
|
].join('&'),
|
|
357
357
|
};
|
|
@@ -363,14 +363,13 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
363
363
|
createApiDestinedIntegrationResponse() {
|
|
364
364
|
if (!this.props.api.withResource)
|
|
365
365
|
return;
|
|
366
|
-
this.apiDestinedRestApi.integrationResponse = {
|
|
366
|
+
this.apiDestinedRestApi.integrationResponse = this.props.api.integrationResponse ?? {
|
|
367
367
|
...{
|
|
368
368
|
statusCode: '200',
|
|
369
369
|
responseTemplates: {
|
|
370
370
|
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
371
371
|
},
|
|
372
372
|
},
|
|
373
|
-
...this.props.api.integrationResponse,
|
|
374
373
|
};
|
|
375
374
|
}
|
|
376
375
|
/**
|
|
@@ -29,6 +29,7 @@ const cloudfront = __importStar(require("aws-cdk-lib/aws-cloudfront"));
|
|
|
29
29
|
const lambda = __importStar(require("aws-cdk-lib/aws-lambda"));
|
|
30
30
|
const cr = __importStar(require("aws-cdk-lib/custom-resources"));
|
|
31
31
|
const utils = __importStar(require("../../utils"));
|
|
32
|
+
const lambda_manager_1 = require("./lambda-manager");
|
|
32
33
|
/**
|
|
33
34
|
* @stability stable
|
|
34
35
|
* @category cdk-utils.cloudfront-manager
|
|
@@ -233,7 +234,7 @@ class CloudFrontManager {
|
|
|
233
234
|
logRetention: props.logRetention,
|
|
234
235
|
memorySize: props.memorySize,
|
|
235
236
|
reservedConcurrentExecutions: props.reservedConcurrentExecutions,
|
|
236
|
-
runtime: props.runtime ??
|
|
237
|
+
runtime: props.runtime ?? lambda_manager_1.LambdaManager.NODEJS_RUNTIME,
|
|
237
238
|
securityGroups: securityGroups,
|
|
238
239
|
stackId: `${id}-stack-id-${scope.props.stage}`,
|
|
239
240
|
timeout: props.timeoutInSecs ? cdk.Duration.seconds(props.timeoutInSecs) : cdk.Duration.minutes(1),
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as events from 'aws-cdk-lib/aws-events';
|
|
2
|
+
import * as targets from 'aws-cdk-lib/aws-events-targets';
|
|
3
|
+
import * as logs from 'aws-cdk-lib/aws-logs';
|
|
4
|
+
import * as common from '../../common';
|
|
5
|
+
/**
|
|
6
|
+
* @stability stable
|
|
7
|
+
* @category cdk-utils.event-taeget-manager
|
|
8
|
+
* @subcategory Construct
|
|
9
|
+
* @classdesc Provides operations on AWS EventBridge Targets.
|
|
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.eventTargetManager.createCloudWatchLogGroupNoPolicy('MyLogGrouptarget', this, myLogGroup)
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* @see [CDK EventBridge Target Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_events_targets-readme.html}
|
|
24
|
+
*/
|
|
25
|
+
export declare class EventTargetManager {
|
|
26
|
+
/**
|
|
27
|
+
* @summary Method to create a cloud watch log group target without a policy.
|
|
28
|
+
* - This method is created as a workaround for cdk issue - https://github.com/aws/aws-cdk/issues/17002
|
|
29
|
+
* @param {string} id scoped id of the resource
|
|
30
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
31
|
+
* @param {logs.ILogGroup} logGroup the log group
|
|
32
|
+
* @param {LogGroupNoPolicyProps} props the log group target properties
|
|
33
|
+
*/
|
|
34
|
+
createCloudWatchLogGroupNoPolicy(id: string, scope: common.CommonConstruct, logGroup: logs.ILogGroup, props?: LogGroupNoPolicyProps): CloudWatchLogGroupNoPolicy;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Customize the CloudWatch LogGroup Event Target
|
|
38
|
+
*/
|
|
39
|
+
export interface LogGroupNoPolicyProps extends targets.TargetBaseProps {
|
|
40
|
+
/**
|
|
41
|
+
* The event to send to the CloudWatch LogGroup
|
|
42
|
+
*
|
|
43
|
+
* This will be the event logged into the CloudWatch LogGroup
|
|
44
|
+
*
|
|
45
|
+
* @default - the entire EventBridge event
|
|
46
|
+
*/
|
|
47
|
+
readonly event?: events.RuleTargetInput;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Use an AWS CloudWatch LogGroup as an event rule target, but don't apply a policy.
|
|
51
|
+
*/
|
|
52
|
+
export declare class CloudWatchLogGroupNoPolicy implements events.IRuleTarget {
|
|
53
|
+
private readonly logGroup;
|
|
54
|
+
private readonly props;
|
|
55
|
+
constructor(logGroup: logs.ILogGroup, props?: LogGroupNoPolicyProps);
|
|
56
|
+
/**
|
|
57
|
+
* Returns a RuleTarget that can be used to log an event into a CloudWatch LogGroup
|
|
58
|
+
*/
|
|
59
|
+
bind(_rule: events.IRule, _id?: string): events.RuleTargetConfig;
|
|
60
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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.CloudWatchLogGroupNoPolicy = exports.EventTargetManager = void 0;
|
|
27
|
+
const cdk = __importStar(require("aws-cdk-lib"));
|
|
28
|
+
const targets = __importStar(require("aws-cdk-lib/aws-events-targets"));
|
|
29
|
+
/**
|
|
30
|
+
* @stability stable
|
|
31
|
+
* @category cdk-utils.event-taeget-manager
|
|
32
|
+
* @subcategory Construct
|
|
33
|
+
* @classdesc Provides operations on AWS EventBridge Targets.
|
|
34
|
+
* - A new instance of this class is injected into {@link common.CommonConstruct} constructor.
|
|
35
|
+
* - If a custom construct extends {@link common.CommonConstruct}, an instance is available within the context.
|
|
36
|
+
* @example
|
|
37
|
+
* import * as common from '@gradientedge/cdk-utils'
|
|
38
|
+
*
|
|
39
|
+
* class CustomConstruct extends common.common.CommonConstruct {
|
|
40
|
+
* constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
|
|
41
|
+
* super(parent, id, props)
|
|
42
|
+
* this.props = props
|
|
43
|
+
* this.eventTargetManager.createCloudWatchLogGroupNoPolicy('MyLogGrouptarget', this, myLogGroup)
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* @see [CDK EventBridge Target Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_events_targets-readme.html}
|
|
48
|
+
*/
|
|
49
|
+
class EventTargetManager {
|
|
50
|
+
/**
|
|
51
|
+
* @summary Method to create a cloud watch log group target without a policy.
|
|
52
|
+
* - This method is created as a workaround for cdk issue - https://github.com/aws/aws-cdk/issues/17002
|
|
53
|
+
* @param {string} id scoped id of the resource
|
|
54
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
55
|
+
* @param {logs.ILogGroup} logGroup the log group
|
|
56
|
+
* @param {LogGroupNoPolicyProps} props the log group target properties
|
|
57
|
+
*/
|
|
58
|
+
createCloudWatchLogGroupNoPolicy(id, scope, logGroup, props) {
|
|
59
|
+
return new CloudWatchLogGroupNoPolicy(logGroup, props);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.EventTargetManager = EventTargetManager;
|
|
63
|
+
/**
|
|
64
|
+
* Use an AWS CloudWatch LogGroup as an event rule target, but don't apply a policy.
|
|
65
|
+
*/
|
|
66
|
+
class CloudWatchLogGroupNoPolicy {
|
|
67
|
+
logGroup;
|
|
68
|
+
props;
|
|
69
|
+
constructor(logGroup, props = {}) {
|
|
70
|
+
this.logGroup = logGroup;
|
|
71
|
+
this.props = props;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns a RuleTarget that can be used to log an event into a CloudWatch LogGroup
|
|
75
|
+
*/
|
|
76
|
+
bind(_rule, _id) {
|
|
77
|
+
const logGroupStack = cdk.Stack.of(this.logGroup);
|
|
78
|
+
return {
|
|
79
|
+
...targets.bindBaseTargetConfig(this.props),
|
|
80
|
+
arn: logGroupStack.formatArn({
|
|
81
|
+
service: 'logs',
|
|
82
|
+
resource: 'log-group',
|
|
83
|
+
arnFormat: cdk.ArnFormat.COLON_RESOURCE_NAME,
|
|
84
|
+
resourceName: this.logGroup.logGroupName,
|
|
85
|
+
}),
|
|
86
|
+
input: this.props.event,
|
|
87
|
+
targetResource: this.logGroup,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.CloudWatchLogGroupNoPolicy = CloudWatchLogGroupNoPolicy;
|
|
@@ -11,6 +11,7 @@ export * from './ecs-manager';
|
|
|
11
11
|
export * from './eks-manager';
|
|
12
12
|
export * from './elasticache-manager';
|
|
13
13
|
export * from './event-manager';
|
|
14
|
+
export * from './event-target-manager';
|
|
14
15
|
export * from './iam-manager';
|
|
15
16
|
export * from './kms-manager';
|
|
16
17
|
export * from './lambda-manager';
|
|
@@ -27,6 +27,7 @@ __exportStar(require("./ecs-manager"), exports);
|
|
|
27
27
|
__exportStar(require("./eks-manager"), exports);
|
|
28
28
|
__exportStar(require("./elasticache-manager"), exports);
|
|
29
29
|
__exportStar(require("./event-manager"), exports);
|
|
30
|
+
__exportStar(require("./event-target-manager"), exports);
|
|
30
31
|
__exportStar(require("./iam-manager"), exports);
|
|
31
32
|
__exportStar(require("./kms-manager"), exports);
|
|
32
33
|
__exportStar(require("./lambda-manager"), exports);
|
|
@@ -26,6 +26,7 @@ import * as types from '../../types';
|
|
|
26
26
|
* @see [CDK Lambda Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda-readme.html}
|
|
27
27
|
*/
|
|
28
28
|
export declare class LambdaManager {
|
|
29
|
+
static NODEJS_RUNTIME: cdk.aws_lambda.Runtime;
|
|
29
30
|
/**
|
|
30
31
|
* @summary Method to create a lambda layer (nodejs)
|
|
31
32
|
* @param {string} id scoped id of the resource
|
|
@@ -50,6 +50,7 @@ const cloudfront_manager_1 = require("./cloudfront-manager");
|
|
|
50
50
|
* @see [CDK Lambda Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda-readme.html}
|
|
51
51
|
*/
|
|
52
52
|
class LambdaManager {
|
|
53
|
+
static NODEJS_RUNTIME = lambda.Runtime.NODEJS_16_X;
|
|
53
54
|
/**
|
|
54
55
|
* @summary Method to create a lambda layer (nodejs)
|
|
55
56
|
* @param {string} id scoped id of the resource
|
|
@@ -58,7 +59,7 @@ class LambdaManager {
|
|
|
58
59
|
*/
|
|
59
60
|
createLambdaLayer(id, scope, code) {
|
|
60
61
|
const lambdaLayer = new lambda.LayerVersion(scope, `${id}`, {
|
|
61
|
-
compatibleRuntimes: [
|
|
62
|
+
compatibleRuntimes: [LambdaManager.NODEJS_RUNTIME],
|
|
62
63
|
code: code,
|
|
63
64
|
description: `${id}`,
|
|
64
65
|
layerVersionName: `${id}-${scope.props.stage}`,
|
|
@@ -92,7 +93,7 @@ class LambdaManager {
|
|
|
92
93
|
allowPublicSubnet: !!vpc,
|
|
93
94
|
functionName: functionName,
|
|
94
95
|
handler: handler || 'index.lambda_handler',
|
|
95
|
-
runtime:
|
|
96
|
+
runtime: LambdaManager.NODEJS_RUNTIME,
|
|
96
97
|
code: code,
|
|
97
98
|
environment: {
|
|
98
99
|
REGION: scope.props.region,
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": "<
|
|
7
|
+
"node": ">=14.16.0 <17"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@types/lodash": "^4.14.182",
|
|
49
|
-
"@types/node": "^17.0.
|
|
49
|
+
"@types/node": "^17.0.33",
|
|
50
50
|
"app-root-path": "^3.0.0",
|
|
51
|
-
"aws-cdk-lib": "^2.
|
|
52
|
-
"aws-sdk": "^2.
|
|
53
|
-
"constructs": "^10.
|
|
51
|
+
"aws-cdk-lib": "^2.24.1",
|
|
52
|
+
"aws-sdk": "^2.1134.0",
|
|
53
|
+
"constructs": "^10.1.7",
|
|
54
54
|
"lodash": "^4.17.21",
|
|
55
55
|
"moment": "^2.29.3",
|
|
56
56
|
"nconf": "^0.12.0",
|
|
@@ -59,20 +59,20 @@
|
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
62
|
-
"@types/jest": "^27.5.
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
64
|
-
"@typescript-eslint/parser": "^5.
|
|
62
|
+
"@types/jest": "^27.5.1",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
|
64
|
+
"@typescript-eslint/parser": "^5.23.0",
|
|
65
65
|
"aws-cdk": "*",
|
|
66
66
|
"babel-eslint": "^10.1.0",
|
|
67
67
|
"better-docs": "^2.7.2",
|
|
68
68
|
"codecov": "^3.8.3",
|
|
69
69
|
"commitizen": "^4.2.4",
|
|
70
|
-
"dotenv": "^16.0.
|
|
71
|
-
"eslint": "^8.
|
|
70
|
+
"dotenv": "^16.0.1",
|
|
71
|
+
"eslint": "^8.15.0",
|
|
72
72
|
"eslint-config-prettier": "^8.5.0",
|
|
73
73
|
"eslint-plugin-import": "^2.26.0",
|
|
74
|
-
"husky": "^
|
|
75
|
-
"jest": "^28.0
|
|
74
|
+
"husky": "^8.0.1",
|
|
75
|
+
"jest": "^28.1.0",
|
|
76
76
|
"jest-extended": "^2.0.0",
|
|
77
77
|
"jest-junit": "^13.2.0",
|
|
78
78
|
"jsdoc": "^3.6.10",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"prettier-plugin-organize-imports": "^2.3.4",
|
|
84
84
|
"rimraf": "^3.0.2",
|
|
85
85
|
"semantic-release": "^19.0.2",
|
|
86
|
-
"ts-jest": "^28.0.
|
|
86
|
+
"ts-jest": "^28.0.2",
|
|
87
87
|
"ts-node": "^10.7.0",
|
|
88
88
|
"typescript": "4.6.4"
|
|
89
89
|
},
|
|
@@ -35,6 +35,7 @@ export class CommonConstruct extends Construct {
|
|
|
35
35
|
eksManager: aws.EksManager
|
|
36
36
|
elasticacheManager: aws.ElastiCacheManager
|
|
37
37
|
eventManager: aws.EventManager
|
|
38
|
+
eventTargetManager: aws.EventTargetManager
|
|
38
39
|
iamManager: aws.IamManager
|
|
39
40
|
kmsManager: aws.KmsManager
|
|
40
41
|
lambdaManager: aws.LambdaManager
|
|
@@ -67,6 +68,7 @@ export class CommonConstruct extends Construct {
|
|
|
67
68
|
this.eksManager = new aws.EksManager()
|
|
68
69
|
this.elasticacheManager = new aws.ElastiCacheManager()
|
|
69
70
|
this.eventManager = new aws.EventManager()
|
|
71
|
+
this.eventTargetManager = new aws.EventTargetManager()
|
|
70
72
|
this.iamManager = new aws.IamManager()
|
|
71
73
|
this.kmsManager = new aws.KmsManager()
|
|
72
74
|
this.lambdaManager = new aws.LambdaManager()
|
|
@@ -401,7 +401,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
401
401
|
'application/json': [
|
|
402
402
|
'Action=Publish',
|
|
403
403
|
`TargetArn=$util.urlEncode('${this.apiDestinedRestApi.topic.topicArn}')`,
|
|
404
|
-
'Message=$input.body',
|
|
404
|
+
'Message=$util.urlEncode($input.body)',
|
|
405
405
|
'Version=2010-03-31',
|
|
406
406
|
].join('&'),
|
|
407
407
|
}
|
|
@@ -413,14 +413,13 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
413
413
|
*/
|
|
414
414
|
protected createApiDestinedIntegrationResponse() {
|
|
415
415
|
if (!this.props.api.withResource) return
|
|
416
|
-
this.apiDestinedRestApi.integrationResponse = {
|
|
416
|
+
this.apiDestinedRestApi.integrationResponse = this.props.api.integrationResponse ?? {
|
|
417
417
|
...{
|
|
418
418
|
statusCode: '200',
|
|
419
419
|
responseTemplates: {
|
|
420
420
|
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
421
421
|
},
|
|
422
422
|
},
|
|
423
|
-
...this.props.api.integrationResponse,
|
|
424
423
|
}
|
|
425
424
|
}
|
|
426
425
|
|
|
@@ -10,6 +10,7 @@ import * as cr from 'aws-cdk-lib/custom-resources'
|
|
|
10
10
|
import * as common from '../../common'
|
|
11
11
|
import * as types from '../../types'
|
|
12
12
|
import * as utils from '../../utils'
|
|
13
|
+
import { LambdaManager } from './lambda-manager'
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @stability stable
|
|
@@ -263,7 +264,7 @@ export class CloudFrontManager {
|
|
|
263
264
|
logRetention: props.logRetention,
|
|
264
265
|
memorySize: props.memorySize,
|
|
265
266
|
reservedConcurrentExecutions: props.reservedConcurrentExecutions,
|
|
266
|
-
runtime: props.runtime ??
|
|
267
|
+
runtime: props.runtime ?? LambdaManager.NODEJS_RUNTIME,
|
|
267
268
|
securityGroups: securityGroups,
|
|
268
269
|
stackId: `${id}-stack-id-${scope.props.stage}`,
|
|
269
270
|
timeout: props.timeoutInSecs ? cdk.Duration.seconds(props.timeoutInSecs) : cdk.Duration.minutes(1),
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as cdk from 'aws-cdk-lib'
|
|
2
|
+
import * as events from 'aws-cdk-lib/aws-events'
|
|
3
|
+
import * as targets from 'aws-cdk-lib/aws-events-targets'
|
|
4
|
+
import * as logs from 'aws-cdk-lib/aws-logs'
|
|
5
|
+
import * as common from '../../common'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @stability stable
|
|
9
|
+
* @category cdk-utils.event-taeget-manager
|
|
10
|
+
* @subcategory Construct
|
|
11
|
+
* @classdesc Provides operations on AWS EventBridge Targets.
|
|
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.eventTargetManager.createCloudWatchLogGroupNoPolicy('MyLogGrouptarget', this, myLogGroup)
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* @see [CDK EventBridge Target Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_events_targets-readme.html}
|
|
26
|
+
*/
|
|
27
|
+
export class EventTargetManager {
|
|
28
|
+
/**
|
|
29
|
+
* @summary Method to create a cloud watch log group target without a policy.
|
|
30
|
+
* - This method is created as a workaround for cdk issue - https://github.com/aws/aws-cdk/issues/17002
|
|
31
|
+
* @param {string} id scoped id of the resource
|
|
32
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
33
|
+
* @param {logs.ILogGroup} logGroup the log group
|
|
34
|
+
* @param {LogGroupNoPolicyProps} props the log group target properties
|
|
35
|
+
*/
|
|
36
|
+
public createCloudWatchLogGroupNoPolicy(
|
|
37
|
+
id: string,
|
|
38
|
+
scope: common.CommonConstruct,
|
|
39
|
+
logGroup: logs.ILogGroup,
|
|
40
|
+
props?: LogGroupNoPolicyProps
|
|
41
|
+
) {
|
|
42
|
+
return new CloudWatchLogGroupNoPolicy(logGroup, props)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Customize the CloudWatch LogGroup Event Target
|
|
48
|
+
*/
|
|
49
|
+
export interface LogGroupNoPolicyProps extends targets.TargetBaseProps {
|
|
50
|
+
/**
|
|
51
|
+
* The event to send to the CloudWatch LogGroup
|
|
52
|
+
*
|
|
53
|
+
* This will be the event logged into the CloudWatch LogGroup
|
|
54
|
+
*
|
|
55
|
+
* @default - the entire EventBridge event
|
|
56
|
+
*/
|
|
57
|
+
readonly event?: events.RuleTargetInput
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Use an AWS CloudWatch LogGroup as an event rule target, but don't apply a policy.
|
|
62
|
+
*/
|
|
63
|
+
export class CloudWatchLogGroupNoPolicy implements events.IRuleTarget {
|
|
64
|
+
constructor(private readonly logGroup: logs.ILogGroup, private readonly props: LogGroupNoPolicyProps = {}) {}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Returns a RuleTarget that can be used to log an event into a CloudWatch LogGroup
|
|
68
|
+
*/
|
|
69
|
+
public bind(_rule: events.IRule, _id?: string): events.RuleTargetConfig {
|
|
70
|
+
const logGroupStack = cdk.Stack.of(this.logGroup)
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
...targets.bindBaseTargetConfig(this.props),
|
|
74
|
+
arn: logGroupStack.formatArn({
|
|
75
|
+
service: 'logs',
|
|
76
|
+
resource: 'log-group',
|
|
77
|
+
arnFormat: cdk.ArnFormat.COLON_RESOURCE_NAME,
|
|
78
|
+
resourceName: this.logGroup.logGroupName,
|
|
79
|
+
}),
|
|
80
|
+
input: this.props.event,
|
|
81
|
+
targetResource: this.logGroup,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -11,6 +11,7 @@ export * from './ecs-manager'
|
|
|
11
11
|
export * from './eks-manager'
|
|
12
12
|
export * from './elasticache-manager'
|
|
13
13
|
export * from './event-manager'
|
|
14
|
+
export * from './event-target-manager'
|
|
14
15
|
export * from './iam-manager'
|
|
15
16
|
export * from './kms-manager'
|
|
16
17
|
export * from './lambda-manager'
|
|
@@ -29,6 +29,7 @@ import { CloudFrontManager } from './cloudfront-manager'
|
|
|
29
29
|
* @see [CDK Lambda Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda-readme.html}
|
|
30
30
|
*/
|
|
31
31
|
export class LambdaManager {
|
|
32
|
+
public static NODEJS_RUNTIME = lambda.Runtime.NODEJS_16_X
|
|
32
33
|
/**
|
|
33
34
|
* @summary Method to create a lambda layer (nodejs)
|
|
34
35
|
* @param {string} id scoped id of the resource
|
|
@@ -37,7 +38,7 @@ export class LambdaManager {
|
|
|
37
38
|
*/
|
|
38
39
|
public createLambdaLayer(id: string, scope: common.CommonConstruct, code: lambda.AssetCode) {
|
|
39
40
|
const lambdaLayer = new lambda.LayerVersion(scope, `${id}`, {
|
|
40
|
-
compatibleRuntimes: [
|
|
41
|
+
compatibleRuntimes: [LambdaManager.NODEJS_RUNTIME],
|
|
41
42
|
code: code,
|
|
42
43
|
description: `${id}`,
|
|
43
44
|
layerVersionName: `${id}-${scope.props.stage}`,
|
|
@@ -88,7 +89,7 @@ export class LambdaManager {
|
|
|
88
89
|
allowPublicSubnet: !!vpc,
|
|
89
90
|
functionName: functionName,
|
|
90
91
|
handler: handler || 'index.lambda_handler',
|
|
91
|
-
runtime:
|
|
92
|
+
runtime: LambdaManager.NODEJS_RUNTIME,
|
|
92
93
|
code: code,
|
|
93
94
|
environment: {
|
|
94
95
|
REGION: scope.props.region,
|