Class NestedStack

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Stack
software.amazon.awscdk.NestedStack
All Implemented Interfaces:
ITaggable, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable
Direct Known Subclasses:
KubectlProvider

@Generated(value="jsii-pacmak/1.104.0 (build e79254c)", date="2024-11-15T10:24:53.545Z") @Stability(Stable) public class NestedStack extends Stack
A CloudFormation nested stack.

When you apply template changes to update a top-level stack, CloudFormation updates the top-level stack and initiates an update to its nested stacks. CloudFormation updates the resources of modified nested stacks, but does not update the resources of unmodified nested stacks.

Furthermore, this stack will not be treated as an independent deployment artifact (won't be listed in "cdk list" or deployable through "cdk deploy"), but rather only synthesized as a template and uploaded as an asset to S3.

Cross references of resource attributes between the parent stack and the nested stack will automatically be translated to stack parameters and outputs.

Example:

 import software.amazon.awscdk.*;
 import software.amazon.awscdk.customresources.CustomResourceConfig;
 import software.amazon.awscdk.services.s3.deployment.*;
 App app = new App();
 Stack stack = new Stack(app, "Stack");
 CustomResourceConfig.of(app).addLogRetentionLifetime(RetentionDays.TEN_YEARS);
 NestedStack nestedStackA = new NestedStack(stack, "NestedStackA");
 Bucket websiteBucketA = Bucket.Builder.create(nestedStackA, "WebsiteBucketA").build();
 BucketDeployment.Builder.create(nestedStackA, "s3deployA")
         .sources(List.of(Source.jsonData("file.json", Map.of("a", "b"))))
         .destinationBucket(websiteBucketA)
         .logRetention(RetentionDays.ONE_DAY)
         .build();
 NestedStack nestedStackB = new NestedStack(stack, "NestedStackB");
 Bucket websiteBucketB = Bucket.Builder.create(nestedStackB, "WebsiteBucketB").build();
 BucketDeployment.Builder.create(nestedStackB, "s3deployB")
         .sources(List.of(Source.jsonData("file.json", Map.of("a", "b"))))
         .destinationBucket(websiteBucketB)
         .logRetention(RetentionDays.ONE_DAY)
         .build();
 
  • Constructor Details

    • NestedStack

      protected NestedStack(software.amazon.jsii.JsiiObjectRef objRef)
    • NestedStack

      protected NestedStack(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • NestedStack

      @Stability(Stable) public NestedStack(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable NestedStackProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props -
    • NestedStack

      @Stability(Stable) public NestedStack(@NotNull software.constructs.Construct scope, @NotNull String id)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
  • Method Details

    • isNestedStack

      @Stability(Stable) @NotNull public static Boolean isNestedStack(@NotNull Object x)
      Checks if x is an object of type NestedStack.

      Parameters:
      x - This parameter is required.
    • setParameter

      @Stability(Stable) public void setParameter(@NotNull String name, @NotNull String value)
      Assign a value to one of the nested stack parameters.

      Parameters:
      name - The parameter name (ID). This parameter is required.
      value - The value to assign. This parameter is required.
    • getStackId

      @Stability(Stable) @NotNull public String getStackId()
      An attribute that represents the ID of the stack.

      This is a context aware attribute:

      • If this is referenced from the parent stack, it will return { "Ref": "LogicalIdOfNestedStackResource" }.
      • If this is referenced from the context of the nested stack, it will return { "Ref": "AWS::StackId" }

      Example value: arn:aws:cloudformation:us-east-2:123456789012:stack/mystack-mynestedstack-sggfrhxhum7w/f449b250-b969-11e0-a185-5081d0136786

      Overrides:
      getStackId in class Stack
    • getStackName

      @Stability(Stable) @NotNull public String getStackName()
      An attribute that represents the name of the nested stack.

      This is a context aware attribute:

      • If this is referenced from the parent stack, it will return a token that parses the name from the stack ID.
      • If this is referenced from the context of the nested stack, it will return { "Ref": "AWS::StackName" }

      Example value: mystack-mynestedstack-sggfrhxhum7w

      Overrides:
      getStackName in class Stack
    • getTemplateFile

      @Stability(Stable) @NotNull public String getTemplateFile()
      The name of the CloudFormation template file emitted to the output directory during synthesis.

      Example value: MyStack.template.json

      Overrides:
      getTemplateFile in class Stack
    • getNestedStackResource

      @Stability(Stable) @Nullable public CfnResource getNestedStackResource()
      If this is a nested stack, this represents its AWS::CloudFormation::Stack resource.

      undefined for top-level (non-nested) stacks.

      Overrides:
      getNestedStackResource in class Stack