@gradientedge/cdk-utils 6.9.0 → 6.10.1
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/construct/api-to-lambda-target/index.d.ts +1 -0
- package/dist/src/lib/construct/api-to-lambda-target/index.js +17 -0
- package/dist/src/lib/construct/api-to-lambda-target/main.d.ts +48 -0
- package/dist/src/lib/construct/api-to-lambda-target/main.js +156 -0
- package/dist/src/lib/construct/index.d.ts +1 -0
- package/dist/src/lib/construct/index.js +1 -0
- package/dist/src/lib/helper/api-to-lambda-target-rest-api.d.ts +36 -0
- package/dist/src/lib/helper/api-to-lambda-target-rest-api.js +30 -0
- package/dist/src/lib/helper/index.d.ts +1 -0
- package/dist/src/lib/helper/index.js +1 -0
- package/dist/src/lib/manager/aws/api-manager.d.ts +1 -1
- package/dist/src/lib/types/aws/index.d.ts +55 -0
- package/package.json +1 -1
- package/src/lib/construct/api-to-lambda-target/index.ts +1 -0
- package/src/lib/construct/api-to-lambda-target/main.ts +189 -0
- package/src/lib/construct/index.ts +1 -0
- package/src/lib/helper/api-to-lambda-target-rest-api.ts +33 -0
- package/src/lib/helper/index.ts +1 -0
- package/src/lib/manager/aws/api-manager.ts +1 -1
- package/src/lib/types/aws/index.ts +54 -0
|
@@ -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,48 @@
|
|
|
1
|
+
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { CommonConstruct } from '../../common';
|
|
4
|
+
import * as types from '../../types/aws';
|
|
5
|
+
export declare class ApiToLambdaTarget extends CommonConstruct {
|
|
6
|
+
props: types.ApiToLambdaTargetProps;
|
|
7
|
+
id: string;
|
|
8
|
+
applicationSecrets: secretsmanager.ISecret[];
|
|
9
|
+
apiToLambdaTargetRestApi: types.ApiToLambdaTargetRestApiType;
|
|
10
|
+
constructor(parent: Construct, id: string, props: types.ApiToLambdaTargetProps);
|
|
11
|
+
protected initResources(): void;
|
|
12
|
+
/**
|
|
13
|
+
* @summary Method to resolve secrets from SecretsManager
|
|
14
|
+
* - To be implemented in the overriding method in the implementation class
|
|
15
|
+
* @protected
|
|
16
|
+
*/
|
|
17
|
+
protected resolveSecrets(): void;
|
|
18
|
+
/**
|
|
19
|
+
* @summary Method to resolve a hosted zone based on domain attributes
|
|
20
|
+
* @protected
|
|
21
|
+
*/
|
|
22
|
+
protected resolveHostedZone(): void;
|
|
23
|
+
/**
|
|
24
|
+
* @summary Method to resolve a certificate based on attributes
|
|
25
|
+
* @protected
|
|
26
|
+
*/
|
|
27
|
+
protected resolveCertificate(): void;
|
|
28
|
+
/**
|
|
29
|
+
* @summary Method to create rest restApi for Api
|
|
30
|
+
* @protected
|
|
31
|
+
*/
|
|
32
|
+
protected createApiToLambdaTargetRestApi(): void;
|
|
33
|
+
/**
|
|
34
|
+
* @summary Method to create custom restApi domain for Api API
|
|
35
|
+
* @protected
|
|
36
|
+
*/
|
|
37
|
+
protected createApiDomain(): void;
|
|
38
|
+
/**
|
|
39
|
+
* @summary Method to create base path mappings for GraphQL API
|
|
40
|
+
* @protected
|
|
41
|
+
*/
|
|
42
|
+
protected createApiBasePathMapping(): void;
|
|
43
|
+
/**
|
|
44
|
+
* @summary Method to create route53 records for Api
|
|
45
|
+
* @protected
|
|
46
|
+
*/
|
|
47
|
+
protected createApiRouteAssets(): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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.ApiToLambdaTarget = void 0;
|
|
27
|
+
const cdk = __importStar(require("aws-cdk-lib"));
|
|
28
|
+
const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
|
|
29
|
+
const lambda = __importStar(require("aws-cdk-lib/aws-lambda"));
|
|
30
|
+
const common_1 = require("../../common");
|
|
31
|
+
const helper = __importStar(require("../../helper"));
|
|
32
|
+
class ApiToLambdaTarget extends common_1.CommonConstruct {
|
|
33
|
+
props;
|
|
34
|
+
id;
|
|
35
|
+
/* application related resources */
|
|
36
|
+
applicationSecrets;
|
|
37
|
+
/* rest restApi related resources */
|
|
38
|
+
apiToLambdaTargetRestApi;
|
|
39
|
+
constructor(parent, id, props) {
|
|
40
|
+
super(parent, id, props);
|
|
41
|
+
this.props = props;
|
|
42
|
+
this.id = id;
|
|
43
|
+
this.apiToLambdaTargetRestApi = new helper.ApiToLambdaTargetRestApi();
|
|
44
|
+
}
|
|
45
|
+
initResources() {
|
|
46
|
+
/* application related resources */
|
|
47
|
+
this.resolveSecrets();
|
|
48
|
+
/* core resources */
|
|
49
|
+
this.resolveHostedZone();
|
|
50
|
+
this.resolveCertificate();
|
|
51
|
+
/* restApi related resources */
|
|
52
|
+
this.createApiToLambdaTargetRestApi();
|
|
53
|
+
this.createApiDomain();
|
|
54
|
+
this.createApiBasePathMapping();
|
|
55
|
+
this.createApiRouteAssets();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @summary Method to resolve secrets from SecretsManager
|
|
59
|
+
* - To be implemented in the overriding method in the implementation class
|
|
60
|
+
* @protected
|
|
61
|
+
*/
|
|
62
|
+
resolveSecrets() {
|
|
63
|
+
this.applicationSecrets = [];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @summary Method to resolve a hosted zone based on domain attributes
|
|
67
|
+
* @protected
|
|
68
|
+
*/
|
|
69
|
+
resolveHostedZone() {
|
|
70
|
+
this.apiToLambdaTargetRestApi.hostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(`${this.id}-hosted-zone`, this, this.props.useExistingHostedZone);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @summary Method to resolve a certificate based on attributes
|
|
74
|
+
* @protected
|
|
75
|
+
*/
|
|
76
|
+
resolveCertificate() {
|
|
77
|
+
if (this.props.api.useExisting)
|
|
78
|
+
return;
|
|
79
|
+
if (this.props.api.certificate.useExistingCertificate &&
|
|
80
|
+
this.props.api.certificate.certificateSsmName &&
|
|
81
|
+
this.props.api.certificate.certificateRegion) {
|
|
82
|
+
this.props.api.certificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-param`, this, this.props.api.certificate.certificateSsmName, this.props.api.certificate.certificateRegion);
|
|
83
|
+
}
|
|
84
|
+
this.apiToLambdaTargetRestApi.certificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.api.certificate);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @summary Method to create rest restApi for Api
|
|
88
|
+
* @protected
|
|
89
|
+
*/
|
|
90
|
+
createApiToLambdaTargetRestApi() {
|
|
91
|
+
if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
|
|
92
|
+
this.apiToLambdaTargetRestApi.api = apig.RestApi.fromRestApiId(this, `${this.id}-rest-api`, cdk.Fn.importValue(this.props.api.importedRestApiRef));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
|
|
96
|
+
logGroupName: `/custom/api/${this.id}-rest-api-access`,
|
|
97
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
98
|
+
});
|
|
99
|
+
this.props.api.restApi = {
|
|
100
|
+
...this.props.api.restApi,
|
|
101
|
+
...{
|
|
102
|
+
deployOptions: {
|
|
103
|
+
accessLogDestination: new apig.LogGroupLogDestination(accessLogGroup),
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
this.apiToLambdaTargetRestApi.api = this.apiManager.createLambdaRestApi(`${this.id}-lambda-rest-api`, this, this.props.api.restApi, lambda.Function.fromFunctionName(this, `${this.id}-lambda`, this.props.lambdaFunctionName));
|
|
108
|
+
this.addCfnOutput(`${this.id}-restApiId`, this.apiToLambdaTargetRestApi.api.restApiId);
|
|
109
|
+
this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToLambdaTargetRestApi.api.root.resourceId);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @summary Method to create custom restApi domain for Api API
|
|
113
|
+
* @protected
|
|
114
|
+
*/
|
|
115
|
+
createApiDomain() {
|
|
116
|
+
if (this.props.api.useExisting)
|
|
117
|
+
return;
|
|
118
|
+
this.apiToLambdaTargetRestApi.domain = this.apiManager.createApiDomain(`${this.id}-api-domain`, this, this.isProductionStage() || this.props.skipStageForARecords
|
|
119
|
+
? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
|
|
120
|
+
: `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.apiToLambdaTargetRestApi.certificate);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @summary Method to create base path mappings for GraphQL API
|
|
124
|
+
* @protected
|
|
125
|
+
*/
|
|
126
|
+
createApiBasePathMapping() {
|
|
127
|
+
const apiRootPaths = this.props.apiRootPaths;
|
|
128
|
+
if (apiRootPaths && apiRootPaths.length > 0) {
|
|
129
|
+
apiRootPaths.forEach((apiRootPath) => {
|
|
130
|
+
this.apiToLambdaTargetRestApi.basePathMappings.push(new apig.BasePathMapping(this, `${this.id}-base-bath-mapping-${apiRootPath}`, {
|
|
131
|
+
basePath: apiRootPath,
|
|
132
|
+
domainName: this.apiToLambdaTargetRestApi.domain,
|
|
133
|
+
restApi: this.apiToLambdaTargetRestApi.api,
|
|
134
|
+
stage: this.apiToLambdaTargetRestApi.api.deploymentStage,
|
|
135
|
+
}));
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// add default mapping if apiRootPaths not set
|
|
140
|
+
new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
|
|
141
|
+
domainName: this.apiToLambdaTargetRestApi.domain,
|
|
142
|
+
restApi: this.apiToLambdaTargetRestApi.api,
|
|
143
|
+
stage: this.apiToLambdaTargetRestApi.api.deploymentStage,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @summary Method to create route53 records for Api
|
|
148
|
+
* @protected
|
|
149
|
+
*/
|
|
150
|
+
createApiRouteAssets() {
|
|
151
|
+
if (this.props.api.useExisting)
|
|
152
|
+
return;
|
|
153
|
+
this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.apiToLambdaTargetRestApi.domain, this.apiToLambdaTargetRestApi.hostedZone, this.props.skipStageForARecords);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.ApiToLambdaTarget = ApiToLambdaTarget;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './api-to-eventbridge-target';
|
|
2
2
|
export * from './api-to-eventbridge-target-with-sns';
|
|
3
|
+
export * from './api-to-lambda-target';
|
|
3
4
|
export * from './graphql-api-lambda';
|
|
4
5
|
export * from './graphql-api-lambda-with-cache';
|
|
5
6
|
export * from './site-with-ecs-backend';
|
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./api-to-eventbridge-target"), exports);
|
|
18
18
|
__exportStar(require("./api-to-eventbridge-target-with-sns"), exports);
|
|
19
|
+
__exportStar(require("./api-to-lambda-target"), exports);
|
|
19
20
|
__exportStar(require("./graphql-api-lambda"), exports);
|
|
20
21
|
__exportStar(require("./graphql-api-lambda-with-cache"), exports);
|
|
21
22
|
__exportStar(require("./site-with-ecs-backend"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
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 route53 from 'aws-cdk-lib/aws-route53';
|
|
5
|
+
import * as sns from 'aws-cdk-lib/aws-sns';
|
|
6
|
+
import * as types from '../types/aws';
|
|
7
|
+
/**
|
|
8
|
+
* @stability stable
|
|
9
|
+
* @category cdk-utils.api-to-lambda-target
|
|
10
|
+
* @subcategory member
|
|
11
|
+
* @classdesc Provides a construct to contain api resources for ApiToLambdaTarget
|
|
12
|
+
*/
|
|
13
|
+
export declare class ApiToLambdaTargetRestApi implements types.ApiToLambdaTargetRestApiType {
|
|
14
|
+
api: apig.RestApi;
|
|
15
|
+
basePathMappings: apig.BasePathMapping[];
|
|
16
|
+
certificate: acm.ICertificate;
|
|
17
|
+
domain: apig.DomainName;
|
|
18
|
+
errorResponseModel: apig.Model;
|
|
19
|
+
hostedZone: route53.IHostedZone;
|
|
20
|
+
integration: apig.Integration;
|
|
21
|
+
integrationErrorResponse: apig.IntegrationResponse;
|
|
22
|
+
integrationRequestParameters: {
|
|
23
|
+
[p: string]: string;
|
|
24
|
+
};
|
|
25
|
+
integrationRequestTemplates: {
|
|
26
|
+
[p: string]: string;
|
|
27
|
+
};
|
|
28
|
+
integrationResponse: apig.IntegrationResponse;
|
|
29
|
+
method: apig.Method;
|
|
30
|
+
methodErrorResponse: apig.MethodResponse;
|
|
31
|
+
methodResponse: apig.MethodResponse;
|
|
32
|
+
resource: apig.Resource;
|
|
33
|
+
responseModel: apig.Model;
|
|
34
|
+
topic: sns.Topic;
|
|
35
|
+
role: iam.Role;
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiToLambdaTargetRestApi = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @stability stable
|
|
6
|
+
* @category cdk-utils.api-to-lambda-target
|
|
7
|
+
* @subcategory member
|
|
8
|
+
* @classdesc Provides a construct to contain api resources for ApiToLambdaTarget
|
|
9
|
+
*/
|
|
10
|
+
class ApiToLambdaTargetRestApi {
|
|
11
|
+
api;
|
|
12
|
+
basePathMappings = [];
|
|
13
|
+
certificate;
|
|
14
|
+
domain;
|
|
15
|
+
errorResponseModel;
|
|
16
|
+
hostedZone;
|
|
17
|
+
integration;
|
|
18
|
+
integrationErrorResponse;
|
|
19
|
+
integrationRequestParameters;
|
|
20
|
+
integrationRequestTemplates;
|
|
21
|
+
integrationResponse;
|
|
22
|
+
method;
|
|
23
|
+
methodErrorResponse;
|
|
24
|
+
methodResponse;
|
|
25
|
+
resource;
|
|
26
|
+
responseModel;
|
|
27
|
+
topic;
|
|
28
|
+
role;
|
|
29
|
+
}
|
|
30
|
+
exports.ApiToLambdaTargetRestApi = ApiToLambdaTargetRestApi;
|
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./api-to-eventbridge-target-event"), exports);
|
|
18
18
|
__exportStar(require("./api-to-eventbridge-target-rest-api"), exports);
|
|
19
|
+
__exportStar(require("./api-to-lambda-target-rest-api"), exports);
|
|
@@ -31,7 +31,7 @@ export declare class ApiManager {
|
|
|
31
31
|
* @param {AcmProps} props lambda rest restApi props
|
|
32
32
|
* @param lambdaFunction
|
|
33
33
|
*/
|
|
34
|
-
createLambdaRestApi(id: string, scope: common.CommonConstruct, props: apig.LambdaRestApiProps, lambdaFunction: lambda.
|
|
34
|
+
createLambdaRestApi(id: string, scope: common.CommonConstruct, props: apig.LambdaRestApiProps, lambdaFunction: lambda.IFunction): apig.LambdaRestApi;
|
|
35
35
|
/**
|
|
36
36
|
* @summary Method to create custom restApi domain
|
|
37
37
|
* @param {string} id scoped id of the resource
|
|
@@ -272,6 +272,36 @@ export interface ApiToEventBridgeTargetRestApiType {
|
|
|
272
272
|
role?: iam.Role;
|
|
273
273
|
policy?: iam.PolicyDocument;
|
|
274
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* @category cdk-utils.api-to-lambda-target
|
|
277
|
+
* @subcategory Types
|
|
278
|
+
*/
|
|
279
|
+
export interface ApiToLambdaTargetRestApiType {
|
|
280
|
+
api: apig.IRestApi;
|
|
281
|
+
authoriser?: apig.IAuthorizer;
|
|
282
|
+
basePathMappings: apig.BasePathMapping[];
|
|
283
|
+
certificate: acm.ICertificate;
|
|
284
|
+
domain: apig.DomainName;
|
|
285
|
+
errorResponseModel: apig.Model;
|
|
286
|
+
hostedZone: route53.IHostedZone;
|
|
287
|
+
integration: apig.Integration;
|
|
288
|
+
integrationErrorResponse: apig.IntegrationResponse;
|
|
289
|
+
integrationRequestParameters: {
|
|
290
|
+
[p: string]: string;
|
|
291
|
+
};
|
|
292
|
+
integrationRequestTemplates: {
|
|
293
|
+
[p: string]: string;
|
|
294
|
+
};
|
|
295
|
+
integrationResponse: apig.IntegrationResponse;
|
|
296
|
+
method: apig.Method;
|
|
297
|
+
methodErrorResponse: apig.MethodResponse;
|
|
298
|
+
methodResponse: apig.MethodResponse;
|
|
299
|
+
resource: apig.Resource;
|
|
300
|
+
responseModel: apig.Model;
|
|
301
|
+
topic?: sns.ITopic;
|
|
302
|
+
role?: iam.Role;
|
|
303
|
+
policy?: iam.PolicyDocument;
|
|
304
|
+
}
|
|
275
305
|
/**
|
|
276
306
|
* @category cdk-utils.api-to-eventbridge-target
|
|
277
307
|
* @subcategory Types
|
|
@@ -345,6 +375,31 @@ export interface ApiToEventBridgeTargetProps extends CommonStackProps {
|
|
|
345
375
|
timezone: string;
|
|
346
376
|
useExistingHostedZone: boolean;
|
|
347
377
|
}
|
|
378
|
+
/**
|
|
379
|
+
* @category cdk-utils.api-to-lambda-target
|
|
380
|
+
* @subcategory Properties
|
|
381
|
+
*/
|
|
382
|
+
export interface ApiToLambdaTargetRestApiProps {
|
|
383
|
+
certificate: AcmProps;
|
|
384
|
+
restApi: apig.LambdaRestApiProps;
|
|
385
|
+
importedRestApiRef?: string;
|
|
386
|
+
importedRestApiRootResourceRef?: string;
|
|
387
|
+
useExisting: boolean;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* @category cdk-utils.api-to-lambda-target
|
|
391
|
+
* @subcategory Properties
|
|
392
|
+
*/
|
|
393
|
+
export interface ApiToLambdaTargetProps extends CommonStackProps {
|
|
394
|
+
apiRootPaths?: string[];
|
|
395
|
+
apiSubDomain: string;
|
|
396
|
+
api: ApiToLambdaTargetRestApiProps;
|
|
397
|
+
lambdaFunctionName: string;
|
|
398
|
+
logLevel: string;
|
|
399
|
+
nodeEnv: string;
|
|
400
|
+
timezone: string;
|
|
401
|
+
useExistingHostedZone: boolean;
|
|
402
|
+
}
|
|
348
403
|
/**
|
|
349
404
|
* @category cdk-utils.acm-manager
|
|
350
405
|
* @subcategory Properties
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './main'
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import * as cdk from 'aws-cdk-lib'
|
|
2
|
+
import * as apig from 'aws-cdk-lib/aws-apigateway'
|
|
3
|
+
import * as lambda from 'aws-cdk-lib/aws-lambda'
|
|
4
|
+
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
|
|
5
|
+
import { Construct } from 'constructs'
|
|
6
|
+
import { CommonConstruct } from '../../common'
|
|
7
|
+
import * as helper from '../../helper'
|
|
8
|
+
import * as types from '../../types/aws'
|
|
9
|
+
|
|
10
|
+
export class ApiToLambdaTarget extends CommonConstruct {
|
|
11
|
+
props: types.ApiToLambdaTargetProps
|
|
12
|
+
id: string
|
|
13
|
+
|
|
14
|
+
/* application related resources */
|
|
15
|
+
applicationSecrets: secretsmanager.ISecret[]
|
|
16
|
+
|
|
17
|
+
/* rest restApi related resources */
|
|
18
|
+
apiToLambdaTargetRestApi: types.ApiToLambdaTargetRestApiType
|
|
19
|
+
|
|
20
|
+
constructor(parent: Construct, id: string, props: types.ApiToLambdaTargetProps) {
|
|
21
|
+
super(parent, id, props)
|
|
22
|
+
|
|
23
|
+
this.props = props
|
|
24
|
+
this.id = id
|
|
25
|
+
|
|
26
|
+
this.apiToLambdaTargetRestApi = new helper.ApiToLambdaTargetRestApi()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected initResources() {
|
|
30
|
+
/* application related resources */
|
|
31
|
+
this.resolveSecrets()
|
|
32
|
+
|
|
33
|
+
/* core resources */
|
|
34
|
+
this.resolveHostedZone()
|
|
35
|
+
this.resolveCertificate()
|
|
36
|
+
|
|
37
|
+
/* restApi related resources */
|
|
38
|
+
this.createApiToLambdaTargetRestApi()
|
|
39
|
+
this.createApiDomain()
|
|
40
|
+
this.createApiBasePathMapping()
|
|
41
|
+
this.createApiRouteAssets()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @summary Method to resolve secrets from SecretsManager
|
|
46
|
+
* - To be implemented in the overriding method in the implementation class
|
|
47
|
+
* @protected
|
|
48
|
+
*/
|
|
49
|
+
protected resolveSecrets() {
|
|
50
|
+
this.applicationSecrets = []
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @summary Method to resolve a hosted zone based on domain attributes
|
|
55
|
+
* @protected
|
|
56
|
+
*/
|
|
57
|
+
protected resolveHostedZone() {
|
|
58
|
+
this.apiToLambdaTargetRestApi.hostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(
|
|
59
|
+
`${this.id}-hosted-zone`,
|
|
60
|
+
this,
|
|
61
|
+
this.props.useExistingHostedZone
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @summary Method to resolve a certificate based on attributes
|
|
67
|
+
* @protected
|
|
68
|
+
*/
|
|
69
|
+
protected resolveCertificate() {
|
|
70
|
+
if (this.props.api.useExisting) return
|
|
71
|
+
if (
|
|
72
|
+
this.props.api.certificate.useExistingCertificate &&
|
|
73
|
+
this.props.api.certificate.certificateSsmName &&
|
|
74
|
+
this.props.api.certificate.certificateRegion
|
|
75
|
+
) {
|
|
76
|
+
this.props.api.certificate.certificateArn = this.ssmManager.readStringParameterFromRegion(
|
|
77
|
+
`${this.id}-certificate-param`,
|
|
78
|
+
this,
|
|
79
|
+
this.props.api.certificate.certificateSsmName,
|
|
80
|
+
this.props.api.certificate.certificateRegion
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.apiToLambdaTargetRestApi.certificate = this.acmManager.resolveCertificate(
|
|
85
|
+
`${this.id}-certificate`,
|
|
86
|
+
this,
|
|
87
|
+
this.props.api.certificate
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @summary Method to create rest restApi for Api
|
|
93
|
+
* @protected
|
|
94
|
+
*/
|
|
95
|
+
protected createApiToLambdaTargetRestApi() {
|
|
96
|
+
if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
|
|
97
|
+
this.apiToLambdaTargetRestApi.api = apig.RestApi.fromRestApiId(
|
|
98
|
+
this,
|
|
99
|
+
`${this.id}-rest-api`,
|
|
100
|
+
cdk.Fn.importValue(this.props.api.importedRestApiRef)
|
|
101
|
+
)
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
|
|
106
|
+
logGroupName: `/custom/api/${this.id}-rest-api-access`,
|
|
107
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
this.props.api.restApi = {
|
|
111
|
+
...this.props.api.restApi,
|
|
112
|
+
...{
|
|
113
|
+
deployOptions: {
|
|
114
|
+
accessLogDestination: new apig.LogGroupLogDestination(accessLogGroup),
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this.apiToLambdaTargetRestApi.api = this.apiManager.createLambdaRestApi(
|
|
120
|
+
`${this.id}-lambda-rest-api`,
|
|
121
|
+
this,
|
|
122
|
+
this.props.api.restApi,
|
|
123
|
+
lambda.Function.fromFunctionName(this, `${this.id}-lambda`, this.props.lambdaFunctionName)
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
this.addCfnOutput(`${this.id}-restApiId`, this.apiToLambdaTargetRestApi.api.restApiId)
|
|
127
|
+
this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToLambdaTargetRestApi.api.root.resourceId)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @summary Method to create custom restApi domain for Api API
|
|
132
|
+
* @protected
|
|
133
|
+
*/
|
|
134
|
+
protected createApiDomain() {
|
|
135
|
+
if (this.props.api.useExisting) return
|
|
136
|
+
this.apiToLambdaTargetRestApi.domain = this.apiManager.createApiDomain(
|
|
137
|
+
`${this.id}-api-domain`,
|
|
138
|
+
this,
|
|
139
|
+
this.isProductionStage() || this.props.skipStageForARecords
|
|
140
|
+
? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
|
|
141
|
+
: `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`,
|
|
142
|
+
this.apiToLambdaTargetRestApi.certificate
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @summary Method to create base path mappings for GraphQL API
|
|
148
|
+
* @protected
|
|
149
|
+
*/
|
|
150
|
+
protected createApiBasePathMapping() {
|
|
151
|
+
const apiRootPaths = this.props.apiRootPaths
|
|
152
|
+
if (apiRootPaths && apiRootPaths.length > 0) {
|
|
153
|
+
apiRootPaths.forEach((apiRootPath: string) => {
|
|
154
|
+
this.apiToLambdaTargetRestApi.basePathMappings.push(
|
|
155
|
+
new apig.BasePathMapping(this, `${this.id}-base-bath-mapping-${apiRootPath}`, {
|
|
156
|
+
basePath: apiRootPath,
|
|
157
|
+
domainName: this.apiToLambdaTargetRestApi.domain,
|
|
158
|
+
restApi: this.apiToLambdaTargetRestApi.api,
|
|
159
|
+
stage: this.apiToLambdaTargetRestApi.api.deploymentStage,
|
|
160
|
+
})
|
|
161
|
+
)
|
|
162
|
+
})
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// add default mapping if apiRootPaths not set
|
|
167
|
+
new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
|
|
168
|
+
domainName: this.apiToLambdaTargetRestApi.domain,
|
|
169
|
+
restApi: this.apiToLambdaTargetRestApi.api,
|
|
170
|
+
stage: this.apiToLambdaTargetRestApi.api.deploymentStage,
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @summary Method to create route53 records for Api
|
|
176
|
+
* @protected
|
|
177
|
+
*/
|
|
178
|
+
protected createApiRouteAssets() {
|
|
179
|
+
if (this.props.api.useExisting) return
|
|
180
|
+
this.route53Manager.createApiGatewayARecord(
|
|
181
|
+
`${this.id}-custom-domain-a-record`,
|
|
182
|
+
this,
|
|
183
|
+
this.props.apiSubDomain,
|
|
184
|
+
this.apiToLambdaTargetRestApi.domain,
|
|
185
|
+
this.apiToLambdaTargetRestApi.hostedZone,
|
|
186
|
+
this.props.skipStageForARecords
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './api-to-eventbridge-target'
|
|
2
2
|
export * from './api-to-eventbridge-target-with-sns'
|
|
3
|
+
export * from './api-to-lambda-target'
|
|
3
4
|
export * from './graphql-api-lambda'
|
|
4
5
|
export * from './graphql-api-lambda-with-cache'
|
|
5
6
|
export * from './site-with-ecs-backend'
|
|
@@ -0,0 +1,33 @@
|
|
|
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 route53 from 'aws-cdk-lib/aws-route53'
|
|
5
|
+
import * as sns from 'aws-cdk-lib/aws-sns'
|
|
6
|
+
import * as types from '../types/aws'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @stability stable
|
|
10
|
+
* @category cdk-utils.api-to-lambda-target
|
|
11
|
+
* @subcategory member
|
|
12
|
+
* @classdesc Provides a construct to contain api resources for ApiToLambdaTarget
|
|
13
|
+
*/
|
|
14
|
+
export class ApiToLambdaTargetRestApi implements types.ApiToLambdaTargetRestApiType {
|
|
15
|
+
api: apig.RestApi
|
|
16
|
+
basePathMappings: apig.BasePathMapping[] = []
|
|
17
|
+
certificate: acm.ICertificate
|
|
18
|
+
domain: apig.DomainName
|
|
19
|
+
errorResponseModel: apig.Model
|
|
20
|
+
hostedZone: route53.IHostedZone
|
|
21
|
+
integration: apig.Integration
|
|
22
|
+
integrationErrorResponse: apig.IntegrationResponse
|
|
23
|
+
integrationRequestParameters: { [p: string]: string }
|
|
24
|
+
integrationRequestTemplates: { [p: string]: string }
|
|
25
|
+
integrationResponse: apig.IntegrationResponse
|
|
26
|
+
method: apig.Method
|
|
27
|
+
methodErrorResponse: apig.MethodResponse
|
|
28
|
+
methodResponse: apig.MethodResponse
|
|
29
|
+
resource: apig.Resource
|
|
30
|
+
responseModel: apig.Model
|
|
31
|
+
topic: sns.Topic
|
|
32
|
+
role: iam.Role
|
|
33
|
+
}
|
package/src/lib/helper/index.ts
CHANGED
|
@@ -37,7 +37,7 @@ export class ApiManager {
|
|
|
37
37
|
id: string,
|
|
38
38
|
scope: common.CommonConstruct,
|
|
39
39
|
props: apig.LambdaRestApiProps,
|
|
40
|
-
lambdaFunction: lambda.
|
|
40
|
+
lambdaFunction: lambda.IFunction
|
|
41
41
|
) {
|
|
42
42
|
const api = new apig.LambdaRestApi(scope, `${id}`, {
|
|
43
43
|
binaryMediaTypes: props.binaryMediaTypes,
|
|
@@ -288,6 +288,33 @@ export interface ApiToEventBridgeTargetRestApiType {
|
|
|
288
288
|
policy?: iam.PolicyDocument
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
/**
|
|
292
|
+
* @category cdk-utils.api-to-lambda-target
|
|
293
|
+
* @subcategory Types
|
|
294
|
+
*/
|
|
295
|
+
export interface ApiToLambdaTargetRestApiType {
|
|
296
|
+
api: apig.IRestApi
|
|
297
|
+
authoriser?: apig.IAuthorizer
|
|
298
|
+
basePathMappings: apig.BasePathMapping[]
|
|
299
|
+
certificate: acm.ICertificate
|
|
300
|
+
domain: apig.DomainName
|
|
301
|
+
errorResponseModel: apig.Model
|
|
302
|
+
hostedZone: route53.IHostedZone
|
|
303
|
+
integration: apig.Integration
|
|
304
|
+
integrationErrorResponse: apig.IntegrationResponse
|
|
305
|
+
integrationRequestParameters: { [p: string]: string }
|
|
306
|
+
integrationRequestTemplates: { [p: string]: string }
|
|
307
|
+
integrationResponse: apig.IntegrationResponse
|
|
308
|
+
method: apig.Method
|
|
309
|
+
methodErrorResponse: apig.MethodResponse
|
|
310
|
+
methodResponse: apig.MethodResponse
|
|
311
|
+
resource: apig.Resource
|
|
312
|
+
responseModel: apig.Model
|
|
313
|
+
topic?: sns.ITopic
|
|
314
|
+
role?: iam.Role
|
|
315
|
+
policy?: iam.PolicyDocument
|
|
316
|
+
}
|
|
317
|
+
|
|
291
318
|
/**
|
|
292
319
|
* @category cdk-utils.api-to-eventbridge-target
|
|
293
320
|
* @subcategory Types
|
|
@@ -366,6 +393,33 @@ export interface ApiToEventBridgeTargetProps extends CommonStackProps {
|
|
|
366
393
|
useExistingHostedZone: boolean
|
|
367
394
|
}
|
|
368
395
|
|
|
396
|
+
/**
|
|
397
|
+
* @category cdk-utils.api-to-lambda-target
|
|
398
|
+
* @subcategory Properties
|
|
399
|
+
*/
|
|
400
|
+
export interface ApiToLambdaTargetRestApiProps {
|
|
401
|
+
certificate: AcmProps
|
|
402
|
+
restApi: apig.LambdaRestApiProps
|
|
403
|
+
importedRestApiRef?: string
|
|
404
|
+
importedRestApiRootResourceRef?: string
|
|
405
|
+
useExisting: boolean
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* @category cdk-utils.api-to-lambda-target
|
|
410
|
+
* @subcategory Properties
|
|
411
|
+
*/
|
|
412
|
+
export interface ApiToLambdaTargetProps extends CommonStackProps {
|
|
413
|
+
apiRootPaths?: string[]
|
|
414
|
+
apiSubDomain: string
|
|
415
|
+
api: ApiToLambdaTargetRestApiProps
|
|
416
|
+
lambdaFunctionName: string
|
|
417
|
+
logLevel: string
|
|
418
|
+
nodeEnv: string
|
|
419
|
+
timezone: string
|
|
420
|
+
useExistingHostedZone: boolean
|
|
421
|
+
}
|
|
422
|
+
|
|
369
423
|
/**
|
|
370
424
|
* @category cdk-utils.acm-manager
|
|
371
425
|
* @subcategory Properties
|