@gradientedge/cdk-utils 8.72.0 → 8.73.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.
@@ -4,7 +4,8 @@ import { Construct } from 'constructs';
4
4
  import { GraphQLApiLambda } from '..';
5
5
  import { GraphQlApiLambdaWithCacheProps } from '../../types';
6
6
  /**
7
- * @stability stable
7
+ * @deprecated Use RestApiLambdaWithCache instead. This will be removed in a future release.
8
+ *
8
9
  * @category cdk-utils.graphql-api-lambda-with-cache
9
10
  * @subcategory construct
10
11
  * @classdesc Provides a construct to create and deploy a Graphql API as Lambda with Caching
@@ -30,7 +30,8 @@ const iam = __importStar(require("aws-cdk-lib/aws-iam"));
30
30
  const __1 = require("..");
31
31
  const utils = __importStar(require("../../utils"));
32
32
  /**
33
- * @stability stable
33
+ * @deprecated Use RestApiLambdaWithCache instead. This will be removed in a future release.
34
+ *
34
35
  * @category cdk-utils.graphql-api-lambda-with-cache
35
36
  * @subcategory construct
36
37
  * @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';
@@ -19,5 +19,7 @@ __exportStar(require("./api-to-eventbridge-target-with-sns"), exports);
19
19
  __exportStar(require("./api-to-lambda-target"), exports);
20
20
  __exportStar(require("./graphql-api-lambda"), exports);
21
21
  __exportStar(require("./graphql-api-lambda-with-cache"), exports);
22
+ __exportStar(require("./rest-api-lambda"), exports);
23
+ __exportStar(require("./rest-api-lambda-with-cache"), exports);
22
24
  __exportStar(require("./site-with-ecs-backend"), exports);
23
25
  __exportStar(require("./static-site"), exports);
@@ -0,0 +1 @@
1
+ export * from './main';
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./main"), exports);
@@ -0,0 +1,114 @@
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
+ * @deprecated Use RestApiLambda instead. This will be removed in a future release.
12
+ *
13
+ * @category cdk-utils.rest-api-lambda
14
+ * @subcategory construct
15
+ * @classdesc Provides a construct to create and deploy a RestApi as Lambda
16
+ *
17
+ * <b>Architecture</b><br/> ![Architecture](./RestApiLambda.jpg)
18
+ *
19
+ * @example
20
+ * import { RestApiLambda, RestApiLambdaProps } '@gradientedge/cdk-utils'
21
+ * import { Construct } from 'constructs'
22
+ *
23
+ * class CustomConstruct extends RestApiLambda {
24
+ * constructor(parent: Construct, id: string, props: RestApiLambdaProps) {
25
+ * super(parent, id, props)
26
+ * this.props = props
27
+ * this.id = id
28
+ * this.initResources()
29
+ * }
30
+ * }
31
+ * @mixin
32
+ */
33
+ export declare class RestApiLambda extends CommonConstruct {
34
+ props: RestApiLambdaProps;
35
+ id: string;
36
+ applicationSecrets: secretsmanager.ISecret[];
37
+ restApiLambdaPolicy: iam.PolicyDocument;
38
+ restApiLambdaRole: iam.Role;
39
+ restApiLambdaEnvironment: RestApiLambdaEnvironment;
40
+ restApiLambdaLayers: lambda.LayerVersion[];
41
+ restApiLambdaFunction: lambda.Function;
42
+ restApi: apig.RestApi;
43
+ restApiHostedZone: route53.IHostedZone;
44
+ restApiCertificate: acm.ICertificate;
45
+ restApiDomain: apig.DomainName;
46
+ restApiBasePathMappings: apig.BasePathMapping[];
47
+ constructor(parent: Construct, id: string, props: RestApiLambdaProps);
48
+ /**
49
+ * @summary Initialise and provision resources
50
+ * @protected
51
+ */
52
+ protected initResources(): void;
53
+ /**
54
+ * @summary Method to resolve secrets from SecretsManager
55
+ * - To be implemented in the overriding method in the implementation class
56
+ * @protected
57
+ */
58
+ protected resolveSecrets(): void;
59
+ /**
60
+ * @summary Method to resolve a hosted zone based on domain attributes
61
+ * @protected
62
+ */
63
+ protected resolveHostedZone(): void;
64
+ /**
65
+ * @summary Method to resolve a certificate based on attributes
66
+ * @protected
67
+ */
68
+ protected resolveCertificate(): void;
69
+ /**
70
+ * @summary Method to create iam policy for RestApi Lambda function
71
+ * @protected
72
+ */
73
+ protected createLambdaPolicy(): void;
74
+ /**
75
+ * @summary Method to create iam role for RestApi Lambda function
76
+ * @protected
77
+ */
78
+ protected createLambdaRole(): void;
79
+ /**
80
+ * @summary Method to create environment variables for RestApi Lambda function
81
+ * @protected
82
+ */
83
+ protected createLambdaEnvironment(): void;
84
+ /**
85
+ * @summary Method to create layers for RestApi Lambda function
86
+ * @protected
87
+ */
88
+ protected createLambdaLayers(): void;
89
+ /**
90
+ * @summary Method to create lambda function for RestApi
91
+ * @protected
92
+ */
93
+ protected createLambdaFunction(): void;
94
+ /**
95
+ * @summary Method to create rest restApiLambda for RestApi
96
+ * @protected
97
+ */
98
+ protected createRestApi(): void;
99
+ /**
100
+ * @summary Method to create custom restApiLambda domain for RestApi API
101
+ * @protected
102
+ */
103
+ protected createApiDomain(): void;
104
+ /**
105
+ * @summary Method to create base path mappings for RestApi API
106
+ * @protected
107
+ */
108
+ protected createApiBasePathMapping(): void;
109
+ /**
110
+ * @summary Method to create route53 records for RestApi API
111
+ * @protected
112
+ */
113
+ protected createApiRouteAssets(): void;
114
+ }
@@ -0,0 +1,214 @@
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.RestApiLambda = void 0;
27
+ const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
28
+ const iam = __importStar(require("aws-cdk-lib/aws-iam"));
29
+ const common_1 = require("../../common");
30
+ /**
31
+ * @deprecated Use RestApiLambda instead. This will be removed in a future release.
32
+ *
33
+ * @category cdk-utils.rest-api-lambda
34
+ * @subcategory construct
35
+ * @classdesc Provides a construct to create and deploy a RestApi as Lambda
36
+ *
37
+ * <b>Architecture</b><br/> ![Architecture](./RestApiLambda.jpg)
38
+ *
39
+ * @example
40
+ * import { RestApiLambda, RestApiLambdaProps } '@gradientedge/cdk-utils'
41
+ * import { Construct } from 'constructs'
42
+ *
43
+ * class CustomConstruct extends RestApiLambda {
44
+ * constructor(parent: Construct, id: string, props: RestApiLambdaProps) {
45
+ * super(parent, id, props)
46
+ * this.props = props
47
+ * this.id = id
48
+ * this.initResources()
49
+ * }
50
+ * }
51
+ * @mixin
52
+ */
53
+ class RestApiLambda extends common_1.CommonConstruct {
54
+ /* restApiLambda props */
55
+ props;
56
+ id;
57
+ /* restApiLambda resources */
58
+ applicationSecrets;
59
+ restApiLambdaPolicy;
60
+ restApiLambdaRole;
61
+ restApiLambdaEnvironment;
62
+ restApiLambdaLayers = [];
63
+ restApiLambdaFunction;
64
+ restApi;
65
+ restApiHostedZone;
66
+ restApiCertificate;
67
+ restApiDomain;
68
+ restApiBasePathMappings = [];
69
+ constructor(parent, id, props) {
70
+ super(parent, id, props);
71
+ this.props = props;
72
+ this.id = id;
73
+ }
74
+ /**
75
+ * @summary Initialise and provision resources
76
+ * @protected
77
+ */
78
+ initResources() {
79
+ this.resolveSecrets();
80
+ this.resolveHostedZone();
81
+ this.resolveCertificate();
82
+ this.createLambdaPolicy();
83
+ this.createLambdaRole();
84
+ this.createLambdaEnvironment();
85
+ this.createLambdaLayers();
86
+ this.createLambdaFunction();
87
+ this.createRestApi();
88
+ this.createApiDomain();
89
+ this.createApiBasePathMapping();
90
+ this.createApiRouteAssets();
91
+ }
92
+ /**
93
+ * @summary Method to resolve secrets from SecretsManager
94
+ * - To be implemented in the overriding method in the implementation class
95
+ * @protected
96
+ */
97
+ resolveSecrets() {
98
+ this.applicationSecrets = [];
99
+ }
100
+ /**
101
+ * @summary Method to resolve a hosted zone based on domain attributes
102
+ * @protected
103
+ */
104
+ resolveHostedZone() {
105
+ this.restApiHostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(`${this.id}-hosted-zone`, this, this.props.useExistingHostedZone);
106
+ }
107
+ /**
108
+ * @summary Method to resolve a certificate based on attributes
109
+ * @protected
110
+ */
111
+ resolveCertificate() {
112
+ if (this.props.restApiCertificate.useExistingCertificate &&
113
+ this.props.restApiCertificate.certificateSsmName &&
114
+ this.props.restApiCertificate.certificateRegion) {
115
+ this.props.restApiCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-param`, this, this.props.restApiCertificate.certificateSsmName, this.props.restApiCertificate.certificateRegion);
116
+ }
117
+ this.restApiCertificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.restApiCertificate);
118
+ }
119
+ /**
120
+ * @summary Method to create iam policy for RestApi Lambda function
121
+ * @protected
122
+ */
123
+ createLambdaPolicy() {
124
+ this.restApiLambdaPolicy = new iam.PolicyDocument({
125
+ statements: [this.iamManager.statementForCreateAnyLogStream()],
126
+ });
127
+ }
128
+ /**
129
+ * @summary Method to create iam role for RestApi Lambda function
130
+ * @protected
131
+ */
132
+ createLambdaRole() {
133
+ this.restApiLambdaRole = this.iamManager.createRoleForLambda(`${this.id}-lambda-role`, this, this.restApiLambdaPolicy);
134
+ }
135
+ /**
136
+ * @summary Method to create environment variables for RestApi Lambda function
137
+ * @protected
138
+ */
139
+ createLambdaEnvironment() {
140
+ this.restApiLambdaEnvironment = {
141
+ NODE_ENV: this.props.nodeEnv,
142
+ LOG_LEVEL: this.props.logLevel,
143
+ TZ: this.props.timezone,
144
+ };
145
+ }
146
+ /**
147
+ * @summary Method to create layers for RestApi Lambda function
148
+ * @protected
149
+ */
150
+ createLambdaLayers() {
151
+ const layers = [];
152
+ if (!this.props.restApiLambdaLayerSources)
153
+ return;
154
+ this.props.restApiLambdaLayerSources.forEach((source, index) => {
155
+ layers.push(this.lambdaManager.createLambdaLayer(`${this.id}-layer-${index}`, this, source));
156
+ });
157
+ this.restApiLambdaLayers = layers;
158
+ }
159
+ /**
160
+ * @summary Method to create lambda function for RestApi
161
+ * @protected
162
+ */
163
+ createLambdaFunction() {
164
+ this.restApiLambdaFunction = this.lambdaManager.createLambdaFunction(`${this.id}-restapi-server`, this, this.props.restApiLambda, this.restApiLambdaRole, this.restApiLambdaLayers, this.props.restApiSource, this.props.restApiHandler || 'index.handler', this.restApiLambdaEnvironment);
165
+ }
166
+ /**
167
+ * @summary Method to create rest restApiLambda for RestApi
168
+ * @protected
169
+ */
170
+ createRestApi() {
171
+ this.restApi = this.apiManager.createLambdaRestApi(`${this.id}-lambda-rest-api`, this, this.props.restApi, this.restApiLambdaFunction);
172
+ }
173
+ /**
174
+ * @summary Method to create custom restApiLambda domain for RestApi API
175
+ * @protected
176
+ */
177
+ createApiDomain() {
178
+ this.restApiDomain = this.apiManager.createApiDomain(`${this.id}-api-domain`, this, this.isProductionStage() || this.props.skipStageForARecords
179
+ ? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
180
+ : `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.restApiCertificate);
181
+ }
182
+ /**
183
+ * @summary Method to create base path mappings for RestApi API
184
+ * @protected
185
+ */
186
+ createApiBasePathMapping() {
187
+ const apiRootPaths = this.props.apiRootPaths;
188
+ if (apiRootPaths && apiRootPaths.length > 0) {
189
+ apiRootPaths.forEach((apiRootPath) => {
190
+ this.restApiBasePathMappings.push(new apig.BasePathMapping(this, `${this.id}-base-bath-mapping-${apiRootPath}`, {
191
+ basePath: apiRootPath,
192
+ domainName: this.restApiDomain,
193
+ restApi: this.restApi,
194
+ stage: this.restApi.deploymentStage,
195
+ }));
196
+ });
197
+ return;
198
+ }
199
+ // add default mapping if apiRootPaths not set
200
+ new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
201
+ domainName: this.restApiDomain,
202
+ restApi: this.restApi,
203
+ stage: this.restApi.deploymentStage,
204
+ });
205
+ }
206
+ /**
207
+ * @summary Method to create route53 records for RestApi API
208
+ * @protected
209
+ */
210
+ createApiRouteAssets() {
211
+ this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.restApiDomain, this.restApiHostedZone, this.props.skipStageForARecords);
212
+ }
213
+ }
214
+ exports.RestApiLambda = RestApiLambda;
@@ -0,0 +1 @@
1
+ export * from './main';
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./main"), exports);
@@ -0,0 +1,67 @@
1
+ import * as ec2 from 'aws-cdk-lib/aws-ec2';
2
+ import * as elasticache from 'aws-cdk-lib/aws-elasticache';
3
+ import { Construct } from 'constructs';
4
+ import { RestApiLambda } from '..';
5
+ import { RestApiLambdaWithCacheProps } from '../../types';
6
+ /**
7
+ * @stability stable
8
+ * @category cdk-utils.rest-api-lambda-with-cache
9
+ * @subcategory construct
10
+ * @classdesc Provides a construct to create and deploy a RestApi API as Lambda with Caching
11
+ *
12
+ * <b>Architecture</b><br/> ![Architecture](./RestApiLambda.jpg)
13
+ *
14
+ * @example
15
+ * import { RestApiLambdaWithCacheProps } '@gradientedge/cdk-utils'
16
+ * import { Construct } from 'constructs'
17
+ *
18
+ * class CustomConstruct extends RestApiLambdaWithCache {
19
+ * constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps) {
20
+ * super(parent, id, props)
21
+ * this.props = props
22
+ * this.id = id
23
+ * this.initResources()
24
+ * }
25
+ * }
26
+ * @mixin
27
+ */
28
+ export declare class RestApiLambdaWithCache extends RestApiLambda {
29
+ props: RestApiLambdaWithCacheProps;
30
+ id: string;
31
+ restApivpc: ec2.IVpc;
32
+ restApiCache: elasticache.CfnReplicationGroup;
33
+ restApiSecurityGroup: ec2.ISecurityGroup;
34
+ restApiSecurityGroupExportName: string;
35
+ constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps);
36
+ protected initResources(): void;
37
+ /**
38
+ * Create VPC
39
+ * @protected
40
+ */
41
+ protected resolveVpc(): void;
42
+ /**
43
+ * Resolve Security Group
44
+ * @protected
45
+ */
46
+ protected resolveSecurityGroup(): void;
47
+ /**
48
+ * Create ElastiCache
49
+ * @protected
50
+ */
51
+ protected createElastiCache(): void;
52
+ /**
53
+ * Create Lambda Role
54
+ * @protected
55
+ */
56
+ protected createLambdaRole(): void;
57
+ /**
58
+ * @summary Method to create environment variables for RestApi Lambda function
59
+ * @protected
60
+ */
61
+ protected createLambdaEnvironment(): void;
62
+ /**
63
+ * @summary Method to create lambda function for RestApi API
64
+ * @protected
65
+ */
66
+ protected createLambdaFunction(): void;
67
+ }
@@ -0,0 +1,137 @@
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.RestApiLambdaWithCache = void 0;
27
+ const cdk = __importStar(require("aws-cdk-lib"));
28
+ const ec2 = __importStar(require("aws-cdk-lib/aws-ec2"));
29
+ const iam = __importStar(require("aws-cdk-lib/aws-iam"));
30
+ const __1 = require("..");
31
+ const utils = __importStar(require("../../utils"));
32
+ /**
33
+ * @stability stable
34
+ * @category cdk-utils.rest-api-lambda-with-cache
35
+ * @subcategory construct
36
+ * @classdesc Provides a construct to create and deploy a RestApi API as Lambda with Caching
37
+ *
38
+ * <b>Architecture</b><br/> ![Architecture](./RestApiLambda.jpg)
39
+ *
40
+ * @example
41
+ * import { RestApiLambdaWithCacheProps } '@gradientedge/cdk-utils'
42
+ * import { Construct } from 'constructs'
43
+ *
44
+ * class CustomConstruct extends RestApiLambdaWithCache {
45
+ * constructor(parent: Construct, id: string, props: RestApiLambdaWithCacheProps) {
46
+ * super(parent, id, props)
47
+ * this.props = props
48
+ * this.id = id
49
+ * this.initResources()
50
+ * }
51
+ * }
52
+ * @mixin
53
+ */
54
+ class RestApiLambdaWithCache extends __1.RestApiLambda {
55
+ /* restApiLambdaWithCache props */
56
+ props;
57
+ id;
58
+ /* restApiLambda resources */
59
+ restApivpc;
60
+ restApiCache;
61
+ restApiSecurityGroup;
62
+ restApiSecurityGroupExportName;
63
+ constructor(parent, id, props) {
64
+ super(parent, id, props);
65
+ this.props = props;
66
+ this.id = id;
67
+ }
68
+ initResources() {
69
+ this.resolveVpc();
70
+ this.resolveSecurityGroup();
71
+ this.createElastiCache();
72
+ super.initResources();
73
+ }
74
+ /**
75
+ * Create VPC
76
+ * @protected
77
+ */
78
+ resolveVpc() {
79
+ if (this.props.useExistingVpc) {
80
+ this.restApivpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName);
81
+ }
82
+ else {
83
+ this.restApivpc = this.vpcManager.createCommonVpc(this, this.props.restApiVpc, this.props.restApiVpc.vpcName);
84
+ }
85
+ }
86
+ /**
87
+ * Resolve Security Group
88
+ * @protected
89
+ */
90
+ resolveSecurityGroup() {
91
+ if (this.props.securityGroupExportName) {
92
+ this.restApiSecurityGroup = ec2.SecurityGroup.fromSecurityGroupId(this, `${this.id}`, cdk.Fn.importValue(this.props.securityGroupExportName));
93
+ }
94
+ else {
95
+ this.restApiSecurityGroup = new ec2.SecurityGroup(this, `${this.id}-security-group-${this.props.stage}`, {
96
+ securityGroupName: `${this.id}-security-group-${this.props.stage}`,
97
+ vpc: this.restApivpc,
98
+ });
99
+ this.restApiSecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.allTraffic(), 'All Traffic');
100
+ utils.createCfnOutput(`${this.id}-security-group-id`, this, this.restApiSecurityGroup.securityGroupId);
101
+ }
102
+ }
103
+ /**
104
+ * Create ElastiCache
105
+ * @protected
106
+ */
107
+ createElastiCache() {
108
+ this.restApiCache = this.elasticacheManager.createReplicatedElastiCache(`${this.id}-elasticache`, this, this.props.restApiElastiCache, this.restApivpc.privateSubnets.map(subnet => subnet.subnetId), [this.restApiSecurityGroup.securityGroupId]);
109
+ }
110
+ /**
111
+ * Create Lambda Role
112
+ * @protected
113
+ */
114
+ createLambdaRole() {
115
+ super.createLambdaRole();
116
+ this.restApiLambdaRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaVPCAccessExecutionRole'));
117
+ }
118
+ /**
119
+ * @summary Method to create environment variables for RestApi Lambda function
120
+ * @protected
121
+ */
122
+ 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
+ * @summary Method to create lambda function for RestApi API
131
+ * @protected
132
+ */
133
+ createLambdaFunction() {
134
+ this.restApiLambdaFunction = this.lambdaManager.createLambdaFunction(`${this.id}-restapi-server`, this, this.props.restApiLambda, this.restApiLambdaRole, this.restApiLambdaLayers, this.props.restApiSource, this.props.restApiHandler || 'index.handler', this.restApiLambdaEnvironment, this.restApivpc, [this.restApiSecurityGroup], undefined, undefined, this.restApivpc);
135
+ }
136
+ }
137
+ exports.RestApiLambdaWithCache = RestApiLambdaWithCache;
@@ -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.73.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
+ }
@@ -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