@guardian/cdk 49.0.0-beta.1 → 49.1.0-beta.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/lib/aspects/cfn-parameter-reporter.d.ts +9 -0
- package/lib/aspects/cfn-parameter-reporter.d.ts.map +1 -0
- package/lib/aspects/cfn-parameter-reporter.js +21 -0
- package/lib/aspects/cfn-parameter-reporter.js.map +1 -0
- package/lib/bin/commands/new-project/index.d.ts +1 -1
- package/lib/bin/commands/new-project/index.d.ts.map +1 -1
- package/lib/constants/metadata-keys.d.ts +0 -1
- package/lib/constants/metadata-keys.d.ts.map +1 -1
- package/lib/constants/metadata-keys.js +0 -1
- package/lib/constants/metadata-keys.js.map +1 -1
- package/lib/constructs/acm/certificate.d.ts +1 -1
- package/lib/constructs/acm/certificate.d.ts.map +1 -1
- package/lib/constructs/autoscaling/user-data.d.ts +1 -1
- package/lib/constructs/autoscaling/user-data.d.ts.map +1 -1
- package/lib/constructs/autoscaling/user-data.js +8 -8
- package/lib/constructs/autoscaling/user-data.js.map +1 -1
- package/lib/constructs/core/parameters/base.d.ts +2 -2
- package/lib/constructs/core/parameters/base.d.ts.map +1 -1
- package/lib/constructs/core/stack.d.ts +7 -1
- package/lib/constructs/core/stack.d.ts.map +1 -1
- package/lib/constructs/core/stack.js +31 -23
- package/lib/constructs/core/stack.js.map +1 -1
- package/lib/constructs/dns/dns-records.js +1 -1
- package/lib/constructs/dns/dns-records.js.map +1 -1
- package/lib/constructs/ec2/vpc.d.ts +1 -1
- package/lib/constructs/ec2/vpc.d.ts.map +1 -1
- package/lib/constructs/ecs/ecs-task.d.ts +4 -4
- package/lib/constructs/ecs/ecs-task.d.ts.map +1 -1
- package/lib/constructs/iam/policies/base-policy.d.ts +3 -3
- package/lib/constructs/iam/policies/base-policy.d.ts.map +1 -1
- package/lib/constructs/iam/roles/instance-role.d.ts +1 -1
- package/lib/constructs/iam/roles/instance-role.d.ts.map +1 -1
- package/lib/constructs/iam/roles/roles.d.ts +1 -1
- package/lib/constructs/iam/roles/roles.d.ts.map +1 -1
- package/lib/constructs/kinesis/kinesis-stream.d.ts +1 -1
- package/lib/constructs/kinesis/kinesis-stream.d.ts.map +1 -1
- package/lib/constructs/s3/index.d.ts +90 -0
- package/lib/constructs/s3/index.d.ts.map +1 -1
- package/lib/constructs/s3/index.js +33 -1
- package/lib/constructs/s3/index.js.map +1 -1
- package/lib/constructs/vpc/vpc.d.ts +1 -1
- package/lib/constructs/vpc/vpc.d.ts.map +1 -1
- package/lib/constructs/vpc/vpc.js +1 -1
- package/lib/constructs/vpc/vpc.js.map +1 -1
- package/lib/experimental/constructs/error-budget-alarm.d.ts +47 -2
- package/lib/experimental/constructs/error-budget-alarm.d.ts.map +1 -1
- package/lib/experimental/constructs/error-budget-alarm.js +84 -42
- package/lib/experimental/constructs/error-budget-alarm.js.map +1 -1
- package/lib/experimental/constructs/index.d.ts +3 -0
- package/lib/experimental/constructs/index.d.ts.map +1 -0
- package/lib/{constructs/sns → experimental/constructs}/index.js +2 -1
- package/lib/experimental/constructs/index.js.map +1 -0
- package/lib/experimental/patterns/sns-lambda.d.ts.map +1 -1
- package/lib/experimental/patterns/sns-lambda.js +1 -2
- package/lib/experimental/patterns/sns-lambda.js.map +1 -1
- package/lib/experimental/riff-raff-yaml-file/deployments/s3.d.ts +4 -0
- package/lib/experimental/riff-raff-yaml-file/deployments/s3.d.ts.map +1 -0
- package/lib/experimental/riff-raff-yaml-file/deployments/s3.js +48 -0
- package/lib/experimental/riff-raff-yaml-file/deployments/s3.js.map +1 -0
- package/lib/experimental/riff-raff-yaml-file/index.d.ts +13 -3
- package/lib/experimental/riff-raff-yaml-file/index.d.ts.map +1 -1
- package/lib/experimental/riff-raff-yaml-file/index.js +71 -51
- package/lib/experimental/riff-raff-yaml-file/index.js.map +1 -1
- package/lib/experimental/riff-raff-yaml-file/types.d.ts +8 -8
- package/lib/experimental/riff-raff-yaml-file/types.d.ts.map +1 -1
- package/lib/experimental/riff-raff-yaml-file/types.js.map +1 -1
- package/lib/patterns/api-multiple-lambdas.d.ts +5 -1
- package/lib/patterns/api-multiple-lambdas.d.ts.map +1 -1
- package/lib/patterns/api-multiple-lambdas.js +3 -1
- package/lib/patterns/api-multiple-lambdas.js.map +1 -1
- package/lib/patterns/ec2-app/base.d.ts.map +1 -1
- package/lib/patterns/ec2-app/base.js +0 -5
- package/lib/patterns/ec2-app/base.js.map +1 -1
- package/lib/patterns/ec2-app/framework.d.ts +1 -1
- package/lib/patterns/ec2-app/framework.d.ts.map +1 -1
- package/lib/types/access.d.ts +1 -1
- package/lib/types/access.d.ts.map +1 -1
- package/lib/types/cli.d.ts +1 -1
- package/lib/types/cli.d.ts.map +1 -1
- package/lib/utils/lambda/event-source.d.ts +4 -4
- package/lib/utils/lambda/event-source.d.ts.map +1 -1
- package/lib/utils/lambda/event-source.js +4 -4
- package/lib/utils/lambda/event-source.js.map +1 -1
- package/lib/utils/mixin/types.d.ts +1 -1
- package/lib/utils/mixin/types.d.ts.map +1 -1
- package/package.json +21 -21
- package/lib/constructs/sns/index.d.ts +0 -2
- package/lib/constructs/sns/index.d.ts.map +0 -1
- package/lib/constructs/sns/index.js.map +0 -1
- package/lib/constructs/sns/sns-topic.d.ts +0 -15
- package/lib/constructs/sns/sns-topic.d.ts.map +0 -1
- package/lib/constructs/sns/sns-topic.js +0 -17
- package/lib/constructs/sns/sns-topic.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/experimental/riff-raff-yaml-file/deployments/s3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EAAE,EAChB,YAAY,EAAE,gBAAgB,EAC9B,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,kBAAkB,GAC1C,kBAAkB,CAoDpB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadStaticFilesDeployment = void 0;
|
|
4
|
+
function uploadStaticFilesDeployment(stages, originBucket, { name: cfnDeployName }) {
|
|
5
|
+
const { app, _deploymentProps } = originBucket;
|
|
6
|
+
const { withoutStageAwareness, baseParameterName, cacheControl, surrogateControl, mimeTypes } = _deploymentProps;
|
|
7
|
+
const { stack, region } = originBucket.stack;
|
|
8
|
+
const cacheControlValue = Object.entries(cacheControl).map(([pattern, duration]) => {
|
|
9
|
+
return {
|
|
10
|
+
pattern,
|
|
11
|
+
value: `public, max-age=${duration.toSeconds()}`,
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
const surrogateControlValue = Object.entries(surrogateControl).map(([pattern, duration]) => {
|
|
15
|
+
return {
|
|
16
|
+
pattern,
|
|
17
|
+
value: `public, max-age=${duration.toSeconds()}`,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
name: ["upload-static-files", region, stack, app].join("-"),
|
|
22
|
+
props: {
|
|
23
|
+
type: "aws-s3",
|
|
24
|
+
actions: ["uploadStaticFiles"],
|
|
25
|
+
dependencies: [cfnDeployName],
|
|
26
|
+
stacks: new Set([stack]),
|
|
27
|
+
regions: new Set([region]),
|
|
28
|
+
app,
|
|
29
|
+
contentDirectory: app,
|
|
30
|
+
parameters: {
|
|
31
|
+
bucketSsmKeyStageParam: stages.reduce((acc, stage) => ({
|
|
32
|
+
...acc,
|
|
33
|
+
[stage]: withoutStageAwareness ? baseParameterName : `/${stage}${baseParameterName}`,
|
|
34
|
+
}), {}),
|
|
35
|
+
// Never create per object ACLs.
|
|
36
|
+
// If the bucket content needs to be public, it’s better to control this via the bucket policy.
|
|
37
|
+
publicReadAcl: false,
|
|
38
|
+
cacheControl: cacheControlValue.length > 0 ? cacheControlValue : "private",
|
|
39
|
+
// only add the `surrogateControl` property if there are some
|
|
40
|
+
...(surrogateControlValue.length > 0 && { surrogateControl: surrogateControlValue }),
|
|
41
|
+
// only add the `mimeTypes` property if there are some
|
|
42
|
+
...(Object.keys(mimeTypes).length > 0 && { mimeTypes }),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.uploadStaticFilesDeployment = uploadStaticFilesDeployment;
|
|
48
|
+
//# sourceMappingURL=s3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.js","sourceRoot":"","sources":["../../../../src/experimental/riff-raff-yaml-file/deployments/s3.ts"],"names":[],"mappings":";;;AAIA,SAAgB,2BAA2B,CACzC,MAAgB,EAChB,YAA8B,EAC9B,EAAE,IAAI,EAAE,aAAa,EAAsB;IAE3C,MAAM,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,YAAY,CAAC;IAC/C,MAAM,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC;IACjH,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC,KAAgB,CAAC;IAExD,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE;QACjF,OAAO;YACL,OAAO;YACP,KAAK,EAAE,mBAAmB,QAAQ,CAAC,SAAS,EAAE,EAAE;SACjD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE;QACzF,OAAO;YACL,OAAO;YACP,KAAK,EAAE,mBAAmB,QAAQ,C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} from \"../../../constructs/s3\";\nimport type { RiffRaffDeployment } from \"../types\";\n\nexport function uploadStaticFilesDeployment(\n stages: string[],\n originBucket: GuS3OriginBucket,\n { name: cfnDeployName }: RiffRaffDeployment\n): RiffRaffDeployment {\n const { app, _deploymentProps } = originBucket;\n const { withoutStageAwareness, baseParameterName, cacheControl, surrogateControl, mimeTypes } = _deploymentProps;\n const { stack, region } = originBucket.stack as GuStack;\n\n const cacheControlValue = Object.entries(cacheControl).map(([pattern, duration]) => {\n return {\n pattern,\n value: `public, max-age=${duration.toSeconds()}`,\n };\n });\n\n const surrogateControlValue = Object.entries(surrogateControl).map(([pattern, duration]) => {\n return {\n pattern,\n value: `public, max-age=${duration.toSeconds()}`,\n };\n });\n\n return {\n name: [\"upload-static-files\", region, stack, app].join(\"-\"),\n props: {\n type: \"aws-s3\",\n actions: [\"uploadStaticFiles\"],\n dependencies: [cfnDeployName],\n stacks: new Set([stack]),\n regions: new Set([region]),\n app,\n contentDirectory: app,\n parameters: {\n bucketSsmKeyStageParam: stages.reduce(\n (acc, stage) => ({\n ...acc,\n [stage]: withoutStageAwareness ? baseParameterName : `/${stage}${baseParameterName}`,\n }),\n {}\n ),\n\n // Never create per object ACLs.\n // If the bucket content needs to be public, it’s better to control this via the bucket policy.\n publicReadAcl: false,\n\n cacheControl: cacheControlValue.length > 0 ? cacheControlValue : \"private\",\n\n // only add the `surrogateControl` property if there are some\n ...(surrogateControlValue.length > 0 && { surrogateControl: surrogateControlValue }),\n\n // only add the `mimeTypes` property if there are some\n ...(Object.keys(mimeTypes).length > 0 && { mimeTypes }),\n },\n },\n };\n}\n"]}
|
|
@@ -9,6 +9,7 @@ import type { App } from "aws-cdk-lib";
|
|
|
9
9
|
* - Multiple regions
|
|
10
10
|
* - Lambda applications
|
|
11
11
|
* - EC2 (autoscaling) applications
|
|
12
|
+
* - Upload of static files to S3
|
|
12
13
|
*
|
|
13
14
|
* For lambda applications, 3 deployments will be defined:
|
|
14
15
|
* 1. Lambda upload (`aws-lambda`, `action: [uploadLambda]`)
|
|
@@ -17,9 +18,13 @@ import type { App } from "aws-cdk-lib";
|
|
|
17
18
|
*
|
|
18
19
|
* For EC2 applications, 3 deployments will be defined:
|
|
19
20
|
* 1. Artifact upload (`autoscaling`, `action: [uploadArtifacts]`)
|
|
20
|
-
*
|
|
21
|
+
* 2. CloudFormation deploy (`cloud-formation`)
|
|
21
22
|
* 3. Autoscaling deploy (`autoscaling`, `action: [deploy]`)
|
|
22
23
|
*
|
|
24
|
+
* For S3 uploads, 2 deployments will be defined:
|
|
25
|
+
* 1. Artifact upload (`aws-s3`, `action: [uploadStaticFiles]`)
|
|
26
|
+
* 2. CloudFormation deploy (`cloud-formation`)
|
|
27
|
+
*
|
|
23
28
|
* It assumes a Riff-Raff bundle structure as follows:
|
|
24
29
|
*
|
|
25
30
|
* ```
|
|
@@ -28,8 +33,12 @@ import type { App } from "aws-cdk-lib";
|
|
|
28
33
|
* │ └── MyApplication.template.json
|
|
29
34
|
* ├── my-application
|
|
30
35
|
* │ └── my-application.deb
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* ├── my-lambda
|
|
37
|
+
* │ └── my-lambda.zip
|
|
38
|
+
* └── my-static-site
|
|
39
|
+
* ├── index.html
|
|
40
|
+
* ├── main.js
|
|
41
|
+
* └── index.css
|
|
33
42
|
* ```
|
|
34
43
|
*
|
|
35
44
|
* That is, all CloudFormation templates are in a `cdk.out` directory, and there is a directory per app.
|
|
@@ -110,6 +119,7 @@ export declare class RiffRaffYamlFileExperimental {
|
|
|
110
119
|
private validateAllRegionsAreResolved;
|
|
111
120
|
private getLambdas;
|
|
112
121
|
private getAutoScalingGroups;
|
|
122
|
+
private getOriginBuckets;
|
|
113
123
|
constructor(app: App);
|
|
114
124
|
/**
|
|
115
125
|
* The `riff-raff.yaml` file as a string.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/riff-raff-yaml-file/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/riff-raff-yaml-file/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAyBvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,qBAAa,4BAA4B;IACvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAY;IACzC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAa;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAa;IAC1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IAEtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC,OAAO,CAAC,iBAAiB;IAqBzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuDG;IACH,OAAO,CAAC,mBAAmB;IAkD3B,OAAO,CAAC,6BAA6B;IAQrC,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,gBAAgB;gBAMZ,GAAG,EAAE,GAAG;IAoEpB;;;OAGG;IACH,MAAM,IAAI,MAAM;IAiBhB;;;OAGG;IACH,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -12,9 +12,11 @@ const js_yaml_1 = require("js-yaml");
|
|
|
12
12
|
const autoscaling_1 = require("../../constructs/autoscaling");
|
|
13
13
|
const core_1 = require("../../constructs/core");
|
|
14
14
|
const lambda_1 = require("../../constructs/lambda");
|
|
15
|
+
const s3_1 = require("../../constructs/s3");
|
|
15
16
|
const autoscaling_2 = require("./deployments/autoscaling");
|
|
16
17
|
const cloudformation_1 = require("./deployments/cloudformation");
|
|
17
18
|
const lambda_2 = require("./deployments/lambda");
|
|
19
|
+
const s3_2 = require("./deployments/s3");
|
|
18
20
|
const group_by_1 = require("./group-by");
|
|
19
21
|
/**
|
|
20
22
|
* A class that creates a `riff-raff.yaml` file.
|
|
@@ -26,6 +28,7 @@ const group_by_1 = require("./group-by");
|
|
|
26
28
|
* - Multiple regions
|
|
27
29
|
* - Lambda applications
|
|
28
30
|
* - EC2 (autoscaling) applications
|
|
31
|
+
* - Upload of static files to S3
|
|
29
32
|
*
|
|
30
33
|
* For lambda applications, 3 deployments will be defined:
|
|
31
34
|
* 1. Lambda upload (`aws-lambda`, `action: [uploadLambda]`)
|
|
@@ -34,9 +37,13 @@ const group_by_1 = require("./group-by");
|
|
|
34
37
|
*
|
|
35
38
|
* For EC2 applications, 3 deployments will be defined:
|
|
36
39
|
* 1. Artifact upload (`autoscaling`, `action: [uploadArtifacts]`)
|
|
37
|
-
*
|
|
40
|
+
* 2. CloudFormation deploy (`cloud-formation`)
|
|
38
41
|
* 3. Autoscaling deploy (`autoscaling`, `action: [deploy]`)
|
|
39
42
|
*
|
|
43
|
+
* For S3 uploads, 2 deployments will be defined:
|
|
44
|
+
* 1. Artifact upload (`aws-s3`, `action: [uploadStaticFiles]`)
|
|
45
|
+
* 2. CloudFormation deploy (`cloud-formation`)
|
|
46
|
+
*
|
|
40
47
|
* It assumes a Riff-Raff bundle structure as follows:
|
|
41
48
|
*
|
|
42
49
|
* ```
|
|
@@ -45,8 +52,12 @@ const group_by_1 = require("./group-by");
|
|
|
45
52
|
* │ └── MyApplication.template.json
|
|
46
53
|
* ├── my-application
|
|
47
54
|
* │ └── my-application.deb
|
|
48
|
-
*
|
|
49
|
-
*
|
|
55
|
+
* ├── my-lambda
|
|
56
|
+
* │ └── my-lambda.zip
|
|
57
|
+
* └── my-static-site
|
|
58
|
+
* ├── index.html
|
|
59
|
+
* ├── main.js
|
|
60
|
+
* └── index.css
|
|
50
61
|
* ```
|
|
51
62
|
*
|
|
52
63
|
* That is, all CloudFormation templates are in a `cdk.out` directory, and there is a directory per app.
|
|
@@ -60,54 +71,6 @@ const group_by_1 = require("./group-by");
|
|
|
60
71
|
* @see https://riffraff.gutools.co.uk/docs/magenta-lib/types
|
|
61
72
|
*/
|
|
62
73
|
class RiffRaffYamlFileExperimental {
|
|
63
|
-
// eslint-disable-next-line custom-rules/valid-constructors -- this needs to sit above GuStack on the cdk tree
|
|
64
|
-
constructor(app) {
|
|
65
|
-
this.allCdkStacks = app.node.findAll().filter((_) => _ instanceof core_1.GuStack);
|
|
66
|
-
const allowedStages = new Set(this.allCdkStacks.map(({ stage }) => stage));
|
|
67
|
-
this.allStageTags = Array.from(allowedStages);
|
|
68
|
-
this.allStackTags = Array.from(new Set(this.allCdkStacks.map(({ stack }) => stack)));
|
|
69
|
-
this.allRegions = Array.from(new Set(this.allCdkStacks.map(({ region }) => region)));
|
|
70
|
-
this.validateStacksInApp();
|
|
71
|
-
this.validateAllRegionsAreResolved();
|
|
72
|
-
this.outdir = app.outdir;
|
|
73
|
-
const deployments = new Map();
|
|
74
|
-
const groupedStacks = (0, group_by_1.groupByClassNameStackRegionStage)(this.allCdkStacks);
|
|
75
|
-
Object.values(groupedStacks).forEach((stackTagGroup) => {
|
|
76
|
-
Object.values(stackTagGroup).forEach((regionGroup) => {
|
|
77
|
-
Object.values(regionGroup).forEach((stageGroup) => {
|
|
78
|
-
const stacks = Object.values(stageGroup).flat();
|
|
79
|
-
if (stacks.length === 0) {
|
|
80
|
-
throw new Error("Unable to produce a working riff-raff.yaml file; there are no stacks!");
|
|
81
|
-
}
|
|
82
|
-
// The items in `stacks` only differ by stage, so we can just use the first item in the list.
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length of `stacks` is checked above
|
|
84
|
-
const stack = stacks[0];
|
|
85
|
-
const lambdas = this.getLambdas(stack);
|
|
86
|
-
const autoscalingGroups = this.getAutoScalingGroups(stack);
|
|
87
|
-
const artifactUploads = [
|
|
88
|
-
lambdas.map(lambda_2.uploadLambdaArtifact),
|
|
89
|
-
autoscalingGroups.map(autoscaling_2.uploadAutoscalingArtifact),
|
|
90
|
-
].flat();
|
|
91
|
-
artifactUploads.forEach(({ name, props }) => deployments.set(name, props));
|
|
92
|
-
const cfnDeployment = (0, cloudformation_1.cloudFormationDeployment)(stacks, artifactUploads, this.outdir);
|
|
93
|
-
deployments.set(cfnDeployment.name, cfnDeployment.props);
|
|
94
|
-
lambdas.forEach((lambda) => {
|
|
95
|
-
const lambdaDeployment = (0, lambda_2.updateLambdaDeployment)(lambda, cfnDeployment);
|
|
96
|
-
deployments.set(lambdaDeployment.name, lambdaDeployment.props);
|
|
97
|
-
});
|
|
98
|
-
autoscalingGroups.forEach((asg) => {
|
|
99
|
-
const asgDeployment = (0, autoscaling_2.autoscalingDeployment)(asg, cfnDeployment);
|
|
100
|
-
deployments.set(asgDeployment.name, asgDeployment.props);
|
|
101
|
-
deployments.set(cfnDeployment.name, (0, cloudformation_1.addAmiParametersToCloudFormationDeployment)(cfnDeployment, asg));
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
this.riffRaffYaml = {
|
|
107
|
-
allowedStages,
|
|
108
|
-
deployments,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
74
|
isCdkStackPresent(expectedClassName, expectedStack, expectedRegion, expectedStage) {
|
|
112
75
|
const matches = this.allCdkStacks.find((cdkStack) => {
|
|
113
76
|
const { constructor: { name }, stack, stage, region, } = cdkStack;
|
|
@@ -223,6 +186,63 @@ class RiffRaffYamlFileExperimental {
|
|
|
223
186
|
getAutoScalingGroups(cdkStack) {
|
|
224
187
|
return cdkStack.node.findAll().filter((_) => _ instanceof autoscaling_1.GuAutoScalingGroup);
|
|
225
188
|
}
|
|
189
|
+
getOriginBuckets(cdkStack) {
|
|
190
|
+
// `GuS3OriginBucket` implements `IConstruct` to remove a `SuspiciousTypeOfGuard` warning here
|
|
191
|
+
return cdkStack.node.findAll().filter((_) => _ instanceof s3_1.GuS3OriginBucket);
|
|
192
|
+
}
|
|
193
|
+
// eslint-disable-next-line custom-rules/valid-constructors -- this needs to sit above GuStack on the cdk tree
|
|
194
|
+
constructor(app) {
|
|
195
|
+
this.allCdkStacks = app.node.findAll().filter((_) => _ instanceof core_1.GuStack);
|
|
196
|
+
const allowedStages = new Set(this.allCdkStacks.map(({ stage }) => stage));
|
|
197
|
+
this.allStageTags = Array.from(allowedStages);
|
|
198
|
+
this.allStackTags = Array.from(new Set(this.allCdkStacks.map(({ stack }) => stack)));
|
|
199
|
+
this.allRegions = Array.from(new Set(this.allCdkStacks.map(({ region }) => region)));
|
|
200
|
+
this.validateStacksInApp();
|
|
201
|
+
this.validateAllRegionsAreResolved();
|
|
202
|
+
this.outdir = app.outdir;
|
|
203
|
+
const deployments = new Map();
|
|
204
|
+
const groupedStacks = (0, group_by_1.groupByClassNameStackRegionStage)(this.allCdkStacks);
|
|
205
|
+
Object.values(groupedStacks).forEach((stackTagGroup) => {
|
|
206
|
+
Object.values(stackTagGroup).forEach((regionGroup) => {
|
|
207
|
+
Object.values(regionGroup).forEach((stageGroup) => {
|
|
208
|
+
const stacks = Object.values(stageGroup).flat();
|
|
209
|
+
if (stacks.length === 0) {
|
|
210
|
+
throw new Error("Unable to produce a working riff-raff.yaml file; there are no stacks!");
|
|
211
|
+
}
|
|
212
|
+
// The items in `stacks` only differ by stage, so we can just use the first item in the list.
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length of `stacks` is checked above
|
|
214
|
+
const stack = stacks[0];
|
|
215
|
+
const lambdas = this.getLambdas(stack);
|
|
216
|
+
const autoscalingGroups = this.getAutoScalingGroups(stack);
|
|
217
|
+
const originBuckets = this.getOriginBuckets(stack);
|
|
218
|
+
const artifactUploads = [
|
|
219
|
+
lambdas.map(lambda_2.uploadLambdaArtifact),
|
|
220
|
+
autoscalingGroups.map(autoscaling_2.uploadAutoscalingArtifact),
|
|
221
|
+
].flat();
|
|
222
|
+
artifactUploads.forEach(({ name, props }) => deployments.set(name, props));
|
|
223
|
+
const cfnDeployment = (0, cloudformation_1.cloudFormationDeployment)(stacks, artifactUploads, this.outdir);
|
|
224
|
+
deployments.set(cfnDeployment.name, cfnDeployment.props);
|
|
225
|
+
lambdas.forEach((lambda) => {
|
|
226
|
+
const lambdaDeployment = (0, lambda_2.updateLambdaDeployment)(lambda, cfnDeployment);
|
|
227
|
+
deployments.set(lambdaDeployment.name, lambdaDeployment.props);
|
|
228
|
+
});
|
|
229
|
+
autoscalingGroups.forEach((asg) => {
|
|
230
|
+
const asgDeployment = (0, autoscaling_2.autoscalingDeployment)(asg, cfnDeployment);
|
|
231
|
+
deployments.set(asgDeployment.name, asgDeployment.props);
|
|
232
|
+
deployments.set(cfnDeployment.name, (0, cloudformation_1.addAmiParametersToCloudFormationDeployment)(cfnDeployment, asg));
|
|
233
|
+
});
|
|
234
|
+
originBuckets.forEach((bucket) => {
|
|
235
|
+
const staticFilesDeployment = (0, s3_2.uploadStaticFilesDeployment)(this.allStageTags, bucket, cfnDeployment);
|
|
236
|
+
deployments.set(staticFilesDeployment.name, staticFilesDeployment.props);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
this.riffRaffYaml = {
|
|
242
|
+
allowedStages,
|
|
243
|
+
deployments,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
226
246
|
/**
|
|
227
247
|
* The `riff-raff.yaml` file as a string.
|
|
228
248
|
* Useful for testing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/riff-raff-yaml-file/index.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAmC;AACnC,gDAAwB;AAExB,6CAAoC;AACpC,kDAA0B;AAC1B,qCAA+B;AAC/B,8DAAkE;AAClE,gDAAgD;AAChD,oDAA2D;AAC3D,2DAA6F;AAC7F,iEAAoH;AACpH,iDAAoF;AACpF,yCAA8D;AAa9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QACJ,qFAAqF;QACrF,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,KAAc,EAAE,EAAE;YAChD,IAAI,KAAK,YAAY,GAAG,EAAE;gBACxB,iGAAiG;gBACjG,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC1B;YACD,IAAI,KAAK,YAAY,GAAG,EAAE;gBACxB,iGAAiG;gBACjG,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;aAClC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;QAEF,OAAO,IAAA,cAAI,EAAC,IAAI,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACzD,IAAA,kBAAa,EAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACxC,CAAC;CACF;AApPD,oEAoPC","sourcesContent":["import { writeFileSync } from \"fs\";\nimport path from \"path\";\nimport type { App } from \"aws-cdk-lib\";\nimport { Token } from \"aws-cdk-lib\";\nimport chalk from \"chalk\";\nimport { dump } from \"js-yaml\";\nimport { GuAutoScalingGroup } from \"../../constructs/autoscaling\";\nimport { GuStack } from \"../../constructs/core\";\nimport { GuLambdaFunction } from \"../../constructs/lambda\";\nimport { autoscalingDeployment, uploadAutoscalingArtifact } from \"./deployments/autoscaling\";\nimport { addAmiParametersToCloudFormationDeployment, cloudFormationDeployment } from \"./deployments/cloudformation\";\nimport { updateLambdaDeployment, uploadLambdaArtifact } from \"./deployments/lambda\";\nimport { groupByClassNameStackRegionStage } from \"./group-by\";\nimport type {\n ClassName,\n GroupedCdkStacks,\n Region,\n RiffRaffDeployment,\n RiffRaffDeploymentName,\n RiffRaffDeploymentProps,\n RiffRaffYaml,\n StackTag,\n StageTag,\n} from \"./types\";\n\n/**\n * A class that creates a `riff-raff.yaml` file.\n *\n * Rather than using this directly, prefer to use [[`GuRoot`]] instead.\n *\n * Supports:\n * - Multiple CloudFormation stacks\n * - Multiple regions\n * - Lambda applications\n * - EC2 (autoscaling) applications\n *\n * For lambda applications, 3 deployments will be defined:\n * 1. Lambda upload (`aws-lambda`, `action: [uploadLambda]`)\n * 2. CloudFormation deploy (`cloud-formation`)\n * 3. Lambda update (`aws-lambda`, `action: [updateLambda]`)\n *\n * For EC2 applications, 3 deployments will be defined:\n * 1. Artifact upload (`autoscaling`, `action: [uploadArtifacts]`)\n * 2. CloudFormation deploy (`cloud-formation`)\n * 3. Autoscaling deploy (`autoscaling`, `action: [deploy]`)\n *\n * It assumes a Riff-Raff bundle structure as follows:\n *\n * ```\n * .\n * ├── cdk.out\n * │ └── MyApplication.template.json\n * ├── my-application\n * │ └── my-application.deb\n * └── my-lambda\n * └── my-lambda.zip\n * ```\n *\n * That is, all CloudFormation templates are in a `cdk.out` directory, and there is a directory per app.\n * Application artifact(s) are in the app directory.\n *\n * NOTE: The file extension is decided by you, the above file tree is used for illustration purposes.\n *\n * NOTE: Resources will be looked up by tags (Stack, Stage, App). Ensure your CFN stack is tagged appropriately!\n *\n * @see https://riffraff.gutools.co.uk/docs/reference/riff-raff.yaml.md\n * @see https://riffraff.gutools.co.uk/docs/magenta-lib/types\n */\nexport class RiffRaffYamlFileExperimental {\n private readonly allCdkStacks: GuStack[];\n private readonly allStackTags: StackTag[];\n private readonly allStageTags: StageTag[];\n private readonly allRegions: Region[];\n\n private readonly riffRaffYaml: RiffRaffYaml;\n private readonly outdir: string;\n\n private isCdkStackPresent(\n expectedClassName: ClassName,\n expectedStack: StackTag,\n expectedRegion: Region,\n expectedStage: StageTag\n ): boolean {\n const matches = this.allCdkStacks.find((cdkStack) => {\n const {\n constructor: { name },\n stack,\n stage,\n region,\n } = cdkStack;\n return (\n name === expectedClassName && stack === expectedStack && stage === expectedStage && region === expectedRegion\n );\n });\n\n return !!matches;\n }\n\n /**\n * Check there are the appropriate number of `GuStack`s.\n * Expect to find an instance for each combination of `GuStack`, `stack`, `region`, and `stage`.\n *\n * If not valid, a message is logged describing what is missing to aid debugging.\n *\n * Given the following:\n *\n * ```ts\n * const app = new App();\n *\n * class MyApplicationStack extends GuStack { }\n *\n * new MyApplicationStack(app, \"App-CODE-deploy\", {\n * env: {\n * region: \"eu-west-1\",\n * },\n * stack: \"deploy\",\n * stage: \"CODE\"\n * });\n *\n * new MyApplicationStack(app, \"App-PROD-media-service\", {\n * env: {\n * region: \"eu-west-1\",\n * },\n * stack: \"media-service\",\n * stage: \"PROD\",\n * });\n *\n * new MyApplicationStack(app, \"App-PROD-deploy\", {\n * env: {\n * region: \"eu-west-1\",\n * },\n * stack: \"deploy\",\n * stage: \"PROD\"\n * });\n * ```\n *\n * This will log a message like this, where ❌ denotes something missing,\n * specifically there is no `CODE` template for `media-service`.\n *\n * ```log\n * Unable to produce a working riff-raff.yaml file; missing 1 definitions (details below)\n *\n * For the class: MyApplicationStack\n *\n * ┌───────────────┬────────────────────────────┐\n * │ (index) │ eu-west-1 │\n * ├───────────────┼────────────────────────────┤\n * │ deploy │ { CODE: '✅', PROD: '✅' } │\n * │ media-service │ { CODE: '❌', PROD: '✅' } │\n * └───────────────┴────────────────────────────┘\n * ```\n *\n * @private\n */\n private validateStacksInApp(): void {\n type Found = \"✅\";\n type NotFound = \"❌\";\n type AppValidation = Record<ClassName, Record<StackTag, Record<Region, Record<StageTag, Found | NotFound>>>>;\n\n const { allCdkStacks, allStackTags, allStageTags, allRegions } = this;\n\n const checks: AppValidation = allCdkStacks.reduce((accClassName, { constructor: { name } }) => {\n return {\n ...accClassName,\n [name]: allStackTags.reduce((accStackTag, stackTag) => {\n return {\n ...accStackTag,\n [stackTag]: allRegions.reduce((accRegion, region) => {\n return {\n ...accRegion,\n [region]: allStageTags.reduce((accStageTag, stageTag) => {\n return {\n ...accStageTag,\n [stageTag]: this.isCdkStackPresent(name, stackTag, region, stageTag) ? \"✅\" : \"❌\",\n };\n }, {}),\n };\n }, {}),\n };\n }, {}),\n };\n }, {});\n\n const missingDefinitions = Object.values(checks).flatMap((groupedByStackTag) => {\n return Object.values(groupedByStackTag).flatMap((groupedByRegion) => {\n return Object.values(groupedByRegion).flatMap((groupedByStage) => {\n return Object.values(groupedByStage).filter((_) => _ === \"❌\");\n });\n });\n });\n\n if (missingDefinitions.length > 0) {\n const message = `Unable to produce a working riff-raff.yaml file; missing ${missingDefinitions.length} definitions`;\n\n console.log(`${message} (details below)`);\n Object.entries(checks).forEach(([className, detail]) => {\n console.log(`For the class: ${chalk.yellow(className)}`);\n console.table(detail);\n });\n\n throw new Error(message);\n }\n }\n\n private validateAllRegionsAreResolved(): void {\n const unresolved = this.allRegions.filter((region) => Token.isUnresolved(region));\n\n if (unresolved.length !== 0) {\n throw new Error(`Unable to produce a working riff-raff.yaml file; all stacks must have an explicit region set`);\n }\n }\n\n private getLambdas(cdkStack: GuStack): GuLambdaFunction[] {\n return cdkStack.node.findAll().filter((_) => _ instanceof GuLambdaFunction) as GuLambdaFunction[];\n }\n\n private getAutoScalingGroups(cdkStack: GuStack): GuAutoScalingGroup[] {\n return cdkStack.node.findAll().filter((_) => _ instanceof GuAutoScalingGroup) as GuAutoScalingGroup[];\n }\n\n // eslint-disable-next-line custom-rules/valid-constructors -- this needs to sit above GuStack on the cdk tree\n constructor(app: App) {\n this.allCdkStacks = app.node.findAll().filter((_) => _ instanceof GuStack) as GuStack[];\n const allowedStages = new Set(this.allCdkStacks.map(({ stage }) => stage));\n this.allStageTags = Array.from(allowedStages);\n this.allStackTags = Array.from(new Set(this.allCdkStacks.map(({ stack }) => stack)));\n this.allRegions = Array.from(new Set(this.allCdkStacks.map(({ region }) => region)));\n\n this.validateStacksInApp();\n this.validateAllRegionsAreResolved();\n\n this.outdir = app.outdir;\n\n const deployments = new Map<RiffRaffDeploymentName, RiffRaffDeploymentProps>();\n\n const groupedStacks: GroupedCdkStacks = groupByClassNameStackRegionStage(this.allCdkStacks);\n\n Object.values(groupedStacks).forEach((stackTagGroup) => {\n Object.values(stackTagGroup).forEach((regionGroup) => {\n Object.values(regionGroup).forEach((stageGroup) => {\n const stacks: GuStack[] = Object.values(stageGroup).flat();\n\n if (stacks.length === 0) {\n throw new Error(\"Unable to produce a working riff-raff.yaml file; there are no stacks!\");\n }\n\n // The items in `stacks` only differ by stage, so we can just use the first item in the list.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length of `stacks` is checked above\n const stack = stacks[0]!;\n\n const lambdas = this.getLambdas(stack);\n const autoscalingGroups = this.getAutoScalingGroups(stack);\n\n const artifactUploads: RiffRaffDeployment[] = [\n lambdas.map(uploadLambdaArtifact),\n autoscalingGroups.map(uploadAutoscalingArtifact),\n ].flat();\n artifactUploads.forEach(({ name, props }) => deployments.set(name, props));\n\n const cfnDeployment = cloudFormationDeployment(stacks, artifactUploads, this.outdir);\n deployments.set(cfnDeployment.name, cfnDeployment.props);\n\n lambdas.forEach((lambda) => {\n const lambdaDeployment = updateLambdaDeployment(lambda, cfnDeployment);\n deployments.set(lambdaDeployment.name, lambdaDeployment.props);\n });\n\n autoscalingGroups.forEach((asg) => {\n const asgDeployment = autoscalingDeployment(asg, cfnDeployment);\n deployments.set(asgDeployment.name, asgDeployment.props);\n\n deployments.set(cfnDeployment.name, addAmiParametersToCloudFormationDeployment(cfnDeployment, asg));\n });\n });\n });\n });\n\n this.riffRaffYaml = {\n allowedStages,\n deployments,\n };\n }\n\n /**\n * The `riff-raff.yaml` file as a string.\n * Useful for testing.\n */\n toYAML(): string {\n // Add support for ES6 Set and Map. See https://github.com/nodeca/js-yaml/issues/436.\n const replacer = (_key: string, value: unknown) => {\n if (value instanceof Set) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- this is how `js-yaml` is typed\n return Array.from(value);\n }\n if (value instanceof Map) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- this is how `js-yaml` is typed\n return Object.fromEntries(value);\n }\n return value;\n };\n\n return dump(this.riffRaffYaml, { replacer });\n }\n\n /**\n * Write the `riff-raff.yaml` file to disk.\n * It'll be located with the CFN JSON templates generated by `cdk synth`.\n */\n synth(): void {\n const outPath = path.join(this.outdir, \"riff-raff.yaml\");\n writeFileSync(outPath, this.toYAML());\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/riff-raff-yaml-file/index.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAmC;AACnC,gDAAwB;AAExB,6CAAoC;AACpC,kDAA0B;AAC1B,qCAA+B;AAC/B,8DAAkE;AAClE,gDAAgD;AAChD,oDAA2D;AAC3D,4CAAuD;AACvD,2DAA6F;AAC7F,iEAAoH;AACpH,iDAAoF;AACpF,yCAA+D;AAC/D,yCAA8D;AAa9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAa,4BAA4B;IAS/B,iBAAiB,CACvB,iBAA4B,EAC5B,aAAuB,EACvB,cAAsB,EACtB,aAAuB;QAEvB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YAClD,MAAM,EACJ,WAAW,EAAE,EAAE,IAAI,EAAE,EACrB,KAAK,EACL,KAAK,EACL,MAAM,GACP,GAAG,QAAQ,CAAC;YACb,OAAO,CACL,IAAI,KAAK,iBAAiB,IAAI,KAAK,KAAK,aAAa,IAAI,KAAK,KAAK,aAAa,IAAI,MAAM,KAAK,cAAc,CAC9G,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,OAAO,CAAC;IACnB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuDG;IACK,mBAAmB;QAKzB,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QAEtE,MAAM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IAAI,KAAK,YAAY,GAAG,EAAE;gBACxB,iGAAiG;gBACjG,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;aAClC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;QAEF,OAAO,IAAA,cAAI,EAAC,IAAI,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACzD,IAAA,kBAAa,EAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACxC,CAAC;CACF;AA/PD,oEA+PC","sourcesContent":["import { writeFileSync } from \"fs\";\nimport path from \"path\";\nimport type { App } from \"aws-cdk-lib\";\nimport { Token } from \"aws-cdk-lib\";\nimport chalk from \"chalk\";\nimport { dump } from \"js-yaml\";\nimport { GuAutoScalingGroup } from \"../../constructs/autoscaling\";\nimport { GuStack } from \"../../constructs/core\";\nimport { GuLambdaFunction } from \"../../constructs/lambda\";\nimport { GuS3OriginBucket } from \"../../constructs/s3\";\nimport { autoscalingDeployment, uploadAutoscalingArtifact } from \"./deployments/autoscaling\";\nimport { addAmiParametersToCloudFormationDeployment, cloudFormationDeployment } from \"./deployments/cloudformation\";\nimport { updateLambdaDeployment, uploadLambdaArtifact } from \"./deployments/lambda\";\nimport { uploadStaticFilesDeployment } from \"./deployments/s3\";\nimport { groupByClassNameStackRegionStage } from \"./group-by\";\nimport type {\n ClassName,\n GroupedCdkStacks,\n Region,\n RiffRaffDeployment,\n RiffRaffDeploymentName,\n RiffRaffDeploymentProps,\n RiffRaffYaml,\n StackTag,\n StageTag,\n} from \"./types\";\n\n/**\n * A class that creates a `riff-raff.yaml` file.\n *\n * Rather than using this directly, prefer to use [[`GuRoot`]] instead.\n *\n * Supports:\n * - Multiple CloudFormation stacks\n * - Multiple regions\n * - Lambda applications\n * - EC2 (autoscaling) applications\n * - Upload of static files to S3\n *\n * For lambda applications, 3 deployments will be defined:\n * 1. Lambda upload (`aws-lambda`, `action: [uploadLambda]`)\n * 2. CloudFormation deploy (`cloud-formation`)\n * 3. Lambda update (`aws-lambda`, `action: [updateLambda]`)\n *\n * For EC2 applications, 3 deployments will be defined:\n * 1. Artifact upload (`autoscaling`, `action: [uploadArtifacts]`)\n * 2. CloudFormation deploy (`cloud-formation`)\n * 3. Autoscaling deploy (`autoscaling`, `action: [deploy]`)\n *\n * For S3 uploads, 2 deployments will be defined:\n * 1. Artifact upload (`aws-s3`, `action: [uploadStaticFiles]`)\n * 2. CloudFormation deploy (`cloud-formation`)\n *\n * It assumes a Riff-Raff bundle structure as follows:\n *\n * ```\n * .\n * ├── cdk.out\n * │ └── MyApplication.template.json\n * ├── my-application\n * │ └── my-application.deb\n * ├── my-lambda\n * │ └── my-lambda.zip\n * └── my-static-site\n * ├── index.html\n * ├── main.js\n * └── index.css\n * ```\n *\n * That is, all CloudFormation templates are in a `cdk.out` directory, and there is a directory per app.\n * Application artifact(s) are in the app directory.\n *\n * NOTE: The file extension is decided by you, the above file tree is used for illustration purposes.\n *\n * NOTE: Resources will be looked up by tags (Stack, Stage, App). Ensure your CFN stack is tagged appropriately!\n *\n * @see https://riffraff.gutools.co.uk/docs/reference/riff-raff.yaml.md\n * @see https://riffraff.gutools.co.uk/docs/magenta-lib/types\n */\nexport class RiffRaffYamlFileExperimental {\n private readonly allCdkStacks: GuStack[];\n private readonly allStackTags: StackTag[];\n private readonly allStageTags: StageTag[];\n private readonly allRegions: Region[];\n\n private readonly riffRaffYaml: RiffRaffYaml;\n private readonly outdir: string;\n\n private isCdkStackPresent(\n expectedClassName: ClassName,\n expectedStack: StackTag,\n expectedRegion: Region,\n expectedStage: StageTag\n ): boolean {\n const matches = this.allCdkStacks.find((cdkStack) => {\n const {\n constructor: { name },\n stack,\n stage,\n region,\n } = cdkStack;\n return (\n name === expectedClassName && stack === expectedStack && stage === expectedStage && region === expectedRegion\n );\n });\n\n return !!matches;\n }\n\n /**\n * Check there are the appropriate number of `GuStack`s.\n * Expect to find an instance for each combination of `GuStack`, `stack`, `region`, and `stage`.\n *\n * If not valid, a message is logged describing what is missing to aid debugging.\n *\n * Given the following:\n *\n * ```ts\n * const app = new App();\n *\n * class MyApplicationStack extends GuStack { }\n *\n * new MyApplicationStack(app, \"App-CODE-deploy\", {\n * env: {\n * region: \"eu-west-1\",\n * },\n * stack: \"deploy\",\n * stage: \"CODE\"\n * });\n *\n * new MyApplicationStack(app, \"App-PROD-media-service\", {\n * env: {\n * region: \"eu-west-1\",\n * },\n * stack: \"media-service\",\n * stage: \"PROD\",\n * });\n *\n * new MyApplicationStack(app, \"App-PROD-deploy\", {\n * env: {\n * region: \"eu-west-1\",\n * },\n * stack: \"deploy\",\n * stage: \"PROD\"\n * });\n * ```\n *\n * This will log a message like this, where ❌ denotes something missing,\n * specifically there is no `CODE` template for `media-service`.\n *\n * ```log\n * Unable to produce a working riff-raff.yaml file; missing 1 definitions (details below)\n *\n * For the class: MyApplicationStack\n *\n * ┌───────────────┬────────────────────────────┐\n * │ (index) │ eu-west-1 │\n * ├───────────────┼────────────────────────────┤\n * │ deploy │ { CODE: '✅', PROD: '✅' } │\n * │ media-service │ { CODE: '❌', PROD: '✅' } │\n * └───────────────┴────────────────────────────┘\n * ```\n *\n * @private\n */\n private validateStacksInApp(): void {\n type Found = \"✅\";\n type NotFound = \"❌\";\n type AppValidation = Record<ClassName, Record<StackTag, Record<Region, Record<StageTag, Found | NotFound>>>>;\n\n const { allCdkStacks, allStackTags, allStageTags, allRegions } = this;\n\n const checks: AppValidation = allCdkStacks.reduce((accClassName, { constructor: { name } }) => {\n return {\n ...accClassName,\n [name]: allStackTags.reduce((accStackTag, stackTag) => {\n return {\n ...accStackTag,\n [stackTag]: allRegions.reduce((accRegion, region) => {\n return {\n ...accRegion,\n [region]: allStageTags.reduce((accStageTag, stageTag) => {\n return {\n ...accStageTag,\n [stageTag]: this.isCdkStackPresent(name, stackTag, region, stageTag) ? \"✅\" : \"❌\",\n };\n }, {}),\n };\n }, {}),\n };\n }, {}),\n };\n }, {});\n\n const missingDefinitions = Object.values(checks).flatMap((groupedByStackTag) => {\n return Object.values(groupedByStackTag).flatMap((groupedByRegion) => {\n return Object.values(groupedByRegion).flatMap((groupedByStage) => {\n return Object.values(groupedByStage).filter((_) => _ === \"❌\");\n });\n });\n });\n\n if (missingDefinitions.length > 0) {\n const message = `Unable to produce a working riff-raff.yaml file; missing ${missingDefinitions.length} definitions`;\n\n console.log(`${message} (details below)`);\n Object.entries(checks).forEach(([className, detail]) => {\n console.log(`For the class: ${chalk.yellow(className)}`);\n console.table(detail);\n });\n\n throw new Error(message);\n }\n }\n\n private validateAllRegionsAreResolved(): void {\n const unresolved = this.allRegions.filter((region) => Token.isUnresolved(region));\n\n if (unresolved.length !== 0) {\n throw new Error(`Unable to produce a working riff-raff.yaml file; all stacks must have an explicit region set`);\n }\n }\n\n private getLambdas(cdkStack: GuStack): GuLambdaFunction[] {\n return cdkStack.node.findAll().filter((_) => _ instanceof GuLambdaFunction) as GuLambdaFunction[];\n }\n\n private getAutoScalingGroups(cdkStack: GuStack): GuAutoScalingGroup[] {\n return cdkStack.node.findAll().filter((_) => _ instanceof GuAutoScalingGroup) as GuAutoScalingGroup[];\n }\n\n private getOriginBuckets(cdkStack: GuStack): GuS3OriginBucket[] {\n // `GuS3OriginBucket` implements `IConstruct` to remove a `SuspiciousTypeOfGuard` warning here\n return cdkStack.node.findAll().filter((_) => _ instanceof GuS3OriginBucket) as GuS3OriginBucket[];\n }\n\n // eslint-disable-next-line custom-rules/valid-constructors -- this needs to sit above GuStack on the cdk tree\n constructor(app: App) {\n this.allCdkStacks = app.node.findAll().filter((_) => _ instanceof GuStack) as GuStack[];\n const allowedStages = new Set(this.allCdkStacks.map(({ stage }) => stage));\n this.allStageTags = Array.from(allowedStages);\n this.allStackTags = Array.from(new Set(this.allCdkStacks.map(({ stack }) => stack)));\n this.allRegions = Array.from(new Set(this.allCdkStacks.map(({ region }) => region)));\n\n this.validateStacksInApp();\n this.validateAllRegionsAreResolved();\n\n this.outdir = app.outdir;\n\n const deployments = new Map<RiffRaffDeploymentName, RiffRaffDeploymentProps>();\n\n const groupedStacks: GroupedCdkStacks = groupByClassNameStackRegionStage(this.allCdkStacks);\n\n Object.values(groupedStacks).forEach((stackTagGroup) => {\n Object.values(stackTagGroup).forEach((regionGroup) => {\n Object.values(regionGroup).forEach((stageGroup) => {\n const stacks: GuStack[] = Object.values(stageGroup).flat();\n\n if (stacks.length === 0) {\n throw new Error(\"Unable to produce a working riff-raff.yaml file; there are no stacks!\");\n }\n\n // The items in `stacks` only differ by stage, so we can just use the first item in the list.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length of `stacks` is checked above\n const stack = stacks[0]!;\n\n const lambdas = this.getLambdas(stack);\n const autoscalingGroups = this.getAutoScalingGroups(stack);\n const originBuckets = this.getOriginBuckets(stack);\n\n const artifactUploads: RiffRaffDeployment[] = [\n lambdas.map(uploadLambdaArtifact),\n autoscalingGroups.map(uploadAutoscalingArtifact),\n ].flat();\n artifactUploads.forEach(({ name, props }) => deployments.set(name, props));\n\n const cfnDeployment = cloudFormationDeployment(stacks, artifactUploads, this.outdir);\n deployments.set(cfnDeployment.name, cfnDeployment.props);\n\n lambdas.forEach((lambda) => {\n const lambdaDeployment = updateLambdaDeployment(lambda, cfnDeployment);\n deployments.set(lambdaDeployment.name, lambdaDeployment.props);\n });\n\n autoscalingGroups.forEach((asg) => {\n const asgDeployment = autoscalingDeployment(asg, cfnDeployment);\n deployments.set(asgDeployment.name, asgDeployment.props);\n\n deployments.set(cfnDeployment.name, addAmiParametersToCloudFormationDeployment(cfnDeployment, asg));\n });\n\n originBuckets.forEach((bucket) => {\n const staticFilesDeployment = uploadStaticFilesDeployment(this.allStageTags, bucket, cfnDeployment);\n deployments.set(staticFilesDeployment.name, staticFilesDeployment.props);\n });\n });\n });\n });\n\n this.riffRaffYaml = {\n allowedStages,\n deployments,\n };\n }\n\n /**\n * The `riff-raff.yaml` file as a string.\n * Useful for testing.\n */\n toYAML(): string {\n // Add support for ES6 Set and Map. See https://github.com/nodeca/js-yaml/issues/436.\n const replacer = (_key: string, value: unknown) => {\n if (value instanceof Set) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- this is how `js-yaml` is typed\n return Array.from(value);\n }\n if (value instanceof Map) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- this is how `js-yaml` is typed\n return Object.fromEntries(value);\n }\n return value;\n };\n\n return dump(this.riffRaffYaml, { replacer });\n }\n\n /**\n * Write the `riff-raff.yaml` file to disk.\n * It'll be located with the CFN JSON templates generated by `cdk synth`.\n */\n synth(): void {\n const outPath = path.join(this.outdir, \"riff-raff.yaml\");\n writeFileSync(outPath, this.toYAML());\n }\n}\n"]}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { GuStack } from "../../constructs/core";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
2
|
+
export type ClassName = string;
|
|
3
|
+
export type StackTag = string;
|
|
4
|
+
export type StageTag = string;
|
|
5
|
+
export type Region = string;
|
|
6
|
+
export type CdkStacksDifferingOnlyByStage = GuStack[];
|
|
7
7
|
export interface RiffRaffYaml {
|
|
8
8
|
allowedStages: Set<StageTag>;
|
|
9
9
|
deployments: Map<RiffRaffDeploymentName, RiffRaffDeploymentProps>;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export type RiffRaffDeploymentName = string;
|
|
12
12
|
export interface RiffRaffDeploymentProps {
|
|
13
13
|
type: string;
|
|
14
14
|
regions: Set<Region>;
|
|
15
15
|
stacks: Set<StackTag>;
|
|
16
16
|
app: string;
|
|
17
17
|
contentDirectory: string;
|
|
18
|
-
parameters: Record<string, string | boolean | Record<string, string
|
|
18
|
+
parameters: Record<string, string | boolean | Record<string, string> | Array<Record<string, string>>>;
|
|
19
19
|
dependencies?: RiffRaffDeploymentName[];
|
|
20
20
|
actions?: string[];
|
|
21
21
|
}
|
|
@@ -23,5 +23,5 @@ export interface RiffRaffDeployment {
|
|
|
23
23
|
name: RiffRaffDeploymentName;
|
|
24
24
|
props: RiffRaffDeploymentProps;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type GroupedCdkStacks = Record<ClassName, Record<StackTag, Record<Region, Record<StageTag, CdkStacksDifferingOnlyByStage>>>>;
|
|
27
27
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/experimental/riff-raff-yaml-file/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/experimental/riff-raff-yaml-file/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAC/B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAC5B,MAAM,MAAM,6BAA6B,GAAG,OAAO,EAAE,CAAC;AAEtD,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7B,WAAW,EAAE,GAAG,CAAC,sBAAsB,EAAE,uBAAuB,CAAC,CAAC;CACnE;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE5C,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACtG,YAAY,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,KAAK,EAAE,uBAAuB,CAAC;CAChC;AASD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CACnC,SAAS,EACT,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,6BAA6B,CAAC,CAAC,CAAC,CAClF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/experimental/riff-raff-yaml-file/types.ts"],"names":[],"mappings":"","sourcesContent":["// type aliases to, hopefully, improve readability\nimport type { GuStack } from \"../../constructs/core\";\n\nexport type ClassName = string;\nexport type StackTag = string;\nexport type StageTag = string;\nexport type Region = string;\nexport type CdkStacksDifferingOnlyByStage = GuStack[];\n\nexport interface RiffRaffYaml {\n allowedStages: Set<StageTag>;\n deployments: Map<RiffRaffDeploymentName, RiffRaffDeploymentProps>;\n}\n\nexport type RiffRaffDeploymentName = string;\n\nexport interface RiffRaffDeploymentProps {\n type: string;\n regions: Set<Region>;\n stacks: Set<StackTag>;\n app: string;\n contentDirectory: string;\n parameters: Record<string, string | boolean | Record<string, string
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/experimental/riff-raff-yaml-file/types.ts"],"names":[],"mappings":"","sourcesContent":["// type aliases to, hopefully, improve readability\nimport type { GuStack } from \"../../constructs/core\";\n\nexport type ClassName = string;\nexport type StackTag = string;\nexport type StageTag = string;\nexport type Region = string;\nexport type CdkStacksDifferingOnlyByStage = GuStack[];\n\nexport interface RiffRaffYaml {\n allowedStages: Set<StageTag>;\n deployments: Map<RiffRaffDeploymentName, RiffRaffDeploymentProps>;\n}\n\nexport type RiffRaffDeploymentName = string;\n\nexport interface RiffRaffDeploymentProps {\n type: string;\n regions: Set<Region>;\n stacks: Set<StackTag>;\n app: string;\n contentDirectory: string;\n parameters: Record<string, string | boolean | Record<string, string> | Array<Record<string, string>>>;\n dependencies?: RiffRaffDeploymentName[];\n actions?: string[];\n}\n\nexport interface RiffRaffDeployment {\n name: RiffRaffDeploymentName;\n props: RiffRaffDeploymentProps;\n}\n\n/*\n The aim here is to produce an identity of a `GuStack` as a composite of:\n - Class name\n - Stack tag\n - Region\n Finally, group by stage to help form the `templateStagePaths` property for the `cloud-formation` deployment type in `riff-raff.yaml`.\n */\nexport type GroupedCdkStacks = Record<\n ClassName,\n Record<StackTag, Record<Region, Record<StageTag, CdkStacksDifferingOnlyByStage>>>\n>;\n"]}
|
|
@@ -4,7 +4,7 @@ import { Construct } from "constructs";
|
|
|
4
4
|
import type { Http5xxAlarmProps, NoMonitoring } from "../constructs/cloudwatch";
|
|
5
5
|
import type { AppIdentity, GuStack } from "../constructs/core";
|
|
6
6
|
import type { GuLambdaFunction } from "../constructs/lambda";
|
|
7
|
-
export
|
|
7
|
+
export type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH";
|
|
8
8
|
export interface ApiTarget {
|
|
9
9
|
/**
|
|
10
10
|
* The path for the request (e.g. /test).
|
|
@@ -18,6 +18,10 @@ export interface ApiTarget {
|
|
|
18
18
|
* The Lambda function responsible for handling the request.
|
|
19
19
|
*/
|
|
20
20
|
lambda: GuLambdaFunction;
|
|
21
|
+
/**
|
|
22
|
+
* Whether an apiKey is required for this method.
|
|
23
|
+
*/
|
|
24
|
+
apiKeyRequired?: true;
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
27
|
* Configuration for an alarm based on the percentage of 5XX responses served by the API Gateway instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-multiple-lambdas.d.ts","sourceRoot":"","sources":["../../src/patterns/api-multiple-lambdas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAqB,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,
|
|
1
|
+
{"version":3,"file":"api-multiple-lambdas.d.ts","sourceRoot":"","sources":["../../src/patterns/api-multiple-lambdas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAqB,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEhF,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;IACvB;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAAC;IACzB;;OAEG;IACH,cAAc,CAAC,EAAE,IAAI,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,iBAAiB,CAAC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,iCAAkC,SAAQ,YAAY,EAAE,WAAW;IAClF;;OAEG;IACH,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB;;;;;;;OAOG;IACH,uBAAuB,EAAE,YAAY,GAAG,gBAAgB,CAAC;CAC1D;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,qBAAa,4BAA6B,SAAQ,SAAS;IACzD,SAAgB,GAAG,EAAE,OAAO,CAAC;gBAEjB,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,iCAAiC;CAwBrE"}
|
|
@@ -72,7 +72,9 @@ class GuApiGatewayWithLambdaByPath extends constructs_1.Construct {
|
|
|
72
72
|
this.api = apiGateway;
|
|
73
73
|
props.targets.map((target) => {
|
|
74
74
|
const resource = apiGateway.root.resourceForPath(target.path);
|
|
75
|
-
resource.addMethod(target.httpMethod, new aws_apigateway_1.LambdaIntegration(target.lambda)
|
|
75
|
+
resource.addMethod(target.httpMethod, new aws_apigateway_1.LambdaIntegration(target.lambda), {
|
|
76
|
+
apiKeyRequired: target.apiKeyRequired,
|
|
77
|
+
});
|
|
76
78
|
});
|
|
77
79
|
if (!isNoMonitoring(props.monitoringConfiguration)) {
|
|
78
80
|
new api_gateway_alarms_1.GuApiGateway5xxPercentageAlarm(scope, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-multiple-lambdas.js","sourceRoot":"","sources":["../../src/patterns/api-multiple-lambdas.ts"],"names":[],"mappings":";;;AACA,+DAAwE;AACxE,2CAAuC;AAEvC,oFAA6F;
|
|
1
|
+
{"version":3,"file":"api-multiple-lambdas.js","sourceRoot":"","sources":["../../src/patterns/api-multiple-lambdas.ts"],"names":[],"mappings":";;;AACA,+DAAwE;AACxE,2CAAuC;AAEvC,oFAA6F;AA8D7F,SAAS,cAAc,CACrB,uBAAwD;IAExD,OAAsB,uBAAwB,CAAC,YAAY,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAa,4BAA6B,SAAQ,sBAAS;IAGzD,YAAY,KAAc,EAAE,KAAwC;QAClE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,oCAAoC;QAC7D,MAAM,UAAU,GAAG,IAAI,wBAAO,CAAC,KAAK,EAAE,SAAS,EAAE;YAC/C,4FAA4F;YAC5F,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,EAAE;YACzD,GAAG,KAAK;SACT,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC;QACtB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3B,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC9D,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,kCAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;gBAC1E,cAAc,EAAE,MAAM,CAAC,cAAc;aACtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,uBAAuB,CAAC,EAAE;YAClD,IAAI,mDAA8B,CAAC,KAAK,EAAE;gBACxC,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,kBAAkB,EAAE,UAAU;gBAC9B,YAAY,EAAE,KAAK,CAAC,uBAAuB,CAAC,YAAY;gBACxD,GAAG,KAAK,CAAC,uBAAuB,CAAC,YAAY;aAC9C,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AA3BD,oEA2BC","sourcesContent":["import type { RestApiProps } from \"aws-cdk-lib/aws-apigateway\";\nimport { LambdaIntegration, RestApi } from \"aws-cdk-lib/aws-apigateway\";\nimport { Construct } from \"constructs\";\nimport type { Http5xxAlarmProps, NoMonitoring } from \"../constructs/cloudwatch\";\nimport { GuApiGateway5xxPercentageAlarm } from \"../constructs/cloudwatch/api-gateway-alarms\";\nimport type { AppIdentity, GuStack } from \"../constructs/core\";\nimport type { GuLambdaFunction } from \"../constructs/lambda\";\n\n// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods\nexport type HttpMethod = \"GET\" | \"HEAD\" | \"POST\" | \"PUT\" | \"DELETE\" | \"CONNECT\" | \"OPTIONS\" | \"TRACE\" | \"PATCH\";\n\nexport interface ApiTarget {\n /**\n * The path for the request (e.g. /test).\n */\n path: string;\n /**\n * The [[`HttpMethod`]] for the target (e.g. GET, POST, PUT).\n */\n httpMethod: HttpMethod;\n /**\n * The Lambda function responsible for handling the request.\n */\n lambda: GuLambdaFunction;\n /**\n * Whether an apiKey is required for this method.\n */\n apiKeyRequired?: true;\n}\n\n/**\n * Configuration for an alarm based on the percentage of 5XX responses served by the API Gateway instance.\n *\n * For example:\n *\n * ```typescript\n * monitoringConfiguration: {\n * snsTopicName: \"my-topic-for-cloudwatch-alerts\",\n * http5xxAlarm: {\n * tolerated5xxPercentage: <sensible_error_percentage_threshold>,\n * }\n * }\n * ```\n */\nexport interface ApiGatewayAlarms {\n snsTopicName: string;\n http5xxAlarm: Http5xxAlarmProps;\n noMonitoring?: false;\n}\n\nexport interface GuApiGatewayWithLambdaByPathProps extends RestApiProps, AppIdentity {\n /**\n * A list of [[`ApiTarget`]]s to configure for the API Gateway instance.\n */\n targets: ApiTarget[];\n /**\n * Alarm configuration for your API. For more details, see [[`ApiGatewayAlarms`]].\n *\n * If your team do not use CloudWatch, it's possible to opt-out with the following configuration:\n * ```typescript\n * monitoringConfiguration: { noMonitoring: true }\n * ```\n */\n monitoringConfiguration: NoMonitoring | ApiGatewayAlarms;\n}\n\nfunction isNoMonitoring(\n monitoringConfiguration: NoMonitoring | ApiGatewayAlarms\n): monitoringConfiguration is NoMonitoring {\n return (<NoMonitoring>monitoringConfiguration).noMonitoring;\n}\n\n/**\n * A pattern to create an API Gateway instance which uses path-based routing to route requests\n * to two or more Lambda functions.\n *\n * This pattern should be used if you need to configure path-based routing to serve different\n * requests with different Lambdas. If you intend to serve all traffic via a single Lambda, use\n * the [[`GuApiLambda`]] pattern instead.\n *\n * Example usage:\n *\n * ```typescript\n * // Configure lambdas\n * const lambdaOne = new GuLambdaFunction(this, \"lambda-one\", {\n * app: \"example-lambda-one\",\n * runtime: Runtime.NODEJS_14_X,\n * handler: \"lambda-one.handler\",\n * fileName: \"lambda-one.zip\",\n * });\n * const lambdaTwo = new GuLambdaFunction(this, \"lambda-two\", {\n * app: \"example-lambda-two\",\n * runtime: Runtime.NODEJS_14_X,\n * handler: \"lambda-two.handler\",\n * fileName: \"lambda-two.zip\",\n * });\n *\n * // Wire up the API\n * new GuApiGatewayWithLambdaByPath(this, {\n * app: \"example-api-gateway-instance\",\n * targets: [\n * {\n * path: \"lambda-one\",\n * httpMethod: \"GET\",\n * lambda: lambdaOne,\n * },\n * {\n * path: \"lambda-two\",\n * httpMethod: \"GET\",\n * lambda: lambdaTwo,\n * },\n * ],\n * // Create an alarm\n * monitoringConfiguration: {\n * snsTopicName: \"my-topic-for-cloudwatch-alerts\",\n * http5xxAlarm: {\n * tolerated5xxPercentage: 1,\n * }\n * }\n * });\n * ```\n *\n * For all API configuration options, see [[`GuApiGatewayWithLambdaByPathProps`]].\n *\n * For details on configuring the individual Lambda functions, see [[`GuLambdaFunction`]].\n */\nexport class GuApiGatewayWithLambdaByPath extends Construct {\n public readonly api: RestApi;\n\n constructor(scope: GuStack, props: GuApiGatewayWithLambdaByPathProps) {\n super(scope, props.app); // The assumption is `app` is unique\n const apiGateway = new RestApi(scope, \"RestApi\", {\n // Override to avoid clashes as default is just api ID, which is often shared across stages.\n restApiName: `${scope.stack}-${scope.stage}-${props.app}`,\n ...props,\n });\n\n this.api = apiGateway;\n props.targets.map((target) => {\n const resource = apiGateway.root.resourceForPath(target.path);\n resource.addMethod(target.httpMethod, new LambdaIntegration(target.lambda), {\n apiKeyRequired: target.apiKeyRequired,\n });\n });\n if (!isNoMonitoring(props.monitoringConfiguration)) {\n new GuApiGateway5xxPercentageAlarm(scope, {\n app: props.app,\n apiGatewayInstance: apiGateway,\n snsTopicName: props.monitoringConfiguration.snsTopicName,\n ...props.monitoringConfiguration.http5xxAlarm,\n });\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/patterns/ec2-app/base.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAS,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAI9E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAc,MAAM,8BAA8B,CAAC;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAmD,MAAM,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AW,EAAE,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC;IACvB,gBAAgB,EAAE,YAAY,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,EAAE,CAAC;CAC3B;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2KG;AACH,qBAAa,QAAS,SAAQ,SAAS;IASrC,SAAgB,GAAG,EAAE,IAAI,CAAC;IAC1B,SAAgB,WAAW,EAAE,aAAa,CAAC;IAC3C,SAAgB,YAAY,EAAE,yBAAyB,CAAC;IACxD,SAAgB,gBAAgB,EAAE,kBAAkB,CAAC;IACrD,SAAgB,QAAQ,EAAE,0BAA0B,CAAC;IACrD,SAAgB,WAAW,EAAE,wBAAwB,CAAC;gBAE1C,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa;CAsKjD"}
|
|
@@ -234,11 +234,6 @@ class GuEc2App extends constructs_1.Construct {
|
|
|
234
234
|
...(blockDevices && { blockDevices }),
|
|
235
235
|
imageRecipe,
|
|
236
236
|
});
|
|
237
|
-
// We are selectively tagging the ASG so that we can expose the number of stacks using this pattern
|
|
238
|
-
// based on which autoscaling groups possess this tag. It may become useful or necessary to tag all resources in the future,
|
|
239
|
-
// but we have decided that this is sufficient for now.
|
|
240
|
-
// TODO: Do we need to tag all resources with this value? What would the use-cases be?
|
|
241
|
-
aws_cdk_lib_1.Tags.of(autoScalingGroup).add(constants_1.MetadataKeys.PATTERN_NAME, this.constructor.name, { applyToLaunchedInstances: true });
|
|
242
237
|
// This allows automatic shipping of instance Cloud Init logs when using the
|
|
243
238
|
// `cdk-base` Amigo role on your AMI.
|
|
244
239
|
aws_cdk_lib_1.Tags.of(autoScalingGroup).add(constants_1.MetadataKeys.LOG_KINESIS_STREAM_NAME, core_1.GuLoggingStreamNameParameter.getInstance(scope).valueAsString);
|