/
nested.ts
48 lines (42 loc) · 1.85 KB
/
nested.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { DockerImageAssetLocation, DockerImageAssetSource, FileAssetLocation, FileAssetSource } from '../assets';
import { ISynthesisSession } from '../construct-compat';
import { Stack } from '../stack';
import { assertBound } from './_shared';
import { StackSynthesizer } from './stack-synthesizer';
import { IStackSynthesizer } from './types';
/**
* Synthesizer for a nested stack
*
* Forwards all calls to the parent stack's synthesizer.
*
* This synthesizer is automatically used for `NestedStack` constructs.
* App builder do not need to use this class directly.
*/
export class NestedStackSynthesizer extends StackSynthesizer {
private stack?: Stack;
constructor(private readonly parentDeployment: IStackSynthesizer) {
super();
}
public bind(stack: Stack): void {
if (this.stack !== undefined) {
throw new Error('A StackSynthesizer can only be used for one Stack: create a new instance to use with a different Stack');
}
this.stack = stack;
}
public addFileAsset(asset: FileAssetSource): FileAssetLocation {
// Forward to parent deployment. By the magic of cross-stack references any parameter
// returned and used will magically be forwarded to the nested stack.
return this.parentDeployment.addFileAsset(asset);
}
public addDockerImageAsset(asset: DockerImageAssetSource): DockerImageAssetLocation {
// Forward to parent deployment. By the magic of cross-stack references any parameter
// returned and used will magically be forwarded to the nested stack.
return this.parentDeployment.addDockerImageAsset(asset);
}
public synthesize(session: ISynthesisSession): void {
assertBound(this.stack);
// Synthesize the template, but don't emit as a cloud assembly artifact.
// It will be registered as an S3 asset of its parent instead.
this.synthesizeStackTemplate(this.stack, session);
}
}