quidproquo-deploy-awscdk 0.0.21 → 0.0.22
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/lib/DeploymentSettings.d.ts +6 -0
- package/lib/DeploymentSettings.js +2 -0
- package/lib/DeploymentType.d.ts +5 -0
- package/lib/DeploymentType.js +9 -0
- package/lib/QPQPrototypeSingleServiceStack.d.ts +12 -0
- package/lib/{QPQPrototypeStack.js → QPQPrototypeSingleServiceStack.js} +113 -21
- package/lib/index.d.ts +4 -1
- package/lib/index.js +4 -1
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +9 -0
- package/package.json +1 -1
- package/lib/QPQPrototypeStack.d.ts +0 -13
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeploymentType = void 0;
|
|
4
|
+
var DeploymentType;
|
|
5
|
+
(function (DeploymentType) {
|
|
6
|
+
DeploymentType["Dev"] = "development";
|
|
7
|
+
DeploymentType["Staging"] = "staging";
|
|
8
|
+
DeploymentType["Prod"] = "production";
|
|
9
|
+
})(DeploymentType = exports.DeploymentType || (exports.DeploymentType = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DeploymentSettings } from './DeploymentSettings';
|
|
2
|
+
import { Stack } from 'aws-cdk-lib';
|
|
3
|
+
import { Construct } from 'constructs';
|
|
4
|
+
export interface QPQPrototypeStackProps extends DeploymentSettings {
|
|
5
|
+
account: string;
|
|
6
|
+
region: string;
|
|
7
|
+
apiBuildPath: string;
|
|
8
|
+
webBuildPath: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class QPQPrototypeSingleServiceStack extends Stack {
|
|
11
|
+
constructor(scope: Construct, id: string, props: QPQPrototypeStackProps);
|
|
12
|
+
}
|
|
@@ -23,21 +23,29 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.QPQPrototypeSingleServiceStack = void 0;
|
|
27
27
|
const path = __importStar(require("path"));
|
|
28
28
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
29
29
|
const cdk = __importStar(require("aws-cdk-lib"));
|
|
30
30
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
31
31
|
const quidproquo_webserver_1 = require("quidproquo-webserver");
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const apexDomain = quidproquo_webserver_1.qpqWebServerUtils.getDomainName(qpqConfig);
|
|
35
|
-
|
|
32
|
+
const DeploymentType_1 = require("./DeploymentType");
|
|
33
|
+
const getEnvironmentDomain = (stackProps) => {
|
|
34
|
+
const apexDomain = quidproquo_webserver_1.qpqWebServerUtils.getDomainName(stackProps.qpqConfig);
|
|
35
|
+
if (stackProps.environment === DeploymentType_1.DeploymentType.Prod) {
|
|
36
|
+
return apexDomain;
|
|
37
|
+
}
|
|
38
|
+
return `${stackProps.environment}.${apexDomain}`;
|
|
39
|
+
};
|
|
40
|
+
const createApiDomainName = (stack, id, stackProps) => {
|
|
41
|
+
const apexDomain = getEnvironmentDomain(stackProps);
|
|
42
|
+
const apiDomainName = `api.${apexDomain}`;
|
|
36
43
|
const apexHostedZone = aws_cdk_lib_1.aws_route53.HostedZone.fromLookup(stack, `${id}-apex-hostedZone`, {
|
|
37
44
|
domainName: apexDomain,
|
|
38
45
|
});
|
|
39
46
|
const certificate = new aws_cdk_lib_1.aws_certificatemanager.Certificate(stack, `${id}-api-certificate`, {
|
|
40
47
|
domainName: apiDomainName,
|
|
48
|
+
certificateName: `api-cert-${quidproquo_core_1.qpqCoreUtils.getAppName(stackProps.qpqConfig)}`,
|
|
41
49
|
validation: aws_cdk_lib_1.aws_certificatemanager.CertificateValidation.fromDns(apexHostedZone),
|
|
42
50
|
});
|
|
43
51
|
const domainName = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, `${id}-api-custom-domain`, {
|
|
@@ -53,24 +61,108 @@ const createApiDomainName = (stack, id, qpqConfig) => {
|
|
|
53
61
|
});
|
|
54
62
|
return domainName;
|
|
55
63
|
};
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
const createWebDistribution = (stack, id, stackProps) => {
|
|
65
|
+
const apexDomain = getEnvironmentDomain(stackProps);
|
|
66
|
+
const serviceName = quidproquo_core_1.qpqCoreUtils.getAppName(stackProps.qpqConfig);
|
|
67
|
+
// create an s3 bucket
|
|
68
|
+
const staticWebFilesBucket = new aws_cdk_lib_1.aws_s3.Bucket(stack, `${id}-web`, {
|
|
69
|
+
bucketName: `${serviceName}-${stackProps.environment}-web`,
|
|
70
|
+
// Disable public access to this bucket, CloudFront will do that
|
|
71
|
+
publicReadAccess: false,
|
|
72
|
+
blockPublicAccess: aws_cdk_lib_1.aws_s3.BlockPublicAccess.BLOCK_ALL,
|
|
73
|
+
// Default website file
|
|
74
|
+
websiteIndexDocument: 'index.html',
|
|
75
|
+
// Allow bucket to auto delete upon cdk:Destroy
|
|
76
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
77
|
+
autoDeleteObjects: true,
|
|
78
|
+
});
|
|
79
|
+
// Create OriginAccessIdentity for the bucket.
|
|
80
|
+
const websiteOAI = new aws_cdk_lib_1.aws_cloudfront.OriginAccessIdentity(stack, `${id}-website-OAI`);
|
|
81
|
+
staticWebFilesBucket.grantRead(websiteOAI);
|
|
82
|
+
// Grab the hosted zone we want to add
|
|
83
|
+
const serviceHostedZone = aws_cdk_lib_1.aws_route53.HostedZone.fromLookup(stack, 'hosted-zone', {
|
|
84
|
+
domainName: apexDomain,
|
|
85
|
+
});
|
|
86
|
+
// Create a certificate for the distribution - Seems to a bug where Route 53 records not cleaned up
|
|
87
|
+
// after removing the DNS Validated certificate see: https://github.com/aws/aws-cdk/issues/3333
|
|
88
|
+
// `switch over to using the Certificate with the new built-in (CloudFormation-based) DNS validation`
|
|
89
|
+
const validationCertificate = aws_cdk_lib_1.aws_certificatemanager.CertificateValidation.fromDns(serviceHostedZone);
|
|
90
|
+
const certificate = new aws_cdk_lib_1.aws_certificatemanager.DnsValidatedCertificate(stack, `${id}-viewer-cert`, {
|
|
91
|
+
hostedZone: serviceHostedZone,
|
|
92
|
+
domainName: apexDomain,
|
|
93
|
+
region: 'us-east-1',
|
|
94
|
+
validation: validationCertificate,
|
|
95
|
+
});
|
|
96
|
+
const viewerCertificate = aws_cdk_lib_1.aws_cloudfront.ViewerCertificate.fromAcmCertificate(certificate, {
|
|
97
|
+
aliases: [apexDomain],
|
|
98
|
+
});
|
|
99
|
+
new aws_cdk_lib_1.aws_s3_deployment.BucketDeployment(stack, `${id}-DeployWebsite`, {
|
|
100
|
+
sources: [aws_cdk_lib_1.aws_s3_deployment.Source.asset(stackProps.webBuildPath)],
|
|
101
|
+
destinationBucket: staticWebFilesBucket,
|
|
102
|
+
});
|
|
103
|
+
// Create a cloud front distribution
|
|
104
|
+
// TODO: use aws_cloudfront.Distribution
|
|
105
|
+
const distribution = new aws_cdk_lib_1.aws_cloudfront.CloudFrontWebDistribution(stack, 'cf-distribution', {
|
|
106
|
+
originConfigs: [
|
|
107
|
+
{
|
|
108
|
+
s3OriginSource: {
|
|
109
|
+
s3BucketSource: staticWebFilesBucket,
|
|
110
|
+
originAccessIdentity: websiteOAI,
|
|
111
|
+
},
|
|
112
|
+
behaviors: [
|
|
113
|
+
...[
|
|
114
|
+
'/remoteEntry.js',
|
|
115
|
+
'/index.js',
|
|
116
|
+
'/index.html', // Add this if we need it
|
|
117
|
+
].map((pp) => ({
|
|
118
|
+
pathPattern: pp,
|
|
119
|
+
maxTtl: cdk.Duration.seconds(0),
|
|
120
|
+
minTtl: cdk.Duration.seconds(0),
|
|
121
|
+
defaultTtl: cdk.Duration.seconds(0),
|
|
122
|
+
})),
|
|
123
|
+
{
|
|
124
|
+
isDefaultBehavior: true,
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
viewerCertificate: viewerCertificate,
|
|
130
|
+
errorConfigurations: [
|
|
131
|
+
{
|
|
132
|
+
errorCode: 404,
|
|
133
|
+
responseCode: 200,
|
|
134
|
+
responsePagePath: '/',
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
// Create a cdn link
|
|
139
|
+
new aws_cdk_lib_1.aws_route53.ARecord(stack, `${id}-web-alias`, {
|
|
140
|
+
zone: serviceHostedZone,
|
|
141
|
+
recordName: apexDomain,
|
|
142
|
+
target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.CloudFrontTarget(distribution)),
|
|
143
|
+
});
|
|
144
|
+
return distribution;
|
|
145
|
+
};
|
|
146
|
+
class QPQPrototypeSingleServiceStack extends aws_cdk_lib_1.Stack {
|
|
147
|
+
constructor(scope, id, props) {
|
|
148
|
+
super(scope, id, {
|
|
149
|
+
env: {
|
|
150
|
+
account: props.account,
|
|
151
|
+
region: props.region,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
58
154
|
const settings = {
|
|
59
155
|
environment: props.environment,
|
|
60
156
|
service: quidproquo_core_1.qpqCoreUtils.getAppName(props.qpqConfig),
|
|
61
|
-
id: `${quidproquo_core_1.qpqCoreUtils.getAppName(props.qpqConfig)}-${props.environment}`,
|
|
62
157
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
region: props.region,
|
|
66
|
-
} }));
|
|
67
|
-
const domainName = createApiDomainName(this, settings.id, props.qpqConfig);
|
|
158
|
+
const domainName = createApiDomainName(this, id, props);
|
|
159
|
+
createWebDistribution(this, `${id}-web-dist`, props);
|
|
68
160
|
const resourceName = (name) => {
|
|
69
161
|
return `${settings.service}-${settings.environment}-${name}`;
|
|
70
162
|
};
|
|
71
|
-
const BLLayer = new aws_cdk_lib_1.aws_lambda.LayerVersion(this, `${
|
|
72
|
-
layerVersionName: `${
|
|
73
|
-
code: new aws_cdk_lib_1.aws_lambda.AssetCode(props.
|
|
163
|
+
const BLLayer = new aws_cdk_lib_1.aws_lambda.LayerVersion(this, `${id}-BLLayer`, {
|
|
164
|
+
layerVersionName: `${id}-BLLayer`,
|
|
165
|
+
code: new aws_cdk_lib_1.aws_lambda.AssetCode(props.apiBuildPath),
|
|
74
166
|
compatibleRuntimes: [aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_16_X],
|
|
75
167
|
});
|
|
76
168
|
const ownedSecrets = quidproquo_core_1.qpqCoreUtils.getOwnedSecrets(props.qpqConfig).map((secret) => {
|
|
@@ -78,7 +170,7 @@ class QPQPrototypeStack extends aws_cdk_lib_1.Stack {
|
|
|
78
170
|
return {
|
|
79
171
|
secretName: secret.key,
|
|
80
172
|
realName: realSecretName,
|
|
81
|
-
secret: new aws_cdk_lib_1.aws_secretsmanager.Secret(this, `${
|
|
173
|
+
secret: new aws_cdk_lib_1.aws_secretsmanager.Secret(this, `${id}-secret-${secret.key}`, {
|
|
82
174
|
secretName: realSecretName,
|
|
83
175
|
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
84
176
|
description: `${settings.environment}-${settings.service}`,
|
|
@@ -139,7 +231,7 @@ class QPQPrototypeStack extends aws_cdk_lib_1.Stack {
|
|
|
139
231
|
proxy: true,
|
|
140
232
|
});
|
|
141
233
|
// Map all requests to this service to /serviceName/*
|
|
142
|
-
new aws_cdk_lib_1.aws_apigateway.BasePathMapping(this, `${
|
|
234
|
+
new aws_cdk_lib_1.aws_apigateway.BasePathMapping(this, `${id}-rest-bpm`, {
|
|
143
235
|
domainName: domainName,
|
|
144
236
|
restApi: api,
|
|
145
237
|
// the properties below are optional
|
|
@@ -170,12 +262,12 @@ class QPQPrototypeStack extends aws_cdk_lib_1.Stack {
|
|
|
170
262
|
buckets.forEach((b) => b.bucket.grantReadWrite(schedulerFunction));
|
|
171
263
|
ownedSecrets.forEach((os) => os.secret.grantRead(schedulerFunction));
|
|
172
264
|
// EventBridge rule which runs every five minutes
|
|
173
|
-
const cronRule = new aws_cdk_lib_1.aws_events.Rule(this, `${
|
|
265
|
+
const cronRule = new aws_cdk_lib_1.aws_events.Rule(this, `${id}-se-cronrule-${index}`, {
|
|
174
266
|
schedule: aws_cdk_lib_1.aws_events.Schedule.expression(`cron(${se.cronExpression})`),
|
|
175
267
|
});
|
|
176
|
-
// Set the
|
|
268
|
+
// Set the target as lambda function
|
|
177
269
|
cronRule.addTarget(new aws_cdk_lib_1.aws_events_targets.LambdaFunction(schedulerFunction));
|
|
178
270
|
});
|
|
179
271
|
}
|
|
180
272
|
}
|
|
181
|
-
exports.
|
|
273
|
+
exports.QPQPrototypeSingleServiceStack = QPQPrototypeSingleServiceStack;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -14,4 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
|
18
|
+
__exportStar(require("./DeploymentType"), exports);
|
|
19
|
+
__exportStar(require("./DeploymentSettings"), exports);
|
|
20
|
+
__exportStar(require("./QPQPrototypeSingleServiceStack"), exports);
|
package/lib/utils.d.ts
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStackName = void 0;
|
|
4
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
5
|
+
const getStackName = (deploymentSettings) => {
|
|
6
|
+
const appName = quidproquo_core_1.qpqCoreUtils.getAppName(deploymentSettings.qpqConfig);
|
|
7
|
+
return `${appName}-${deploymentSettings.environment}`;
|
|
8
|
+
};
|
|
9
|
+
exports.getStackName = getStackName;
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Stack, StackProps } from 'aws-cdk-lib';
|
|
2
|
-
import { Construct } from 'constructs';
|
|
3
|
-
import { QPQConfig } from 'quidproquo-core';
|
|
4
|
-
export interface QPQPrototypeStackProps extends StackProps {
|
|
5
|
-
environment: string;
|
|
6
|
-
serviceBuildPath: string;
|
|
7
|
-
qpqConfig: QPQConfig;
|
|
8
|
-
account: string;
|
|
9
|
-
region: string;
|
|
10
|
-
}
|
|
11
|
-
export declare class QPQPrototypeStack extends Stack {
|
|
12
|
-
constructor(scope: Construct, props: QPQPrototypeStackProps);
|
|
13
|
-
}
|