@gradientedge/cdk-utils 8.72.0 → 8.74.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.
Files changed (27) hide show
  1. package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.d.ts +2 -1
  2. package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.js +2 -1
  3. package/dist/src/lib/construct/index.d.ts +2 -0
  4. package/dist/src/lib/construct/index.js +2 -0
  5. package/dist/src/lib/construct/rest-api-lambda/index.d.ts +1 -0
  6. package/dist/src/lib/construct/rest-api-lambda/index.js +17 -0
  7. package/dist/src/lib/construct/rest-api-lambda/main.d.ts +114 -0
  8. package/dist/src/lib/construct/rest-api-lambda/main.js +214 -0
  9. package/dist/src/lib/construct/rest-api-lambda-with-cache/index.d.ts +1 -0
  10. package/dist/src/lib/construct/rest-api-lambda-with-cache/index.js +17 -0
  11. package/dist/src/lib/construct/rest-api-lambda-with-cache/main.d.ts +67 -0
  12. package/dist/src/lib/construct/rest-api-lambda-with-cache/main.js +137 -0
  13. package/dist/src/lib/manager/aws/iam-manager.d.ts +15 -0
  14. package/dist/src/lib/manager/aws/iam-manager.js +33 -0
  15. package/dist/src/lib/manager/aws/lambda-manager.js +1 -0
  16. package/dist/src/lib/types/aws/index.d.ts +38 -0
  17. package/dist/src/lib/utils/index.js +1 -1
  18. package/package.json +9 -9
  19. package/src/lib/construct/graphql-api-lambda-with-cache/main.ts +2 -1
  20. package/src/lib/construct/index.ts +2 -0
  21. package/src/lib/construct/rest-api-lambda/index.ts +1 -0
  22. package/src/lib/construct/rest-api-lambda/main.ts +261 -0
  23. package/src/lib/construct/rest-api-lambda-with-cache/index.ts +1 -0
  24. package/src/lib/construct/rest-api-lambda-with-cache/main.ts +151 -0
  25. package/src/lib/manager/aws/iam-manager.ts +36 -0
  26. package/src/lib/manager/aws/lambda-manager.ts +1 -0
  27. package/src/lib/types/aws/index.ts +40 -0
@@ -215,6 +215,7 @@ class LambdaManager {
215
215
  filesystem: accessPoint
216
216
  ? lambda.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg')
217
217
  : undefined,
218
+ logRetention: scope.props.logRetention ?? props.logRetention,
218
219
  reservedConcurrentExecutions: props.reservedConcurrentExecutions,
219
220
  role: role instanceof iam.Role ? role : undefined,
220
221
  securityGroups: securityGroups,
@@ -249,12 +249,20 @@ export interface ApiDestinedLambdaEnvironment extends LambdaEnvironment {
249
249
  SOURCE_ID: string;
250
250
  }
251
251
  /**
252
+ * @deprecated Use RestApiLambdaEnvironment instead. This will be removed in a future release.
252
253
  * @category cdk-utils.graphql-api-lambda
253
254
  * @subcategory Types
254
255
  */
255
256
  export interface GraphQlApiLambdaEnvironment extends LambdaEnvironment {
256
257
  }
257
258
  /**
259
+ * @category cdk-utils.rest-api-lambda
260
+ * @subcategory Types
261
+ */
262
+ export interface RestApiLambdaEnvironment extends LambdaEnvironment {
263
+ }
264
+ /**
265
+ * @deprecated Use RestApiLambdaProps instead. This will be removed in a future release.
258
266
  * @category cdk-utils.graphql-api-lambda
259
267
  * @subcategory Properties
260
268
  */
@@ -273,6 +281,25 @@ export interface GraphQlApiLambdaProps extends CommonStackProps {
273
281
  timezone: string;
274
282
  }
275
283
  /**
284
+ * @category cdk-utils.rest-api-lambda
285
+ * @subcategory Properties
286
+ */
287
+ export interface RestApiLambdaProps extends CommonStackProps {
288
+ apiRootPaths?: string[];
289
+ apiSubDomain: string;
290
+ restApiCertificate: AcmProps;
291
+ restApi: apig.LambdaRestApiProps;
292
+ restApiLambdaLayerSources?: lambda.AssetCode[];
293
+ restApiHandler: string;
294
+ restApiSource: lambda.AssetCode;
295
+ restApiLambda: LambdaProps;
296
+ useExistingHostedZone: boolean;
297
+ nodeEnv: string;
298
+ logLevel: string;
299
+ timezone: string;
300
+ }
301
+ /**
302
+ * @deprecated Use RestApiLambdaWithCacheProps instead. This will be removed in a future release.
276
303
  * @category cdk-utils.graphql-api-lambda-with-cache
277
304
  * @subcategory Properties
278
305
  */
@@ -283,6 +310,17 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
283
310
  useExistingVpc: boolean;
284
311
  vpcName?: string;
285
312
  }
313
+ /**
314
+ * @category cdk-utils.rest-api-lambda-with-cache
315
+ * @subcategory Properties
316
+ */
317
+ export interface RestApiLambdaWithCacheProps extends RestApiLambdaProps {
318
+ restApiVpc: ec2.VpcProps;
319
+ restApiElastiCache: ReplicatedElastiCacheProps;
320
+ securityGroupExportName: string;
321
+ useExistingVpc: boolean;
322
+ vpcName?: string;
323
+ }
286
324
  /**
287
325
  * @category cdk-utils.api-to-eventbridge-target
288
326
  * @subcategory Types
@@ -38,7 +38,7 @@ var LogLevel;
38
38
  LogLevel["TRACE"] = "TRACE";
39
39
  LogLevel["ERROR"] = "ERROR";
40
40
  LogLevel["CRITICAL"] = "CRITICAL";
41
- })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
41
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
42
42
  /**
43
43
  * @category cdk-utils.utils
44
44
  * @param stage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.72.0",
3
+ "version": "8.74.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -46,13 +46,13 @@
46
46
  }
47
47
  },
48
48
  "dependencies": {
49
- "@aws-sdk/client-secrets-manager": "^3.341.0",
49
+ "@aws-sdk/client-secrets-manager": "^3.344.0",
50
50
  "@types/lodash": "^4.14.195",
51
51
  "@types/node": "^20.2.5",
52
52
  "@types/uuid": "^9.0.1",
53
53
  "app-root-path": "^3.1.0",
54
- "aws-cdk-lib": "^2.81.0",
55
- "constructs": "^10.2.37",
54
+ "aws-cdk-lib": "^2.82.0",
55
+ "constructs": "^10.2.40",
56
56
  "lodash": "^4.17.21",
57
57
  "moment": "^2.29.4",
58
58
  "nconf": "^0.12.0",
@@ -64,19 +64,19 @@
64
64
  "@babel/core": "^7.22.1",
65
65
  "@babel/eslint-parser": "^7.21.8",
66
66
  "@babel/plugin-proposal-class-properties": "^7.18.6",
67
- "@types/jest": "^29.5.1",
67
+ "@types/jest": "^29.5.2",
68
68
  "@typescript-eslint/eslint-plugin": "^5.59.8",
69
69
  "@typescript-eslint/parser": "^5.59.8",
70
- "aws-cdk": "^2.81.0",
70
+ "aws-cdk": "^2.82.0",
71
71
  "better-docs": "^2.7.2",
72
72
  "codecov": "^3.8.3",
73
73
  "commitizen": "^4.3.0",
74
74
  "docdash": "^2.0.1",
75
- "dotenv": "^16.0.3",
75
+ "dotenv": "^16.1.3",
76
76
  "eslint": "^8.41.0",
77
77
  "eslint-config-prettier": "^8.8.0",
78
78
  "eslint-plugin-import": "^2.27.5",
79
- "eslint-plugin-jsdoc": "^45.0.0",
79
+ "eslint-plugin-jsdoc": "^46.1.0",
80
80
  "husky": "^8.0.3",
81
81
  "jest": "^29.5.0",
82
82
  "jest-extended": "^3.2.4",
@@ -93,7 +93,7 @@
93
93
  "taffydb": "^2.7.3",
94
94
  "ts-jest": "^29.1.0",
95
95
  "ts-node": "^10.9.1",
96
- "typescript": "5.0.4"
96
+ "typescript": "5.1.3"
97
97
  },
98
98
  "optionalDependencies": {
99
99
  "prop-types": "^15.8.1",
@@ -8,7 +8,8 @@ import { GraphQlApiLambdaWithCacheProps } from '../../types'
8
8
  import * as utils from '../../utils'
9
9
 
10
10
  /**
11
- * @stability stable
11
+ * @deprecated Use RestApiLambdaWithCache instead. This will be removed in a future release.
12
+ *
12
13
  * @category cdk-utils.graphql-api-lambda-with-cache
13
14
  * @subcategory construct
14
15
  * @classdesc Provides a construct to create and deploy a Graphql API as Lambda with Caching
@@ -3,5 +3,7 @@ export * from './api-to-eventbridge-target-with-sns'
3
3
  export * from './api-to-lambda-target'
4
4
  export * from './graphql-api-lambda'
5
5
  export * from './graphql-api-lambda-with-cache'
6
+ export * from './rest-api-lambda'
7
+ export * from './rest-api-lambda-with-cache'
6
8
  export * from './site-with-ecs-backend'
7
9
  export * from './static-site'
@@ -0,0 +1 @@
1
+ export * from './main'
@@ -0,0 +1,261 @@
1
+ import * as apig from 'aws-cdk-lib/aws-apigateway'
2
+ import * as acm from 'aws-cdk-lib/aws-certificatemanager'
3
+ import * as iam from 'aws-cdk-lib/aws-iam'
4
+ import * as lambda from 'aws-cdk-lib/aws-lambda'
5
+ import * as route53 from 'aws-cdk-lib/aws-route53'
6
+ import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
7
+ import { Construct } from 'constructs'
8
+ import { CommonConstruct } from '../../common'
9
+ import { RestApiLambdaEnvironment, RestApiLambdaProps } from '../../types'
10
+
11
+ /**
12
+ * @deprecated Use RestApiLambda instead. This will be removed in a future release.
13
+ *
14
+ * @category cdk-utils.rest-api-lambda
15
+ * @subcategory construct
16
+ * @classdesc Provides a construct to create and deploy a RestApi as Lambda
17
+ *
18
+ * <b>Architecture</b><br/> ![Architecture](./RestApiLambda.jpg)
19
+ *
20
+ * @example
21
+ * import { RestApiLambda, RestApiLambdaProps } '@gradientedge/cdk-utils'
22
+ * import { Construct } from 'constructs'
23
+ *
24
+ * class CustomConstruct extends RestApiLambda {
25
+ * constructor(parent: Construct, id: string, props: RestApiLambdaProps) {
26
+ * super(parent, id, props)
27
+ * this.props = props
28
+ * this.id = id
29
+ * this.initResources()
30
+ * }
31
+ * }
32
+ * @mixin
33
+ */
34
+ export class RestApiLambda extends CommonConstruct {
35
+ /* restApiLambda props */
36
+ props: RestApiLambdaProps
37
+ id: string
38
+
39
+ /* restApiLambda resources */
40
+ applicationSecrets: secretsmanager.ISecret[]
41
+ restApiLambdaPolicy: iam.PolicyDocument
42
+ restApiLambdaRole: iam.Role
43
+ restApiLambdaEnvironment: RestApiLambdaEnvironment
44
+ restApiLambdaLayers: lambda.LayerVersion[] = []
45
+ restApiLambdaFunction: lambda.Function
46
+ restApi: apig.RestApi
47
+ restApiHostedZone: route53.IHostedZone
48
+ restApiCertificate: acm.ICertificate
49
+ restApiDomain: apig.DomainName
50
+ restApiBasePathMappings: apig.BasePathMapping[] = []
51
+
52
+ constructor(parent: Construct, id: string, props: RestApiLambdaProps) {
53
+ super(parent, id, props)
54
+
55
+ this.props = props
56
+ this.id = id
57
+ }
58
+
59
+ /**
60
+ * @summary Initialise and provision resources
61
+ * @protected
62
+ */
63
+ protected initResources() {
64
+ this.resolveSecrets()
65
+ this.resolveHostedZone()
66
+ this.resolveCertificate()
67
+ this.createLambdaPolicy()
68
+ this.createLambdaRole()
69
+ this.createLambdaEnvironment()
70
+ this.createLambdaLayers()
71
+ this.createLambdaFunction()
72
+ this.createRestApi()
73
+ this.createApiDomain()
74
+ this.createApiBasePathMapping()
75
+ this.createApiRouteAssets()
76
+ }
77
+
78
+ /**
79
+ * @summary Method to resolve secrets from SecretsManager
80
+ * - To be implemented in the overriding method in the implementation class
81
+ * @protected
82
+ */
83
+ protected resolveSecrets() {
84
+ this.applicationSecrets = []
85
+ }
86
+
87
+ /**
88
+ * @summary Method to resolve a hosted zone based on domain attributes
89
+ * @protected
90
+ */
91
+ protected resolveHostedZone() {
92
+ this.restApiHostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(
93
+ `${this.id}-hosted-zone`,
94
+ this,
95
+ this.props.useExistingHostedZone
96
+ )
97
+ }
98
+
99
+ /**
100
+ * @summary Method to resolve a certificate based on attributes
101
+ * @protected
102
+ */
103
+ protected resolveCertificate() {
104
+ if (
105
+ this.props.restApiCertificate.useExistingCertificate &&
106
+ this.props.restApiCertificate.certificateSsmName &&
107
+ this.props.restApiCertificate.certificateRegion
108
+ ) {
109
+ this.props.restApiCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(
110
+ `${this.id}-certificate-param`,
111
+ this,
112
+ this.props.restApiCertificate.certificateSsmName,
113
+ this.props.restApiCertificate.certificateRegion
114
+ )
115
+ }
116
+
117
+ this.restApiCertificate = this.acmManager.resolveCertificate(
118
+ `${this.id}-certificate`,
119
+ this,
120
+ this.props.restApiCertificate
121
+ )
122
+ }
123
+
124
+ /**
125
+ * @summary Method to create iam policy for RestApi Lambda function
126
+ * @protected
127
+ */
128
+ protected createLambdaPolicy() {
129
+ this.restApiLambdaPolicy = new iam.PolicyDocument({
130
+ statements: [this.iamManager.statementForCreateAnyLogStream()],
131
+ })
132
+ }
133
+
134
+ /**
135
+ * @summary Method to create iam role for RestApi Lambda function
136
+ * @protected
137
+ */
138
+ protected createLambdaRole() {
139
+ this.restApiLambdaRole = this.iamManager.createRoleForLambda(
140
+ `${this.id}-lambda-role`,
141
+ this,
142
+ this.restApiLambdaPolicy
143
+ )
144
+ }
145
+
146
+ /**
147
+ * @summary Method to create environment variables for RestApi Lambda function
148
+ * @protected
149
+ */
150
+ protected createLambdaEnvironment() {
151
+ this.restApiLambdaEnvironment = {
152
+ NODE_ENV: this.props.nodeEnv,
153
+ LOG_LEVEL: this.props.logLevel,
154
+ TZ: this.props.timezone,
155
+ }
156
+ }
157
+
158
+ /**
159
+ * @summary Method to create layers for RestApi Lambda function
160
+ * @protected
161
+ */
162
+ protected createLambdaLayers() {
163
+ const layers: lambda.LayerVersion[] = []
164
+
165
+ if (!this.props.restApiLambdaLayerSources) return
166
+
167
+ this.props.restApiLambdaLayerSources.forEach((source: lambda.AssetCode, index: number) => {
168
+ layers.push(this.lambdaManager.createLambdaLayer(`${this.id}-layer-${index}`, this, source))
169
+ })
170
+
171
+ this.restApiLambdaLayers = layers
172
+ }
173
+
174
+ /**
175
+ * @summary Method to create lambda function for RestApi
176
+ * @protected
177
+ */
178
+ protected createLambdaFunction() {
179
+ this.restApiLambdaFunction = this.lambdaManager.createLambdaFunction(
180
+ `${this.id}-restapi-server`,
181
+ this,
182
+ this.props.restApiLambda,
183
+ this.restApiLambdaRole,
184
+ this.restApiLambdaLayers,
185
+ this.props.restApiSource,
186
+ this.props.restApiHandler || 'index.handler',
187
+ this.restApiLambdaEnvironment
188
+ )
189
+ }
190
+
191
+ /**
192
+ * @summary Method to create rest restApiLambda for RestApi
193
+ * @protected
194
+ */
195
+ protected createRestApi() {
196
+ this.restApi = this.apiManager.createLambdaRestApi(
197
+ `${this.id}-lambda-rest-api`,
198
+ this,
199
+ this.props.restApi,
200
+ this.restApiLambdaFunction
201
+ )
202
+ }
203
+
204
+ /**
205
+ * @summary Method to create custom restApiLambda domain for RestApi API
206
+ * @protected
207
+ */
208
+ protected createApiDomain() {
209
+ this.restApiDomain = this.apiManager.createApiDomain(
210
+ `${this.id}-api-domain`,
211
+ this,
212
+ this.isProductionStage() || this.props.skipStageForARecords
213
+ ? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
214
+ : `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`,
215
+ this.restApiCertificate
216
+ )
217
+ }
218
+
219
+ /**
220
+ * @summary Method to create base path mappings for RestApi API
221
+ * @protected
222
+ */
223
+ protected createApiBasePathMapping() {
224
+ const apiRootPaths = this.props.apiRootPaths
225
+ if (apiRootPaths && apiRootPaths.length > 0) {
226
+ apiRootPaths.forEach((apiRootPath: string) => {
227
+ this.restApiBasePathMappings.push(
228
+ new apig.BasePathMapping(this, `${this.id}-base-bath-mapping-${apiRootPath}`, {
229
+ basePath: apiRootPath,
230
+ domainName: this.restApiDomain,
231
+ restApi: this.restApi,
232
+ stage: this.restApi.deploymentStage,
233
+ })
234
+ )
235
+ })
236
+ return
237
+ }
238
+
239
+ // add default mapping if apiRootPaths not set
240
+ new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
241
+ domainName: this.restApiDomain,
242
+ restApi: this.restApi,
243
+ stage: this.restApi.deploymentStage,
244
+ })
245
+ }
246
+
247
+ /**
248
+ * @summary Method to create route53 records for RestApi API
249
+ * @protected
250
+ */
251
+ protected createApiRouteAssets() {
252
+ this.route53Manager.createApiGatewayARecord(
253
+ `${this.id}-custom-domain-a-record`,
254
+ this,
255
+ this.props.apiSubDomain,
256
+ this.restApiDomain,
257
+ this.restApiHostedZone,
258
+ this.props.skipStageForARecords
259
+ )
260
+ }
261
+ }
@@ -0,0 +1 @@
1
+ export * from './main'
@@ -0,0 +1,151 @@
1
+ import * as cdk from 'aws-cdk-lib'
2
+ import * as ec2 from 'aws-cdk-lib/aws-ec2'
3
+ import * as elasticache from 'aws-cdk-lib/aws-elasticache'
4
+ import * as iam from 'aws-cdk-lib/aws-iam'
5
+ import { Construct } from 'constructs'
6
+ import { RestApiLambda } from '..'
7
+ import { RestApiLambdaWithCacheProps } from '../../types'
8
+ import * as utils from '../../utils'
9
+
10
+ /**
11
+ * @stability stable
12
+ * @category cdk-utils.rest-api-lambda-with-cache
13
+ * @subcategory construct
14
+ * @classdesc Provides a construct to create and deploy a RestApi API as Lambda with Caching
15
+ *
16
+ * <b>Architecture</b><br/> ![Architecture](./RestApiLambda.jpg)
17
+ *
18
+ * @example
19
+ * import { RestApiLambdaWithCacheProps } '@gradientedge/cdk-utils'
20
+ * import { Construct } from 'constructs'
21
+ *
22
+ * class CustomConstruct extends RestApiLambdaWithCache {
23
+ * constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps) {
24
+ * super(parent, id, props)
25
+ * this.props = props
26
+ * this.id = id
27
+ * this.initResources()
28
+ * }
29
+ * }
30
+ * @mixin
31
+ */
32
+ export class RestApiLambdaWithCache extends RestApiLambda {
33
+ /* restApiLambdaWithCache props */
34
+ props: RestApiLambdaWithCacheProps
35
+ id: string
36
+
37
+ /* restApiLambda resources */
38
+ restApivpc: ec2.IVpc
39
+ restApiCache: elasticache.CfnReplicationGroup
40
+ restApiSecurityGroup: ec2.ISecurityGroup
41
+ restApiSecurityGroupExportName: string
42
+
43
+ constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps) {
44
+ super(parent, id, props)
45
+
46
+ this.props = props
47
+ this.id = id
48
+ }
49
+
50
+ protected initResources() {
51
+ this.resolveVpc()
52
+ this.resolveSecurityGroup()
53
+ this.createElastiCache()
54
+ super.initResources()
55
+ }
56
+
57
+ /**
58
+ * Create VPC
59
+ * @protected
60
+ */
61
+ protected resolveVpc() {
62
+ if (this.props.useExistingVpc) {
63
+ this.restApivpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName)
64
+ } else {
65
+ this.restApivpc = this.vpcManager.createCommonVpc(this, this.props.restApiVpc, this.props.restApiVpc.vpcName)
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Resolve Security Group
71
+ * @protected
72
+ */
73
+ protected resolveSecurityGroup() {
74
+ if (this.props.securityGroupExportName) {
75
+ this.restApiSecurityGroup = ec2.SecurityGroup.fromSecurityGroupId(
76
+ this,
77
+ `${this.id}`,
78
+ cdk.Fn.importValue(this.props.securityGroupExportName)
79
+ )
80
+ } else {
81
+ this.restApiSecurityGroup = new ec2.SecurityGroup(this, `${this.id}-security-group-${this.props.stage}`, {
82
+ securityGroupName: `${this.id}-security-group-${this.props.stage}`,
83
+ vpc: this.restApivpc,
84
+ })
85
+
86
+ this.restApiSecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.allTraffic(), 'All Traffic')
87
+
88
+ utils.createCfnOutput(`${this.id}-security-group-id`, this, this.restApiSecurityGroup.securityGroupId)
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Create ElastiCache
94
+ * @protected
95
+ */
96
+ protected createElastiCache() {
97
+ this.restApiCache = this.elasticacheManager.createReplicatedElastiCache(
98
+ `${this.id}-elasticache`,
99
+ this,
100
+ this.props.restApiElastiCache,
101
+ this.restApivpc.privateSubnets.map(subnet => subnet.subnetId),
102
+ [this.restApiSecurityGroup.securityGroupId]
103
+ )
104
+ }
105
+
106
+ /**
107
+ * Create Lambda Role
108
+ * @protected
109
+ */
110
+ protected createLambdaRole() {
111
+ super.createLambdaRole()
112
+
113
+ this.restApiLambdaRole.addManagedPolicy(
114
+ iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaVPCAccessExecutionRole')
115
+ )
116
+ }
117
+
118
+ /**
119
+ * @summary Method to create environment variables for RestApi Lambda function
120
+ * @protected
121
+ */
122
+ protected createLambdaEnvironment() {
123
+ this.restApiLambdaEnvironment = {
124
+ NODE_ENV: this.props.nodeEnv,
125
+ LOG_LEVEL: this.props.logLevel,
126
+ TZ: this.props.timezone,
127
+ }
128
+ }
129
+
130
+ /**
131
+ * @summary Method to create lambda function for RestApi API
132
+ * @protected
133
+ */
134
+ protected createLambdaFunction() {
135
+ this.restApiLambdaFunction = this.lambdaManager.createLambdaFunction(
136
+ `${this.id}-restapi-server`,
137
+ this,
138
+ this.props.restApiLambda,
139
+ this.restApiLambdaRole,
140
+ this.restApiLambdaLayers,
141
+ this.props.restApiSource,
142
+ this.props.restApiHandler || 'index.handler',
143
+ this.restApiLambdaEnvironment,
144
+ this.restApivpc,
145
+ [this.restApiSecurityGroup],
146
+ undefined,
147
+ undefined,
148
+ this.restApivpc
149
+ )
150
+ }
151
+ }
@@ -117,6 +117,42 @@ export class IamManager {
117
117
  })
118
118
  }
119
119
 
120
+ /**
121
+ * @summary Method to create iam statement to access app config
122
+ * @param {string[]} resourceArns list of ARNs to allow access to
123
+ */
124
+ public statementForAppConfigExecution(resourceArns?: string[]) {
125
+ return new iam.PolicyStatement({
126
+ effect: iam.Effect.ALLOW,
127
+ actions: ['appconfig:GetLatestConfiguration', 'appconfig:StartConfigurationSession'],
128
+ resources: resourceArns ?? ['*'],
129
+ })
130
+ }
131
+
132
+ /**
133
+ * @summary Method to create iam statement to put xray telemetry
134
+ * @param {string[]} resourceArns list of ARNs to allow access to
135
+ */
136
+ public statementForPutXrayTelemetry(resourceArns?: string[]) {
137
+ return new iam.PolicyStatement({
138
+ effect: iam.Effect.ALLOW,
139
+ actions: ['xray:PutTraceSegments', 'xray:PutTelemetryRecords'],
140
+ resources: resourceArns ?? ['*'],
141
+ })
142
+ }
143
+
144
+ /**
145
+ * @summary Method to create iam statement to decrypt kms
146
+ * @param {string[]} resourceArns list of ARNs to allow access to
147
+ */
148
+ public statementForDecryptKms(resourceArns?: string[]) {
149
+ return new iam.PolicyStatement({
150
+ effect: iam.Effect.ALLOW,
151
+ actions: ['kms:Decrypt'],
152
+ resources: resourceArns ?? ['*'],
153
+ })
154
+ }
155
+
120
156
  /**
121
157
  * @summary Method to create iam statement to list s3 buckets
122
158
  * @param {common.CommonConstruct} scope scope in which this resource is defined
@@ -270,6 +270,7 @@ export class LambdaManager {
270
270
  filesystem: accessPoint
271
271
  ? lambda.FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg')
272
272
  : undefined,
273
+ logRetention: scope.props.logRetention ?? props.logRetention,
273
274
  reservedConcurrentExecutions: props.reservedConcurrentExecutions,
274
275
  role: role instanceof iam.Role ? role : undefined,
275
276
  securityGroups: securityGroups,
@@ -270,12 +270,20 @@ export interface ApiDestinedLambdaEnvironment extends LambdaEnvironment {
270
270
  }
271
271
 
272
272
  /**
273
+ * @deprecated Use RestApiLambdaEnvironment instead. This will be removed in a future release.
273
274
  * @category cdk-utils.graphql-api-lambda
274
275
  * @subcategory Types
275
276
  */
276
277
  export interface GraphQlApiLambdaEnvironment extends LambdaEnvironment {}
277
278
 
278
279
  /**
280
+ * @category cdk-utils.rest-api-lambda
281
+ * @subcategory Types
282
+ */
283
+ export interface RestApiLambdaEnvironment extends LambdaEnvironment {}
284
+
285
+ /**
286
+ * @deprecated Use RestApiLambdaProps instead. This will be removed in a future release.
279
287
  * @category cdk-utils.graphql-api-lambda
280
288
  * @subcategory Properties
281
289
  */
@@ -295,6 +303,26 @@ export interface GraphQlApiLambdaProps extends CommonStackProps {
295
303
  }
296
304
 
297
305
  /**
306
+ * @category cdk-utils.rest-api-lambda
307
+ * @subcategory Properties
308
+ */
309
+ export interface RestApiLambdaProps extends CommonStackProps {
310
+ apiRootPaths?: string[]
311
+ apiSubDomain: string
312
+ restApiCertificate: AcmProps
313
+ restApi: apig.LambdaRestApiProps
314
+ restApiLambdaLayerSources?: lambda.AssetCode[]
315
+ restApiHandler: string
316
+ restApiSource: lambda.AssetCode
317
+ restApiLambda: LambdaProps
318
+ useExistingHostedZone: boolean
319
+ nodeEnv: string
320
+ logLevel: string
321
+ timezone: string
322
+ }
323
+
324
+ /**
325
+ * @deprecated Use RestApiLambdaWithCacheProps instead. This will be removed in a future release.
298
326
  * @category cdk-utils.graphql-api-lambda-with-cache
299
327
  * @subcategory Properties
300
328
  */
@@ -306,6 +334,18 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
306
334
  vpcName?: string
307
335
  }
308
336
 
337
+ /**
338
+ * @category cdk-utils.rest-api-lambda-with-cache
339
+ * @subcategory Properties
340
+ */
341
+ export interface RestApiLambdaWithCacheProps extends RestApiLambdaProps {
342
+ restApiVpc: ec2.VpcProps
343
+ restApiElastiCache: ReplicatedElastiCacheProps
344
+ securityGroupExportName: string
345
+ useExistingVpc: boolean
346
+ vpcName?: string
347
+ }
348
+
309
349
  /**
310
350
  * @category cdk-utils.api-to-eventbridge-target
311
351
  * @subcategory Types