@composurecdk/cloudformation 0.1.2 → 0.3.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/README.md +107 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/outputs.d.ts +60 -0
- package/dist/outputs.d.ts.map +1 -0
- package/dist/outputs.js +52 -0
- package/dist/outputs.js.map +1 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# @composurecdk/cloudformation
|
|
2
|
+
|
|
3
|
+
CloudFormation builders for [ComposureCDK](../../README.md).
|
|
4
|
+
|
|
5
|
+
This package provides a fluent builder for CloudFormation Stacks, convenience stack strategies, and a post-build hook for creating CloudFormation outputs from composed systems.
|
|
6
|
+
|
|
7
|
+
## Stack Builder
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createStackBuilder } from "@composurecdk/cloudformation";
|
|
11
|
+
|
|
12
|
+
const { stack } = createStackBuilder()
|
|
13
|
+
.description("Network infrastructure")
|
|
14
|
+
.terminationProtection(true)
|
|
15
|
+
.build(app, "NetworkStack");
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Every [StackProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.StackProps.html) property is available as a fluent setter on the builder.
|
|
19
|
+
|
|
20
|
+
### Tags
|
|
21
|
+
|
|
22
|
+
Add tags that propagate to all resources within the stack:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const { stack } = createStackBuilder()
|
|
26
|
+
.tag("team", "platform")
|
|
27
|
+
.tag("environment", "production")
|
|
28
|
+
.build(app, "ServiceStack");
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Scope factory
|
|
32
|
+
|
|
33
|
+
Convert a configured builder into a `ScopeFactory` for use with stack strategies:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const factory = createStackBuilder()
|
|
37
|
+
.terminationProtection(true)
|
|
38
|
+
.tag("team", "platform")
|
|
39
|
+
.toScopeFactory();
|
|
40
|
+
|
|
41
|
+
compose({ ... }, { ... })
|
|
42
|
+
.withStackStrategy(singleStack(factory))
|
|
43
|
+
.build(app, "MySystem");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Stack Strategies
|
|
47
|
+
|
|
48
|
+
Convenience wrappers around `@composurecdk/core`'s strategy primitives that default to creating Stacks via `createStackBuilder`. Pass an optional `ScopeFactory` to customise the Stack configuration.
|
|
49
|
+
|
|
50
|
+
### singleStack
|
|
51
|
+
|
|
52
|
+
Places all components in a single auto-created Stack:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { singleStack } from "@composurecdk/cloudformation";
|
|
56
|
+
|
|
57
|
+
compose({ handler, api }, { handler: [], api: ["handler"] })
|
|
58
|
+
.withStackStrategy(singleStack())
|
|
59
|
+
.build(app, "MySystem");
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### groupedStacks
|
|
63
|
+
|
|
64
|
+
Groups components into named Stacks by a classifier function:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { groupedStacks } from "@composurecdk/cloudformation";
|
|
68
|
+
|
|
69
|
+
compose({ handler, api, table }, { ... })
|
|
70
|
+
.withStackStrategy(
|
|
71
|
+
groupedStacks((key) => (key === "table" ? "persistence" : "service")),
|
|
72
|
+
)
|
|
73
|
+
.build(app, "MySystem");
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## outputs
|
|
77
|
+
|
|
78
|
+
A post-build hook that creates CloudFormation stack outputs from a composed system's build results. Output values can be concrete strings or `Ref`s that resolve against the system's results.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { compose, ref } from "@composurecdk/core";
|
|
82
|
+
import { outputs } from "@composurecdk/cloudformation";
|
|
83
|
+
|
|
84
|
+
compose(
|
|
85
|
+
{ site: createBucketBuilder(), cdn: createDistributionBuilder() },
|
|
86
|
+
{ site: [], cdn: ["site"] },
|
|
87
|
+
)
|
|
88
|
+
.afterBuild(
|
|
89
|
+
outputs({
|
|
90
|
+
DistributionUrl: {
|
|
91
|
+
value: ref("cdn", (r) => `https://${r.distribution.distributionDomainName}`),
|
|
92
|
+
description: "CloudFront distribution URL",
|
|
93
|
+
},
|
|
94
|
+
BucketName: {
|
|
95
|
+
value: ref("site", (r) => r.bucket.bucketName),
|
|
96
|
+
description: "S3 bucket name for site content",
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
100
|
+
.build(stack, "StaticWebsite");
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Examples
|
|
104
|
+
|
|
105
|
+
- [MultiStackApp](../examples/src/multi-stack-app.ts) — REST API + Lambda split across stacks via `.withStacks()`
|
|
106
|
+
- [StrategyStackApp](../examples/src/strategy-stack-app.ts) — REST API + Lambda split across stacks via `.withStackStrategy()`
|
|
107
|
+
- [StaticWebsiteStack](../examples/src/static-website/app.ts) — CloudFormation outputs with `afterBuild` and `outputs`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { createStackBuilder, type IStackBuilder, type StackBuilderResult, } from "./stack-builder.js";
|
|
2
2
|
export { singleStack, groupedStacks } from "./strategies.js";
|
|
3
|
+
export { outputs, type OutputDefinition, type OutputDefinitions } from "./outputs.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAGnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAGnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAiD,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type AfterBuildHook, type Resolvable } from "@composurecdk/core";
|
|
2
|
+
/**
|
|
3
|
+
* Defines a CloudFormation stack output with a value that can be a
|
|
4
|
+
* {@link Resolvable} — either a concrete string or a {@link Ref} that
|
|
5
|
+
* resolves against the system's build results at build time.
|
|
6
|
+
*/
|
|
7
|
+
export interface OutputDefinition {
|
|
8
|
+
/** The output value, or a Ref that resolves to one. */
|
|
9
|
+
value: Resolvable<string>;
|
|
10
|
+
/** A description of the output. */
|
|
11
|
+
description?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The name under which the output is exported for cross-stack references.
|
|
14
|
+
* When set, this creates a CloudFormation Export.
|
|
15
|
+
*/
|
|
16
|
+
exportName?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A record of output definitions keyed by logical output name.
|
|
20
|
+
*/
|
|
21
|
+
export type OutputDefinitions = Record<string, OutputDefinition>;
|
|
22
|
+
/**
|
|
23
|
+
* Returns an {@link AfterBuildHook} that creates CloudFormation stack outputs
|
|
24
|
+
* from the composed system's build results.
|
|
25
|
+
*
|
|
26
|
+
* Each output definition's `value` can be a concrete string or a {@link Ref}
|
|
27
|
+
* that is resolved against the build results. This enables outputs that
|
|
28
|
+
* reference values produced by composed components without breaking the
|
|
29
|
+
* composition abstraction.
|
|
30
|
+
*
|
|
31
|
+
* Intended for use with {@link ComposedSystem.afterBuild}.
|
|
32
|
+
*
|
|
33
|
+
* @param defs - A record of output definitions keyed by logical name.
|
|
34
|
+
* @returns An {@link AfterBuildHook} that creates `CfnOutput` constructs.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { compose, ref } from "@composurecdk/core";
|
|
39
|
+
* import { outputs } from "@composurecdk/cloudformation";
|
|
40
|
+
*
|
|
41
|
+
* compose(
|
|
42
|
+
* { site: createBucketBuilder(), cdn: createDistributionBuilder() },
|
|
43
|
+
* { site: [], cdn: ["site"] },
|
|
44
|
+
* )
|
|
45
|
+
* .afterBuild(outputs({
|
|
46
|
+
* DistributionUrl: {
|
|
47
|
+
* value: ref("cdn", (r: DistributionBuilderResult) =>
|
|
48
|
+
* `https://${r.distribution.distributionDomainName}`),
|
|
49
|
+
* description: "CloudFront distribution URL",
|
|
50
|
+
* },
|
|
51
|
+
* BucketName: {
|
|
52
|
+
* value: ref("site", (r: BucketBuilderResult) => r.bucket.bucketName),
|
|
53
|
+
* description: "S3 bucket name for site content",
|
|
54
|
+
* },
|
|
55
|
+
* }))
|
|
56
|
+
* .build(stack, "StaticWebsite");
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function outputs(defs: OutputDefinitions): AfterBuildHook<object>;
|
|
60
|
+
//# sourceMappingURL=outputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputs.d.ts","sourceRoot":"","sources":["../src/outputs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAW,MAAM,oBAAoB,CAAC;AAEnF;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAE1B,mCAAmC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc,CAAC,MAAM,CAAC,CAYvE"}
|
package/dist/outputs.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CfnOutput } from "aws-cdk-lib";
|
|
2
|
+
import { resolve } from "@composurecdk/core";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an {@link AfterBuildHook} that creates CloudFormation stack outputs
|
|
5
|
+
* from the composed system's build results.
|
|
6
|
+
*
|
|
7
|
+
* Each output definition's `value` can be a concrete string or a {@link Ref}
|
|
8
|
+
* that is resolved against the build results. This enables outputs that
|
|
9
|
+
* reference values produced by composed components without breaking the
|
|
10
|
+
* composition abstraction.
|
|
11
|
+
*
|
|
12
|
+
* Intended for use with {@link ComposedSystem.afterBuild}.
|
|
13
|
+
*
|
|
14
|
+
* @param defs - A record of output definitions keyed by logical name.
|
|
15
|
+
* @returns An {@link AfterBuildHook} that creates `CfnOutput` constructs.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { compose, ref } from "@composurecdk/core";
|
|
20
|
+
* import { outputs } from "@composurecdk/cloudformation";
|
|
21
|
+
*
|
|
22
|
+
* compose(
|
|
23
|
+
* { site: createBucketBuilder(), cdn: createDistributionBuilder() },
|
|
24
|
+
* { site: [], cdn: ["site"] },
|
|
25
|
+
* )
|
|
26
|
+
* .afterBuild(outputs({
|
|
27
|
+
* DistributionUrl: {
|
|
28
|
+
* value: ref("cdn", (r: DistributionBuilderResult) =>
|
|
29
|
+
* `https://${r.distribution.distributionDomainName}`),
|
|
30
|
+
* description: "CloudFront distribution URL",
|
|
31
|
+
* },
|
|
32
|
+
* BucketName: {
|
|
33
|
+
* value: ref("site", (r: BucketBuilderResult) => r.bucket.bucketName),
|
|
34
|
+
* description: "S3 bucket name for site content",
|
|
35
|
+
* },
|
|
36
|
+
* }))
|
|
37
|
+
* .build(stack, "StaticWebsite");
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function outputs(defs) {
|
|
41
|
+
return (scope, _id, results) => {
|
|
42
|
+
const resultAsContext = results;
|
|
43
|
+
for (const [name, def] of Object.entries(defs)) {
|
|
44
|
+
new CfnOutput(scope, name, {
|
|
45
|
+
value: resolve(def.value, resultAsContext),
|
|
46
|
+
...(def.description !== undefined ? { description: def.description } : {}),
|
|
47
|
+
...(def.exportName !== undefined ? { exportName: def.exportName } : {}),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=outputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputs.js","sourceRoot":"","sources":["../src/outputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAwC,OAAO,EAAE,MAAM,oBAAoB,CAAC;AA0BnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,OAAO,CAAC,IAAuB;IAC7C,OAAO,CAAC,KAAiB,EAAE,GAAW,EAAE,OAAe,EAAE,EAAE;QACzD,MAAM,eAAe,GAAG,OAAiC,CAAC;QAE1D,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/C,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE;gBACzB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,eAAe,CAAC;gBAC1C,GAAG,CAAC,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC1E,GAAG,CAAC,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACxE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composurecdk/cloudformation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Composable CloudFormation stack builder and stack assignment strategies",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"type": "module",
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@composurecdk/core": "^0.
|
|
38
|
+
"@composurecdk/core": "^0.3.0",
|
|
39
39
|
"aws-cdk-lib": "^2.0.0",
|
|
40
40
|
"constructs": "^10.0.0"
|
|
41
41
|
},
|