@gradientedge/cdk-utils 7.9.1 → 7.11.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/manager/aws/lambda-manager.d.ts +15 -0
- package/dist/src/lib/manager/aws/lambda-manager.js +58 -1
- package/dist/src/lib/manager/aws/ssm-manager.d.ts +1 -0
- package/dist/src/lib/manager/aws/ssm-manager.js +1 -0
- package/dist/src/lib/types/aws/index.d.ts +1 -0
- package/package.json +13 -13
- package/src/lib/manager/aws/lambda-manager.ts +79 -1
- package/src/lib/manager/aws/ssm-manager.ts +1 -0
- package/src/lib/types/aws/index.ts +1 -0
|
@@ -66,4 +66,19 @@ export declare class LambdaManager {
|
|
|
66
66
|
* @param {string?} mountPath
|
|
67
67
|
*/
|
|
68
68
|
createEdgeFunction(id: string, scope: common.CommonConstruct, props: types.LambdaEdgeProps, layers: lambda.ILayerVersion[], code: lambda.AssetCode, environment?: any, vpc?: ec2.IVpc, securityGroups?: ec2.ISecurityGroup[], accessPoint?: efs.IAccessPoint, mountPath?: string): cdk.aws_cloudfront.experimental.EdgeFunction;
|
|
69
|
+
/**
|
|
70
|
+
* @summary Method to create a lambda function (nodejs) with docker image
|
|
71
|
+
* @param {string} id scoped id of the resource
|
|
72
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
73
|
+
* @param {types.LambdaProps} props
|
|
74
|
+
* @param {iam.Role | iam.CfnRole} role
|
|
75
|
+
* @param {lambda.DockerImageCode} code
|
|
76
|
+
* @param {Map<string, string>?} environment
|
|
77
|
+
* @param {ec2.IVpc?} vpc
|
|
78
|
+
* @param {ec2.ISecurityGroup[]?} securityGroups
|
|
79
|
+
* @param {efs.IAccessPoint?} accessPoint
|
|
80
|
+
* @param {string?} mountPath
|
|
81
|
+
* @param {ec2.SubnetSelection?} vpcSubnets
|
|
82
|
+
*/
|
|
83
|
+
createLambdaDockerFunction(id: string, scope: common.CommonConstruct, props: types.LambdaProps, role: iam.Role | iam.CfnRole, code: lambda.DockerImageCode, environment?: any, vpc?: ec2.IVpc, securityGroups?: ec2.ISecurityGroup[], accessPoint?: efs.IAccessPoint, mountPath?: string, vpcSubnets?: ec2.SubnetSelection): cdk.aws_lambda.DockerImageFunction;
|
|
69
84
|
}
|
|
@@ -29,6 +29,7 @@ const iam = __importStar(require("aws-cdk-lib/aws-iam"));
|
|
|
29
29
|
const lambda = __importStar(require("aws-cdk-lib/aws-lambda"));
|
|
30
30
|
const utils = __importStar(require("../../utils"));
|
|
31
31
|
const cloudfront_manager_1 = require("./cloudfront-manager");
|
|
32
|
+
const ssm_manager_1 = require("./ssm-manager");
|
|
32
33
|
/**
|
|
33
34
|
* @stability stable
|
|
34
35
|
* @category cdk-utils.lambda-manager
|
|
@@ -104,8 +105,10 @@ class LambdaManager {
|
|
|
104
105
|
architecture: props.architecture ?? lambda.Architecture.ARM_64,
|
|
105
106
|
environment: {
|
|
106
107
|
REGION: scope.props.region,
|
|
107
|
-
LAST_MODIFIED_TS: new Date().toISOString(),
|
|
108
108
|
STAGE: scope.props.stage,
|
|
109
|
+
LAST_MODIFIED_TS: props.excludeLastModifiedTimestamp
|
|
110
|
+
? ''
|
|
111
|
+
: scope.ssmManager.readStringParameter(`${id}-sm-ts`, scope, `${ssm_manager_1.SsmManager.SECRETS_MODIFIED_TIMESTAMP_PARAM}-${scope.props.stage}`),
|
|
109
112
|
...environment,
|
|
110
113
|
},
|
|
111
114
|
filesystem: accessPoint
|
|
@@ -142,5 +145,59 @@ class LambdaManager {
|
|
|
142
145
|
createEdgeFunction(id, scope, props, layers, code, environment, vpc, securityGroups, accessPoint, mountPath) {
|
|
143
146
|
return new cloudfront_manager_1.CloudFrontManager().createEdgeFunction(id, scope, props, layers, code, environment, vpc, securityGroups, accessPoint, mountPath);
|
|
144
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* @summary Method to create a lambda function (nodejs) with docker image
|
|
150
|
+
* @param {string} id scoped id of the resource
|
|
151
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
152
|
+
* @param {types.LambdaProps} props
|
|
153
|
+
* @param {iam.Role | iam.CfnRole} role
|
|
154
|
+
* @param {lambda.DockerImageCode} code
|
|
155
|
+
* @param {Map<string, string>?} environment
|
|
156
|
+
* @param {ec2.IVpc?} vpc
|
|
157
|
+
* @param {ec2.ISecurityGroup[]?} securityGroups
|
|
158
|
+
* @param {efs.IAccessPoint?} accessPoint
|
|
159
|
+
* @param {string?} mountPath
|
|
160
|
+
* @param {ec2.SubnetSelection?} vpcSubnets
|
|
161
|
+
*/
|
|
162
|
+
createLambdaDockerFunction(id, scope, props, role, code, environment, vpc, securityGroups, accessPoint, mountPath, vpcSubnets) {
|
|
163
|
+
if (!props)
|
|
164
|
+
throw `Lambda props undefined for ${id}`;
|
|
165
|
+
const functionName = `${props.functionName}-${scope.props.stage}`;
|
|
166
|
+
let deadLetterQueue;
|
|
167
|
+
if (props.deadLetterQueueEnabled && props.dlq) {
|
|
168
|
+
const redriveQueue = scope.sqsManager.createRedriveQueueForLambda(`${id}-rdq`, scope, props);
|
|
169
|
+
deadLetterQueue = scope.sqsManager.createDeadLetterQueueForLambda(`${id}-dlq`, scope, props, redriveQueue);
|
|
170
|
+
}
|
|
171
|
+
const lambdaFunction = new lambda.DockerImageFunction(scope, `${id}`, {
|
|
172
|
+
...props,
|
|
173
|
+
...{
|
|
174
|
+
allowPublicSubnet: !!vpc,
|
|
175
|
+
functionName: functionName,
|
|
176
|
+
runtime: LambdaManager.NODEJS_RUNTIME,
|
|
177
|
+
code: code,
|
|
178
|
+
deadLetterQueue: deadLetterQueue,
|
|
179
|
+
architecture: props.architecture ?? lambda.Architecture.ARM_64,
|
|
180
|
+
environment: {
|
|
181
|
+
REGION: scope.props.region,
|
|
182
|
+
LAST_MODIFIED_TS: new Date().toISOString(),
|
|
183
|
+
STAGE: scope.props.stage,
|
|
184
|
+
...environment,
|
|
185
|
+
},
|
|
186
|
+
filesystem: accessPoint
|
|
187
|
+
? lambda.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg')
|
|
188
|
+
: undefined,
|
|
189
|
+
reservedConcurrentExecutions: props.reservedConcurrentExecutions,
|
|
190
|
+
role: role instanceof iam.Role ? role : undefined,
|
|
191
|
+
securityGroups: securityGroups,
|
|
192
|
+
timeout: props.timeoutInSecs ? cdk.Duration.seconds(props.timeoutInSecs) : cdk.Duration.minutes(1),
|
|
193
|
+
vpc: vpc,
|
|
194
|
+
vpcSubnets: vpcSubnets,
|
|
195
|
+
tracing: props.tracing,
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
utils.createCfnOutput(`${id}-lambdaArn`, scope, lambdaFunction.functionArn);
|
|
199
|
+
utils.createCfnOutput(`${id}-lambdaName`, scope, lambdaFunction.functionName);
|
|
200
|
+
return lambdaFunction;
|
|
201
|
+
}
|
|
145
202
|
}
|
|
146
203
|
exports.LambdaManager = LambdaManager;
|
|
@@ -23,6 +23,7 @@ import * as types from '../../types';
|
|
|
23
23
|
* @see [CDK Systems Manager Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ssm-readme.html}
|
|
24
24
|
*/
|
|
25
25
|
export declare class SsmManager {
|
|
26
|
+
static SECRETS_MODIFIED_TIMESTAMP_PARAM: string;
|
|
26
27
|
/**
|
|
27
28
|
* Method to write a string parameter to the parameters store
|
|
28
29
|
* @param {string} id scoped id of the resource
|
|
@@ -48,6 +48,7 @@ const utils = __importStar(require("../../utils"));
|
|
|
48
48
|
* @see [CDK Systems Manager Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ssm-readme.html}
|
|
49
49
|
*/
|
|
50
50
|
class SsmManager {
|
|
51
|
+
static SECRETS_MODIFIED_TIMESTAMP_PARAM = 'secrets-last-modified-timestamp';
|
|
51
52
|
/**
|
|
52
53
|
* Method to write a string parameter to the parameters store
|
|
53
54
|
* @param {string} id scoped id of the resource
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.11.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"prettier": "npx prettier --check \"**/*.{ts,json,md}\"",
|
|
39
39
|
"prettify": "npx prettier --write \"**/*.{ts,json,md}\"",
|
|
40
40
|
"test": "rimraf coverage && npx jest --ci --runInBand",
|
|
41
|
-
"
|
|
41
|
+
"update:deps": "ncu -u -x lerna",
|
|
42
42
|
"validate": "yarn prettier && yarn test"
|
|
43
43
|
},
|
|
44
44
|
"husky": {
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@types/lodash": "^4.14.
|
|
51
|
-
"@types/node": "^18.11.
|
|
50
|
+
"@types/lodash": "^4.14.191",
|
|
51
|
+
"@types/node": "^18.11.11",
|
|
52
52
|
"app-root-path": "^3.1.0",
|
|
53
|
-
"aws-cdk-lib": "^2.
|
|
54
|
-
"aws-sdk": "^2.
|
|
55
|
-
"constructs": "^10.1.
|
|
53
|
+
"aws-cdk-lib": "^2.53.0",
|
|
54
|
+
"aws-sdk": "^2.1268.0",
|
|
55
|
+
"constructs": "^10.1.181",
|
|
56
56
|
"lodash": "^4.17.21",
|
|
57
57
|
"moment": "^2.29.4",
|
|
58
58
|
"nconf": "^0.12.0",
|
|
@@ -61,16 +61,16 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
64
|
-
"@types/jest": "^29.2.
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
66
|
-
"@typescript-eslint/parser": "^5.
|
|
64
|
+
"@types/jest": "^29.2.4",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^5.45.1",
|
|
66
|
+
"@typescript-eslint/parser": "^5.45.1",
|
|
67
67
|
"aws-cdk": "*",
|
|
68
68
|
"babel-eslint": "^10.1.0",
|
|
69
69
|
"better-docs": "^2.7.2",
|
|
70
70
|
"codecov": "^3.8.3",
|
|
71
|
-
"commitizen": "^4.2.
|
|
71
|
+
"commitizen": "^4.2.6",
|
|
72
72
|
"dotenv": "^16.0.3",
|
|
73
|
-
"eslint": "^8.
|
|
73
|
+
"eslint": "^8.29.0",
|
|
74
74
|
"eslint-config-prettier": "^8.5.0",
|
|
75
75
|
"eslint-plugin-import": "^2.26.0",
|
|
76
76
|
"husky": "^8.0.2",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"typescript": "4.9.3"
|
|
92
92
|
},
|
|
93
93
|
"optionalDependencies": {
|
|
94
|
-
"@babel/core": "^7.20.
|
|
94
|
+
"@babel/core": "^7.20.5",
|
|
95
95
|
"prop-types": "^15.8.1",
|
|
96
96
|
"react": "^18.2.0",
|
|
97
97
|
"react-dom": "^18.2.0"
|
|
@@ -7,6 +7,7 @@ import * as common from '../../common'
|
|
|
7
7
|
import * as types from '../../types'
|
|
8
8
|
import * as utils from '../../utils'
|
|
9
9
|
import { CloudFrontManager } from './cloudfront-manager'
|
|
10
|
+
import { SsmManager } from './ssm-manager'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @stability stable
|
|
@@ -103,8 +104,14 @@ export class LambdaManager {
|
|
|
103
104
|
architecture: props.architecture ?? lambda.Architecture.ARM_64,
|
|
104
105
|
environment: {
|
|
105
106
|
REGION: scope.props.region,
|
|
106
|
-
LAST_MODIFIED_TS: new Date().toISOString(),
|
|
107
107
|
STAGE: scope.props.stage,
|
|
108
|
+
LAST_MODIFIED_TS: props.excludeLastModifiedTimestamp
|
|
109
|
+
? ''
|
|
110
|
+
: scope.ssmManager.readStringParameter(
|
|
111
|
+
`${id}-sm-ts`,
|
|
112
|
+
scope,
|
|
113
|
+
`${SsmManager.SECRETS_MODIFIED_TIMESTAMP_PARAM}-${scope.props.stage}`
|
|
114
|
+
),
|
|
108
115
|
...environment,
|
|
109
116
|
},
|
|
110
117
|
filesystem: accessPoint
|
|
@@ -166,4 +173,75 @@ export class LambdaManager {
|
|
|
166
173
|
mountPath
|
|
167
174
|
)
|
|
168
175
|
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @summary Method to create a lambda function (nodejs) with docker image
|
|
179
|
+
* @param {string} id scoped id of the resource
|
|
180
|
+
* @param {common.CommonConstruct} scope scope in which this resource is defined
|
|
181
|
+
* @param {types.LambdaProps} props
|
|
182
|
+
* @param {iam.Role | iam.CfnRole} role
|
|
183
|
+
* @param {lambda.DockerImageCode} code
|
|
184
|
+
* @param {Map<string, string>?} environment
|
|
185
|
+
* @param {ec2.IVpc?} vpc
|
|
186
|
+
* @param {ec2.ISecurityGroup[]?} securityGroups
|
|
187
|
+
* @param {efs.IAccessPoint?} accessPoint
|
|
188
|
+
* @param {string?} mountPath
|
|
189
|
+
* @param {ec2.SubnetSelection?} vpcSubnets
|
|
190
|
+
*/
|
|
191
|
+
public createLambdaDockerFunction(
|
|
192
|
+
id: string,
|
|
193
|
+
scope: common.CommonConstruct,
|
|
194
|
+
props: types.LambdaProps,
|
|
195
|
+
role: iam.Role | iam.CfnRole,
|
|
196
|
+
code: lambda.DockerImageCode,
|
|
197
|
+
environment?: any,
|
|
198
|
+
vpc?: ec2.IVpc,
|
|
199
|
+
securityGroups?: ec2.ISecurityGroup[],
|
|
200
|
+
accessPoint?: efs.IAccessPoint,
|
|
201
|
+
mountPath?: string,
|
|
202
|
+
vpcSubnets?: ec2.SubnetSelection
|
|
203
|
+
) {
|
|
204
|
+
if (!props) throw `Lambda props undefined for ${id}`
|
|
205
|
+
|
|
206
|
+
const functionName = `${props.functionName}-${scope.props.stage}`
|
|
207
|
+
|
|
208
|
+
let deadLetterQueue
|
|
209
|
+
if (props.deadLetterQueueEnabled && props.dlq) {
|
|
210
|
+
const redriveQueue = scope.sqsManager.createRedriveQueueForLambda(`${id}-rdq`, scope, props)
|
|
211
|
+
deadLetterQueue = scope.sqsManager.createDeadLetterQueueForLambda(`${id}-dlq`, scope, props, redriveQueue)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const lambdaFunction = new lambda.DockerImageFunction(scope, `${id}`, {
|
|
215
|
+
...props,
|
|
216
|
+
...{
|
|
217
|
+
allowPublicSubnet: !!vpc,
|
|
218
|
+
functionName: functionName,
|
|
219
|
+
runtime: LambdaManager.NODEJS_RUNTIME,
|
|
220
|
+
code: code,
|
|
221
|
+
deadLetterQueue: deadLetterQueue,
|
|
222
|
+
architecture: props.architecture ?? lambda.Architecture.ARM_64,
|
|
223
|
+
environment: {
|
|
224
|
+
REGION: scope.props.region,
|
|
225
|
+
LAST_MODIFIED_TS: new Date().toISOString(),
|
|
226
|
+
STAGE: scope.props.stage,
|
|
227
|
+
...environment,
|
|
228
|
+
},
|
|
229
|
+
filesystem: accessPoint
|
|
230
|
+
? lambda.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg')
|
|
231
|
+
: undefined,
|
|
232
|
+
reservedConcurrentExecutions: props.reservedConcurrentExecutions,
|
|
233
|
+
role: role instanceof iam.Role ? role : undefined,
|
|
234
|
+
securityGroups: securityGroups,
|
|
235
|
+
timeout: props.timeoutInSecs ? cdk.Duration.seconds(props.timeoutInSecs) : cdk.Duration.minutes(1),
|
|
236
|
+
vpc: vpc,
|
|
237
|
+
vpcSubnets: vpcSubnets,
|
|
238
|
+
tracing: props.tracing,
|
|
239
|
+
},
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
utils.createCfnOutput(`${id}-lambdaArn`, scope, lambdaFunction.functionArn)
|
|
243
|
+
utils.createCfnOutput(`${id}-lambdaName`, scope, lambdaFunction.functionName)
|
|
244
|
+
|
|
245
|
+
return lambdaFunction
|
|
246
|
+
}
|
|
169
247
|
}
|
|
@@ -25,6 +25,7 @@ import * as utils from '../../utils'
|
|
|
25
25
|
* @see [CDK Systems Manager Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ssm-readme.html}
|
|
26
26
|
*/
|
|
27
27
|
export class SsmManager {
|
|
28
|
+
public static SECRETS_MODIFIED_TIMESTAMP_PARAM = 'secrets-last-modified-timestamp'
|
|
28
29
|
/**
|
|
29
30
|
* Method to write a string parameter to the parameters store
|
|
30
31
|
* @param {string} id scoped id of the resource
|