Class Stack.Builder

java.lang.Object
software.amazon.awscdk.core.Stack.Builder
All Implemented Interfaces:
software.amazon.jsii.Builder<Stack>
Enclosing class:
Stack

@Stability(Stable) public static final class Stack.Builder extends Object implements software.amazon.jsii.Builder<Stack>
A fluent builder for Stack.
  • Method Details

    • create

      @Stability(Stable) public static Stack.Builder create(software.constructs.Construct scope, String id)
      Parameters:
      scope - Parent of this stack, usually an App or a Stage, but could be any construct.
      id - The construct ID of this stack.
      Returns:
      a new instance of Stack.Builder.
    • create

      @Stability(Stable) public static Stack.Builder create(software.constructs.Construct scope)
      Parameters:
      scope - Parent of this stack, usually an App or a Stage, but could be any construct.
      Returns:
      a new instance of Stack.Builder.
    • create

      @Stability(Stable) public static Stack.Builder create()
      Returns:
      a new instance of Stack.Builder.
    • analyticsReporting

      @Stability(Stable) public Stack.Builder analyticsReporting(Boolean analyticsReporting)
      Include runtime versioning information in this Stack.

      Default: `analyticsReporting` setting of containing `App`, or value of 'aws:cdk:version-reporting' context key

      Parameters:
      analyticsReporting - Include runtime versioning information in this Stack. This parameter is required.
      Returns:
      this
    • description

      @Stability(Stable) public Stack.Builder description(String description)
      A description of the stack.

      Default: - No description.

      Parameters:
      description - A description of the stack. This parameter is required.
      Returns:
      this
    • env

      @Stability(Stable) public Stack.Builder env(Environment env)
      The AWS environment (account/region) where this stack will be deployed.

      Set the region/account fields of env to either a concrete value to select the indicated environment (recommended for production stacks), or to the values of environment variables CDK_DEFAULT_REGION/CDK_DEFAULT_ACCOUNT to let the target environment depend on the AWS credentials/configuration that the CDK CLI is executed under (recommended for development stacks).

      If the Stack is instantiated inside a Stage, any undefined region/account fields from env will default to the same field on the encompassing Stage, if configured there.

      If either region or account are not set nor inherited from Stage, the Stack will be considered "environment-agnostic"". Environment-agnostic stacks can be deployed to any environment but may not be able to take advantage of all features of the CDK. For example, they will not be able to use environmental context lookups such as ec2.Vpc.fromLookup and will not automatically translate Service Principals to the right format based on the environment's AWS partition, and other such enhancements.

      Default: - The environment of the containing `Stage` if available, otherwise create the stack will be environment-agnostic.

      Example:

       // Use a concrete account and region to deploy this stack to:
       // `.account` and `.region` will simply return these values.
       // Use a concrete account and region to deploy this stack to:
       // `.account` and `.region` will simply return these values.
       Stack.Builder.create(app, "Stack1")
               .env(Environment.builder()
                       .account("123456789012")
                       .region("us-east-1")
                       .build())
               .build();
       // Use the CLI's current credentials to determine the target environment:
       // `.account` and `.region` will reflect the account+region the CLI
       // is configured to use (based on the user CLI credentials)
       // Use the CLI's current credentials to determine the target environment:
       // `.account` and `.region` will reflect the account+region the CLI
       // is configured to use (based on the user CLI credentials)
       Stack.Builder.create(app, "Stack2")
               .env(Environment.builder()
                       .account(process.getEnv().getCDK_DEFAULT_ACCOUNT())
                       .region(process.getEnv().getCDK_DEFAULT_REGION())
                       .build())
               .build();
       // Define multiple stacks stage associated with an environment
       Stage myStage = Stage.Builder.create(app, "MyStage")
               .env(Environment.builder()
                       .account("123456789012")
                       .region("us-east-1")
                       .build())
               .build();
       // both of these stacks will use the stage's account/region:
       // `.account` and `.region` will resolve to the concrete values as above
       // both of these stacks will use the stage's account/region:
       // `.account` and `.region` will resolve to the concrete values as above
       new MyStack(myStage, "Stack1");
       new YourStack(myStage, "Stack2");
       // Define an environment-agnostic stack:
       // `.account` and `.region` will resolve to `{ "Ref": "AWS::AccountId" }` and `{ "Ref": "AWS::Region" }` respectively.
       // which will only resolve to actual values by CloudFormation during deployment.
       // Define an environment-agnostic stack:
       // `.account` and `.region` will resolve to `{ "Ref": "AWS::AccountId" }` and `{ "Ref": "AWS::Region" }` respectively.
       // which will only resolve to actual values by CloudFormation during deployment.
       new MyStack(app, "Stack1");
       

      Parameters:
      env - The AWS environment (account/region) where this stack will be deployed. This parameter is required.
      Returns:
      this
    • stackName

      @Stability(Stable) public Stack.Builder stackName(String stackName)
      Name to deploy the stack with.

      Default: - Derived from construct path.

      Parameters:
      stackName - Name to deploy the stack with. This parameter is required.
      Returns:
      this
    • synthesizer

      @Stability(Stable) public Stack.Builder synthesizer(IStackSynthesizer synthesizer)
      Synthesis method to use while deploying this stack.

      Default: - `DefaultStackSynthesizer` if the `@aws-cdk/core:newStyleStackSynthesis` feature flag is set, `LegacyStackSynthesizer` otherwise.

      Parameters:
      synthesizer - Synthesis method to use while deploying this stack. This parameter is required.
      Returns:
      this
    • tags

      @Stability(Stable) public Stack.Builder tags(Map<String,String> tags)
      Stack tags that will be applied to all the taggable resources and the stack itself.

      Default: {}

      Parameters:
      tags - Stack tags that will be applied to all the taggable resources and the stack itself. This parameter is required.
      Returns:
      this
    • terminationProtection

      @Stability(Stable) public Stack.Builder terminationProtection(Boolean terminationProtection)
      Whether to enable termination protection for this stack.

      Default: false

      Parameters:
      terminationProtection - Whether to enable termination protection for this stack. This parameter is required.
      Returns:
      this
    • build

      @Stability(Stable) public Stack build()
      Specified by:
      build in interface software.amazon.jsii.Builder<Stack>
      Returns:
      a newly built instance of Stack.