@gradientedge/cdk-utils 8.158.0 → 8.160.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/api-destined-function/package.json +1 -1
- package/dist/src/lib/aws/construct/index.d.ts +0 -2
- package/dist/src/lib/aws/construct/index.js +0 -2
- package/dist/src/lib/aws/construct/rest-api-lambda/main.d.ts +0 -4
- package/dist/src/lib/aws/construct/rest-api-lambda/main.js +0 -7
- package/dist/src/lib/aws/services/elastic-container-service/main.js +0 -3
- package/dist/src/lib/aws/services/elastic-container-service/types.d.ts +9 -2
- package/dist/src/lib/aws/services/lambda/main.js +13 -4
- package/eslint.config.mjs +5 -0
- package/package.json +29 -29
- package/src/lib/aws/construct/index.ts +0 -2
- package/src/lib/aws/construct/rest-api-lambda/main.ts +0 -8
- package/src/lib/aws/services/elastic-container-service/main.ts +0 -3
- package/src/lib/aws/services/elastic-container-service/types.ts +16 -2
- package/src/lib/aws/services/lambda/main.ts +15 -4
- package/dist/src/lib/aws/construct/graphql-api-lambda/index.d.ts +0 -2
- package/dist/src/lib/aws/construct/graphql-api-lambda/index.js +0 -18
- package/dist/src/lib/aws/construct/graphql-api-lambda/main.d.ts +0 -96
- package/dist/src/lib/aws/construct/graphql-api-lambda/main.js +0 -177
- package/dist/src/lib/aws/construct/graphql-api-lambda/types.d.ts +0 -26
- package/dist/src/lib/aws/construct/graphql-api-lambda/types.js +0 -2
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/index.d.ts +0 -2
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/index.js +0 -18
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/main.d.ts +0 -57
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/main.js +0 -137
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/types.d.ts +0 -12
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/types.js +0 -2
- package/src/lib/aws/construct/graphql-api-lambda/index.ts +0 -2
- package/src/lib/aws/construct/graphql-api-lambda/main.ts +0 -244
- package/src/lib/aws/construct/graphql-api-lambda/types.ts +0 -27
- package/src/lib/aws/construct/graphql-api-lambda-with-cache/index.ts +0 -2
- package/src/lib/aws/construct/graphql-api-lambda-with-cache/main.ts +0 -147
- package/src/lib/aws/construct/graphql-api-lambda-with-cache/types.ts +0 -13
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GraphQLApiLambda = void 0;
|
|
7
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
|
8
|
-
const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
|
9
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
const common_1 = require("../../common");
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated Use RestApiLambda instead. This will be removed in a future release.
|
|
13
|
-
* @classdesc Provides a construct to create and deploy a Graphql API as Lambda
|
|
14
|
-
*
|
|
15
|
-
* <b>Architecture</b><br/> 
|
|
16
|
-
* @example
|
|
17
|
-
* import { GraphQLApiLambda, GraphQlApiLambdaProps } '@gradientedge/cdk-utils'
|
|
18
|
-
* import { Construct } from 'constructs'
|
|
19
|
-
*
|
|
20
|
-
* class CustomConstruct extends GraphQLApiLambda {
|
|
21
|
-
* constructor(parent: Construct, id: string, props: GraphQlApiLambdaProps) {
|
|
22
|
-
* super(parent, id, props)
|
|
23
|
-
* this.props = props
|
|
24
|
-
* this.id = id
|
|
25
|
-
* this.initResources()
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
*/
|
|
29
|
-
class GraphQLApiLambda extends common_1.CommonConstruct {
|
|
30
|
-
/* graphql restApi props */
|
|
31
|
-
props;
|
|
32
|
-
id;
|
|
33
|
-
/* graphql restApi resources */
|
|
34
|
-
applicationSecrets;
|
|
35
|
-
graphQLApiLambdaPolicy;
|
|
36
|
-
graphQLApiLambdaRole;
|
|
37
|
-
graphQLApiLambdaEnvironment;
|
|
38
|
-
graphQLApiLambdaLayers = [];
|
|
39
|
-
graphQLApiLambdaFunction;
|
|
40
|
-
graphQLApi;
|
|
41
|
-
graphQLApiHostedZone;
|
|
42
|
-
graphQLApiCertificate;
|
|
43
|
-
graphQLApiDomain;
|
|
44
|
-
graphQLApiBasePathMappings = [];
|
|
45
|
-
constructor(parent, id, props) {
|
|
46
|
-
super(parent, id, props);
|
|
47
|
-
this.props = props;
|
|
48
|
-
this.id = id;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @summary Initialise and provision resources
|
|
52
|
-
*/
|
|
53
|
-
initResources() {
|
|
54
|
-
this.resolveSecrets();
|
|
55
|
-
this.resolveHostedZone();
|
|
56
|
-
this.resolveCertificate();
|
|
57
|
-
this.createLambdaPolicy();
|
|
58
|
-
this.createLambdaRole();
|
|
59
|
-
this.createLambdaEnvironment();
|
|
60
|
-
this.createLambdaLayers();
|
|
61
|
-
this.createLambdaFunction();
|
|
62
|
-
this.createRestApi();
|
|
63
|
-
this.createApiDomain();
|
|
64
|
-
this.createApiBasePathMapping();
|
|
65
|
-
this.createApiRouteAssets();
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @summary Method to resolve secrets from SecretsManager
|
|
69
|
-
* - To be implemented in the overriding method in the implementation class
|
|
70
|
-
*/
|
|
71
|
-
resolveSecrets() {
|
|
72
|
-
this.applicationSecrets = [];
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* @summary Method to resolve a hosted zone based on domain attributes
|
|
76
|
-
*/
|
|
77
|
-
resolveHostedZone() {
|
|
78
|
-
this.graphQLApiHostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(`${this.id}-hosted-zone`, this, this.props.useExistingHostedZone);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @summary Method to resolve a certificate based on attributes
|
|
82
|
-
*/
|
|
83
|
-
resolveCertificate() {
|
|
84
|
-
if (this.props.graphQLApiCertificate.useExistingCertificate &&
|
|
85
|
-
this.props.graphQLApiCertificate.certificateSsmName &&
|
|
86
|
-
this.props.graphQLApiCertificate.certificateRegion) {
|
|
87
|
-
this.props.graphQLApiCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-param`, this, this.props.graphQLApiCertificate.certificateSsmName, this.props.graphQLApiCertificate.certificateRegion);
|
|
88
|
-
}
|
|
89
|
-
this.graphQLApiCertificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.graphQLApiCertificate);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @summary Method to create iam policy for GraphQL Lambda function
|
|
93
|
-
*/
|
|
94
|
-
createLambdaPolicy() {
|
|
95
|
-
this.graphQLApiLambdaPolicy = new aws_iam_1.PolicyDocument({
|
|
96
|
-
statements: [this.iamManager.statementForCreateAnyLogStream()],
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* @summary Method to create iam role for GraphQL Lambda function
|
|
101
|
-
*/
|
|
102
|
-
createLambdaRole() {
|
|
103
|
-
this.graphQLApiLambdaRole = this.iamManager.createRoleForLambda(`${this.id}-lambda-role`, this, this.graphQLApiLambdaPolicy);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* @summary Method to create environment variables for GraphQL Lambda function
|
|
107
|
-
*/
|
|
108
|
-
createLambdaEnvironment() {
|
|
109
|
-
this.graphQLApiLambdaEnvironment = {
|
|
110
|
-
LOG_LEVEL: this.props.logLevel,
|
|
111
|
-
NODE_ENV: this.props.nodeEnv,
|
|
112
|
-
TZ: this.props.timezone,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* @summary Method to create layers for GraphQL Lambda function
|
|
117
|
-
*/
|
|
118
|
-
createLambdaLayers() {
|
|
119
|
-
const layers = [];
|
|
120
|
-
if (!this.props.graphqlApiLambdaLayerSources)
|
|
121
|
-
return;
|
|
122
|
-
lodash_1.default.forEach(this.props.graphqlApiLambdaLayerSources, (source, index) => {
|
|
123
|
-
layers.push(this.lambdaManager.createLambdaLayer(`${this.id}-layer-${index}`, this, source));
|
|
124
|
-
});
|
|
125
|
-
this.graphQLApiLambdaLayers = layers;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* @summary Method to create lambda function for GraphQL
|
|
129
|
-
*/
|
|
130
|
-
createLambdaFunction() {
|
|
131
|
-
this.graphQLApiLambdaFunction = this.lambdaManager.createLambdaFunction(`${this.id}-graphql-server`, this, this.props.graphqlApi, this.graphQLApiLambdaRole, this.graphQLApiLambdaLayers, this.props.graphQLApiSource, this.props.graphQLApiHandler || 'index.handler', this.graphQLApiLambdaEnvironment);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* @summary Method to create rest restApi for GraphQL
|
|
135
|
-
*/
|
|
136
|
-
createRestApi() {
|
|
137
|
-
this.graphQLApi = this.apiManager.createLambdaRestApi(`${this.id}-lambda-rest-api`, this, this.props.graphqlRestApi, this.graphQLApiLambdaFunction);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* @summary Method to create custom restApi domain for GraphQL API
|
|
141
|
-
*/
|
|
142
|
-
createApiDomain() {
|
|
143
|
-
this.graphQLApiDomain = this.apiManager.createApiDomain(`${this.id}-api-domain`, this, this.isProductionStage() || this.props.skipStageForARecords
|
|
144
|
-
? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
|
|
145
|
-
: `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.graphQLApiCertificate);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* @summary Method to create base path mappings for GraphQL API
|
|
149
|
-
*/
|
|
150
|
-
createApiBasePathMapping() {
|
|
151
|
-
const apiRootPaths = this.props.apiRootPaths;
|
|
152
|
-
if (apiRootPaths && !lodash_1.default.isEmpty(apiRootPaths)) {
|
|
153
|
-
lodash_1.default.forEach(apiRootPaths, (apiRootPath) => {
|
|
154
|
-
this.graphQLApiBasePathMappings.push(new aws_apigateway_1.BasePathMapping(this, `${this.id}-base-bath-mapping-${apiRootPath}`, {
|
|
155
|
-
basePath: apiRootPath,
|
|
156
|
-
domainName: this.graphQLApiDomain,
|
|
157
|
-
restApi: this.graphQLApi,
|
|
158
|
-
stage: this.graphQLApi.deploymentStage,
|
|
159
|
-
}));
|
|
160
|
-
});
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
// add default mapping if apiRootPaths not set
|
|
164
|
-
new aws_apigateway_1.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
|
|
165
|
-
domainName: this.graphQLApiDomain,
|
|
166
|
-
restApi: this.graphQLApi,
|
|
167
|
-
stage: this.graphQLApi.deploymentStage,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* @summary Method to create route53 records for GraphQL API
|
|
172
|
-
*/
|
|
173
|
-
createApiRouteAssets() {
|
|
174
|
-
this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.graphQLApiDomain, this.graphQLApiHostedZone, this.props.skipStageForARecords);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.GraphQLApiLambda = GraphQLApiLambda;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { CommonStackProps } from '../../common';
|
|
2
|
-
import { AcmProps, LambdaEnvironment, LambdaProps } from '../../services';
|
|
3
|
-
import { LambdaRestApiProps } from 'aws-cdk-lib/aws-apigateway';
|
|
4
|
-
import { AssetCode } from 'aws-cdk-lib/aws-lambda';
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use RestApiLambdaEnvironment instead. This will be removed in a future release.
|
|
7
|
-
*/
|
|
8
|
-
export interface GraphQlApiLambdaEnvironment extends LambdaEnvironment {
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Use RestApiLambdaProps instead. This will be removed in a future release.
|
|
12
|
-
*/
|
|
13
|
-
export interface GraphQlApiLambdaProps extends CommonStackProps {
|
|
14
|
-
apiRootPaths?: string[];
|
|
15
|
-
apiSubDomain: string;
|
|
16
|
-
graphQLApiCertificate: AcmProps;
|
|
17
|
-
graphQLApiHandler: string;
|
|
18
|
-
graphQLApiSource: AssetCode;
|
|
19
|
-
graphqlApi: LambdaProps;
|
|
20
|
-
graphqlApiLambdaLayerSources?: AssetCode[];
|
|
21
|
-
graphqlRestApi: LambdaRestApiProps;
|
|
22
|
-
logLevel: string;
|
|
23
|
-
nodeEnv: string;
|
|
24
|
-
timezone: string;
|
|
25
|
-
useExistingHostedZone: boolean;
|
|
26
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
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);
|
|
18
|
-
__exportStar(require("./types"), exports);
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ISecurityGroup, IVpc } from 'aws-cdk-lib/aws-ec2';
|
|
2
|
-
import { CfnReplicationGroup } from 'aws-cdk-lib/aws-elasticache';
|
|
3
|
-
import { Construct } from 'constructs';
|
|
4
|
-
import { GraphQLApiLambda } from '..';
|
|
5
|
-
import { GraphQlApiLambdaWithCacheProps } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Use RestApiLambdaWithCache instead. This will be removed in a future release.
|
|
8
|
-
* @classdesc Provides a construct to create and deploy a Graphql API as Lambda with Caching
|
|
9
|
-
*
|
|
10
|
-
* <b>Architecture</b><br/> 
|
|
11
|
-
* @example
|
|
12
|
-
* import { GraphQlApiLambdaWithCacheProps } '@gradientedge/cdk-utils'
|
|
13
|
-
* import { Construct } from 'constructs'
|
|
14
|
-
*
|
|
15
|
-
* class CustomConstruct extends GraphQLApiLambdaWithCache {
|
|
16
|
-
* constructor(parent: Construct, id: string, props: GraphQlApiLambdaWithCacheProps) {
|
|
17
|
-
* super(parent, id, props)
|
|
18
|
-
* this.props = props
|
|
19
|
-
* this.id = id
|
|
20
|
-
* this.initResources()
|
|
21
|
-
* }
|
|
22
|
-
* }
|
|
23
|
-
*/
|
|
24
|
-
export declare class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
|
|
25
|
-
props: GraphQlApiLambdaWithCacheProps;
|
|
26
|
-
id: string;
|
|
27
|
-
graphQLVpc: IVpc;
|
|
28
|
-
graphQLElastiCache: CfnReplicationGroup;
|
|
29
|
-
graphQLSecurityGroup: ISecurityGroup;
|
|
30
|
-
securityGroupExportName: string;
|
|
31
|
-
constructor(parent: Construct, id: string, props: GraphQlApiLambdaWithCacheProps);
|
|
32
|
-
protected initResources(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Create VPC
|
|
35
|
-
*/
|
|
36
|
-
protected setVpc(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Resolve Security Group
|
|
39
|
-
*/
|
|
40
|
-
protected setSecurityGroup(): void;
|
|
41
|
-
/**
|
|
42
|
-
* Create ElastiCache
|
|
43
|
-
*/
|
|
44
|
-
protected createElastiCache(): void;
|
|
45
|
-
/**
|
|
46
|
-
* Create Lambda Role
|
|
47
|
-
*/
|
|
48
|
-
protected createLambdaRole(): void;
|
|
49
|
-
/**
|
|
50
|
-
* @summary Method to create environment variables for GraphQL Lambda function
|
|
51
|
-
*/
|
|
52
|
-
protected createLambdaEnvironment(): void;
|
|
53
|
-
/**
|
|
54
|
-
* @summary Method to create lambda function for GraphQL API
|
|
55
|
-
*/
|
|
56
|
-
protected createLambdaFunction(): void;
|
|
57
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.GraphQLApiLambdaWithCache = void 0;
|
|
30
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
31
|
-
const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
|
|
32
|
-
const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
|
33
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
34
|
-
const __1 = require("..");
|
|
35
|
-
const utils = __importStar(require("../../utils"));
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated Use RestApiLambdaWithCache instead. This will be removed in a future release.
|
|
38
|
-
* @classdesc Provides a construct to create and deploy a Graphql API as Lambda with Caching
|
|
39
|
-
*
|
|
40
|
-
* <b>Architecture</b><br/> 
|
|
41
|
-
* @example
|
|
42
|
-
* import { GraphQlApiLambdaWithCacheProps } '@gradientedge/cdk-utils'
|
|
43
|
-
* import { Construct } from 'constructs'
|
|
44
|
-
*
|
|
45
|
-
* class CustomConstruct extends GraphQLApiLambdaWithCache {
|
|
46
|
-
* constructor(parent: Construct, id: string, props: GraphQlApiLambdaWithCacheProps) {
|
|
47
|
-
* super(parent, id, props)
|
|
48
|
-
* this.props = props
|
|
49
|
-
* this.id = id
|
|
50
|
-
* this.initResources()
|
|
51
|
-
* }
|
|
52
|
-
* }
|
|
53
|
-
*/
|
|
54
|
-
class GraphQLApiLambdaWithCache extends __1.GraphQLApiLambda {
|
|
55
|
-
/* graphql restApi props */
|
|
56
|
-
props;
|
|
57
|
-
id;
|
|
58
|
-
/* graphql restApi resources */
|
|
59
|
-
graphQLVpc;
|
|
60
|
-
graphQLElastiCache;
|
|
61
|
-
graphQLSecurityGroup;
|
|
62
|
-
securityGroupExportName;
|
|
63
|
-
constructor(parent, id, props) {
|
|
64
|
-
super(parent, id, props);
|
|
65
|
-
this.props = props;
|
|
66
|
-
this.id = id;
|
|
67
|
-
}
|
|
68
|
-
initResources() {
|
|
69
|
-
this.setVpc();
|
|
70
|
-
this.setSecurityGroup();
|
|
71
|
-
this.createElastiCache();
|
|
72
|
-
super.initResources();
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Create VPC
|
|
76
|
-
*/
|
|
77
|
-
setVpc() {
|
|
78
|
-
if (this.props.useExistingVpc) {
|
|
79
|
-
this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
this.graphQLVpc = this.vpcManager.createCommonVpc(this, this.props.graphQLVpc, this.props.graphQLVpc.vpcName);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Resolve Security Group
|
|
87
|
-
*/
|
|
88
|
-
setSecurityGroup() {
|
|
89
|
-
if (this.props.securityGroupExportName) {
|
|
90
|
-
this.graphQLSecurityGroup = aws_ec2_1.SecurityGroup.fromSecurityGroupId(this, `${this.id}`, aws_cdk_lib_1.Fn.importValue(this.props.securityGroupExportName));
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
this.graphQLSecurityGroup = new aws_ec2_1.SecurityGroup(this, `${this.id}-security-group-${this.props.stage}`, {
|
|
94
|
-
securityGroupName: `${this.id}-security-group-${this.props.stage}`,
|
|
95
|
-
vpc: this.graphQLVpc,
|
|
96
|
-
});
|
|
97
|
-
this.graphQLSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv4(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
|
|
98
|
-
if (this.props.graphQLVpc.isIPV6) {
|
|
99
|
-
this.graphQLSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv6(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
this.graphQLSecurityGroup.addIngressRule(aws_ec2_1.Peer.anyIpv4(), aws_ec2_1.Port.allTraffic(), 'All Traffic');
|
|
103
|
-
}
|
|
104
|
-
utils.createCfnOutput(`${this.id}-security-group-id`, this, this.graphQLSecurityGroup.securityGroupId);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Create ElastiCache
|
|
109
|
-
*/
|
|
110
|
-
createElastiCache() {
|
|
111
|
-
this.graphQLElastiCache = this.elasticacheManager.createReplicatedElastiCache(`${this.id}-elasticache`, this, this.props.graphQLElastiCache, lodash_1.default.map(this.graphQLVpc.privateSubnets, subnet => subnet.subnetId), [this.graphQLSecurityGroup.securityGroupId]);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Create Lambda Role
|
|
115
|
-
*/
|
|
116
|
-
createLambdaRole() {
|
|
117
|
-
super.createLambdaRole();
|
|
118
|
-
this.graphQLApiLambdaRole.addManagedPolicy(aws_iam_1.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaVPCAccessExecutionRole'));
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* @summary Method to create environment variables for GraphQL Lambda function
|
|
122
|
-
*/
|
|
123
|
-
createLambdaEnvironment() {
|
|
124
|
-
this.graphQLApiLambdaEnvironment = {
|
|
125
|
-
LOG_LEVEL: this.props.logLevel,
|
|
126
|
-
NODE_ENV: this.props.nodeEnv,
|
|
127
|
-
TZ: this.props.timezone,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* @summary Method to create lambda function for GraphQL API
|
|
132
|
-
*/
|
|
133
|
-
createLambdaFunction() {
|
|
134
|
-
this.graphQLApiLambdaFunction = this.lambdaManager.createLambdaFunction(`${this.id}-graphql-server`, this, this.props.graphqlApi, this.graphQLApiLambdaRole, this.graphQLApiLambdaLayers, this.props.graphQLApiSource, this.props.graphQLApiHandler || 'index.handler', this.graphQLApiLambdaEnvironment, this.graphQLVpc, [this.graphQLSecurityGroup], undefined, undefined, this.graphQLVpc);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.GraphQLApiLambdaWithCache = GraphQLApiLambdaWithCache;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ReplicatedElastiCacheProps, VpcProps } from '../../services';
|
|
2
|
-
import { GraphQlApiLambdaProps } from '../graphql-api-lambda';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Use RestApiLambdaWithCacheProps instead. This will be removed in a future release.
|
|
5
|
-
*/
|
|
6
|
-
export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
|
|
7
|
-
graphQLElastiCache: ReplicatedElastiCacheProps;
|
|
8
|
-
graphQLVpc: VpcProps;
|
|
9
|
-
securityGroupExportName: string;
|
|
10
|
-
useExistingVpc: boolean;
|
|
11
|
-
vpcName?: string;
|
|
12
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import { BasePathMapping, DomainName, RestApi } from 'aws-cdk-lib/aws-apigateway'
|
|
2
|
-
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
|
|
3
|
-
import { PolicyDocument, Role } from 'aws-cdk-lib/aws-iam'
|
|
4
|
-
import { AssetCode, IFunction, ILayerVersion, LayerVersion } from 'aws-cdk-lib/aws-lambda'
|
|
5
|
-
import { IHostedZone } from 'aws-cdk-lib/aws-route53'
|
|
6
|
-
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'
|
|
7
|
-
import { Construct } from 'constructs'
|
|
8
|
-
import _ from 'lodash'
|
|
9
|
-
import { CommonConstruct } from '../../common'
|
|
10
|
-
import { GraphQlApiLambdaEnvironment, GraphQlApiLambdaProps } from './types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Use RestApiLambda instead. This will be removed in a future release.
|
|
14
|
-
* @classdesc Provides a construct to create and deploy a Graphql API as Lambda
|
|
15
|
-
*
|
|
16
|
-
* <b>Architecture</b><br/> 
|
|
17
|
-
* @example
|
|
18
|
-
* import { GraphQLApiLambda, GraphQlApiLambdaProps } '@gradientedge/cdk-utils'
|
|
19
|
-
* import { Construct } from 'constructs'
|
|
20
|
-
*
|
|
21
|
-
* class CustomConstruct extends GraphQLApiLambda {
|
|
22
|
-
* constructor(parent: Construct, id: string, props: GraphQlApiLambdaProps) {
|
|
23
|
-
* super(parent, id, props)
|
|
24
|
-
* this.props = props
|
|
25
|
-
* this.id = id
|
|
26
|
-
* this.initResources()
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
*/
|
|
30
|
-
export class GraphQLApiLambda extends CommonConstruct {
|
|
31
|
-
/* graphql restApi props */
|
|
32
|
-
props: GraphQlApiLambdaProps
|
|
33
|
-
id: string
|
|
34
|
-
|
|
35
|
-
/* graphql restApi resources */
|
|
36
|
-
applicationSecrets: ISecret[]
|
|
37
|
-
graphQLApiLambdaPolicy: PolicyDocument
|
|
38
|
-
graphQLApiLambdaRole: Role
|
|
39
|
-
graphQLApiLambdaEnvironment: GraphQlApiLambdaEnvironment
|
|
40
|
-
graphQLApiLambdaLayers: ILayerVersion[] = []
|
|
41
|
-
graphQLApiLambdaFunction: IFunction
|
|
42
|
-
graphQLApi: RestApi
|
|
43
|
-
graphQLApiHostedZone: IHostedZone
|
|
44
|
-
graphQLApiCertificate: ICertificate
|
|
45
|
-
graphQLApiDomain: DomainName
|
|
46
|
-
graphQLApiBasePathMappings: BasePathMapping[] = []
|
|
47
|
-
|
|
48
|
-
constructor(parent: Construct, id: string, props: GraphQlApiLambdaProps) {
|
|
49
|
-
super(parent, id, props)
|
|
50
|
-
|
|
51
|
-
this.props = props
|
|
52
|
-
this.id = id
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @summary Initialise and provision resources
|
|
57
|
-
*/
|
|
58
|
-
protected initResources() {
|
|
59
|
-
this.resolveSecrets()
|
|
60
|
-
this.resolveHostedZone()
|
|
61
|
-
this.resolveCertificate()
|
|
62
|
-
this.createLambdaPolicy()
|
|
63
|
-
this.createLambdaRole()
|
|
64
|
-
this.createLambdaEnvironment()
|
|
65
|
-
this.createLambdaLayers()
|
|
66
|
-
this.createLambdaFunction()
|
|
67
|
-
this.createRestApi()
|
|
68
|
-
this.createApiDomain()
|
|
69
|
-
this.createApiBasePathMapping()
|
|
70
|
-
this.createApiRouteAssets()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @summary Method to resolve secrets from SecretsManager
|
|
75
|
-
* - To be implemented in the overriding method in the implementation class
|
|
76
|
-
*/
|
|
77
|
-
protected resolveSecrets() {
|
|
78
|
-
this.applicationSecrets = []
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @summary Method to resolve a hosted zone based on domain attributes
|
|
83
|
-
*/
|
|
84
|
-
protected resolveHostedZone() {
|
|
85
|
-
this.graphQLApiHostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(
|
|
86
|
-
`${this.id}-hosted-zone`,
|
|
87
|
-
this,
|
|
88
|
-
this.props.useExistingHostedZone
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @summary Method to resolve a certificate based on attributes
|
|
94
|
-
*/
|
|
95
|
-
protected resolveCertificate() {
|
|
96
|
-
if (
|
|
97
|
-
this.props.graphQLApiCertificate.useExistingCertificate &&
|
|
98
|
-
this.props.graphQLApiCertificate.certificateSsmName &&
|
|
99
|
-
this.props.graphQLApiCertificate.certificateRegion
|
|
100
|
-
) {
|
|
101
|
-
this.props.graphQLApiCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(
|
|
102
|
-
`${this.id}-certificate-param`,
|
|
103
|
-
this,
|
|
104
|
-
this.props.graphQLApiCertificate.certificateSsmName,
|
|
105
|
-
this.props.graphQLApiCertificate.certificateRegion
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.graphQLApiCertificate = this.acmManager.resolveCertificate(
|
|
110
|
-
`${this.id}-certificate`,
|
|
111
|
-
this,
|
|
112
|
-
this.props.graphQLApiCertificate
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @summary Method to create iam policy for GraphQL Lambda function
|
|
118
|
-
*/
|
|
119
|
-
protected createLambdaPolicy() {
|
|
120
|
-
this.graphQLApiLambdaPolicy = new PolicyDocument({
|
|
121
|
-
statements: [this.iamManager.statementForCreateAnyLogStream()],
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @summary Method to create iam role for GraphQL Lambda function
|
|
127
|
-
*/
|
|
128
|
-
protected createLambdaRole() {
|
|
129
|
-
this.graphQLApiLambdaRole = this.iamManager.createRoleForLambda(
|
|
130
|
-
`${this.id}-lambda-role`,
|
|
131
|
-
this,
|
|
132
|
-
this.graphQLApiLambdaPolicy
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @summary Method to create environment variables for GraphQL Lambda function
|
|
138
|
-
*/
|
|
139
|
-
protected createLambdaEnvironment() {
|
|
140
|
-
this.graphQLApiLambdaEnvironment = {
|
|
141
|
-
LOG_LEVEL: this.props.logLevel,
|
|
142
|
-
NODE_ENV: this.props.nodeEnv,
|
|
143
|
-
TZ: this.props.timezone,
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @summary Method to create layers for GraphQL Lambda function
|
|
149
|
-
*/
|
|
150
|
-
protected createLambdaLayers() {
|
|
151
|
-
const layers: LayerVersion[] = []
|
|
152
|
-
|
|
153
|
-
if (!this.props.graphqlApiLambdaLayerSources) return
|
|
154
|
-
|
|
155
|
-
_.forEach(this.props.graphqlApiLambdaLayerSources, (source: AssetCode, index: number) => {
|
|
156
|
-
layers.push(this.lambdaManager.createLambdaLayer(`${this.id}-layer-${index}`, this, source))
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
this.graphQLApiLambdaLayers = layers
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @summary Method to create lambda function for GraphQL
|
|
164
|
-
*/
|
|
165
|
-
protected createLambdaFunction() {
|
|
166
|
-
this.graphQLApiLambdaFunction = this.lambdaManager.createLambdaFunction(
|
|
167
|
-
`${this.id}-graphql-server`,
|
|
168
|
-
this,
|
|
169
|
-
this.props.graphqlApi,
|
|
170
|
-
this.graphQLApiLambdaRole,
|
|
171
|
-
this.graphQLApiLambdaLayers,
|
|
172
|
-
this.props.graphQLApiSource,
|
|
173
|
-
this.props.graphQLApiHandler || 'index.handler',
|
|
174
|
-
this.graphQLApiLambdaEnvironment
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @summary Method to create rest restApi for GraphQL
|
|
180
|
-
*/
|
|
181
|
-
protected createRestApi() {
|
|
182
|
-
this.graphQLApi = this.apiManager.createLambdaRestApi(
|
|
183
|
-
`${this.id}-lambda-rest-api`,
|
|
184
|
-
this,
|
|
185
|
-
this.props.graphqlRestApi,
|
|
186
|
-
this.graphQLApiLambdaFunction
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @summary Method to create custom restApi domain for GraphQL API
|
|
192
|
-
*/
|
|
193
|
-
protected createApiDomain() {
|
|
194
|
-
this.graphQLApiDomain = this.apiManager.createApiDomain(
|
|
195
|
-
`${this.id}-api-domain`,
|
|
196
|
-
this,
|
|
197
|
-
this.isProductionStage() || this.props.skipStageForARecords
|
|
198
|
-
? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
|
|
199
|
-
: `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`,
|
|
200
|
-
this.graphQLApiCertificate
|
|
201
|
-
)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* @summary Method to create base path mappings for GraphQL API
|
|
206
|
-
*/
|
|
207
|
-
protected createApiBasePathMapping() {
|
|
208
|
-
const apiRootPaths = this.props.apiRootPaths
|
|
209
|
-
if (apiRootPaths && !_.isEmpty(apiRootPaths)) {
|
|
210
|
-
_.forEach(apiRootPaths, (apiRootPath: string) => {
|
|
211
|
-
this.graphQLApiBasePathMappings.push(
|
|
212
|
-
new BasePathMapping(this, `${this.id}-base-bath-mapping-${apiRootPath}`, {
|
|
213
|
-
basePath: apiRootPath,
|
|
214
|
-
domainName: this.graphQLApiDomain,
|
|
215
|
-
restApi: this.graphQLApi,
|
|
216
|
-
stage: this.graphQLApi.deploymentStage,
|
|
217
|
-
})
|
|
218
|
-
)
|
|
219
|
-
})
|
|
220
|
-
return
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// add default mapping if apiRootPaths not set
|
|
224
|
-
new BasePathMapping(this, `${this.id}-base-bath-mapping`, {
|
|
225
|
-
domainName: this.graphQLApiDomain,
|
|
226
|
-
restApi: this.graphQLApi,
|
|
227
|
-
stage: this.graphQLApi.deploymentStage,
|
|
228
|
-
})
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* @summary Method to create route53 records for GraphQL API
|
|
233
|
-
*/
|
|
234
|
-
protected createApiRouteAssets() {
|
|
235
|
-
this.route53Manager.createApiGatewayARecord(
|
|
236
|
-
`${this.id}-custom-domain-a-record`,
|
|
237
|
-
this,
|
|
238
|
-
this.props.apiSubDomain,
|
|
239
|
-
this.graphQLApiDomain,
|
|
240
|
-
this.graphQLApiHostedZone,
|
|
241
|
-
this.props.skipStageForARecords
|
|
242
|
-
)
|
|
243
|
-
}
|
|
244
|
-
}
|