Show / Hide Table of Contents

Class Stack

A root construct which represents a single CloudFormation stack.

Inheritance
System.Object
Construct
Stack
NestedStack
Implements
IConstruct
Constructs.IConstruct
IDependable
ITaggable
Inherited Members
Construct.IsConstruct(Object)
Construct.OnPrepare()
Construct.OnSynthesize(ISynthesisSession)
Construct.OnValidate()
Construct.Prepare()
Construct.Synthesize(ISynthesisSession)
Construct.Validate()
Construct.Node
Namespace: Amazon.CDK
Assembly: Amazon.CDK.dll
Syntax (csharp)
public class Stack : Construct, IConstruct, IConstruct, IDependable, ITaggable
Syntax (vb)
Public Class Stack
    Inherits Construct
    Implements IConstruct, IConstruct, IDependable, ITaggable

Synopsis

Constructors

Stack(ByRefValue)

Used by jsii to construct an instance of this class from a Javascript-owned object reference

Stack(DeputyBase.DeputyProps)

Used by jsii to construct an instance of this class from DeputyProps

Stack(Construct, String, IStackProps)

Creates a new stack.

Properties

Account

The AWS account into which this stack will be deployed.

ArtifactId

The ID of the cloud assembly artifact for this stack.

AvailabilityZones

Returns the list of AZs that are available in the AWS environment (account/region) associated with this stack.

Dependencies

Return the stacks this stack depends on.

Environment

The environment coordinates in which this stack is deployed.

Nested

Indicates if this is a nested stack, in which case parentStack will include a reference to it's parent.

NestedStackParent

If this is a nested stack, returns it's parent stack.

NestedStackResource

(experimental) If this is a nested stack, this represents its AWS::CloudFormation::Stack resource.

NotificationArns

Returns the list of notification Amazon Resource Names (ARNs) for the current stack.

ParentStack

(deprecated) Returns the parent of a nested stack.

Partition

The partition in which this stack is defined.

Region

The AWS region into which this stack will be deployed (e.g. us-west-2).

StackId

The ID of the stack.

StackName

The concrete CloudFormation physical stack name.

Synthesizer

(experimental) Synthesis method for this stack.

Tags

Tags to be applied to the stack.

TemplateFile

The name of the CloudFormation template file emitted to the output directory during synthesis.

TemplateOptions

Options for CloudFormation template (like version, transform, description).

TerminationProtection

Whether termination protection is enabled for this stack.

UrlSuffix

The Amazon domain suffix for the region in which this stack is defined.

Methods

AddDependency(Stack, String)

Add a dependency between this stack and another stack.

AddDockerImageAsset(IDockerImageAssetSource)

(deprecated) Register a docker image asset on this Stack.

AddFileAsset(IFileAssetSource)

(deprecated) Register a file asset on this Stack.

AddTransform(String)

Add a Transform to this stack. A Transform is a macro that AWS CloudFormation uses to process your template.

AllocateLogicalId(CfnElement)

Returns the naming scheme used to allocate logical IDs.

ExportValue(Object, IExportValueOptions)

Create a CloudFormation Export for a value.

FormatArn(IArnComponents)

Creates an ARN from components.

GetLogicalId(CfnElement)

Allocates a stack-unique CloudFormation-compatible logical identity for a specific resource.

IsStack(Object)

Return whether the given object is a Stack.

Of(IConstruct)

Looks up the first stack scope in which construct is defined.

ParseArn(String, String, Nullable<Boolean>)

Given an ARN, parses it and returns components.

PrepareCrossReference(Stack, Reference)

(deprecated) Deprecated.

RenameLogicalId(String, String)

Rename a generated logical identities.

ReportMissingContext(IMissingContext)

Indicate that a context key was expected.

Resolve(Object)

Resolve a tokenized value in the context of the current stack.

ToJsonString(Object, Nullable<Double>)

Convert an object, potentially containing tokens, to a JSON string.

Constructors

Stack(ByRefValue)

Used by jsii to construct an instance of this class from a Javascript-owned object reference

protected Stack(ByRefValue reference)
Parameters
reference Amazon.JSII.Runtime.Deputy.ByRefValue

The Javascript-owned object reference

Stack(DeputyBase.DeputyProps)

Used by jsii to construct an instance of this class from DeputyProps

protected Stack(DeputyBase.DeputyProps props)
Parameters
props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps

The deputy props

Stack(Construct, String, IStackProps)

Creates a new stack.

public Stack(Construct scope = null, string id = null, IStackProps props = null)
Parameters
scope Constructs.Construct

Parent of this stack, usually an App or a Stage, but could be any construct.

id System.String

The construct ID of this stack.

props IStackProps

Stack properties.

Properties

Account

The AWS account into which this stack will be deployed.

public virtual string Account { get; }
Property Value

System.String

Remarks

This value is resolved according to the following rules:

    Preferably, you should use the return value as an opaque string and not attempt to parse it to implement your logic. If you do, you must first check that it is a concerete value an not an unresolved token. If this value is an unresolved token (Token.isUnresolved(stack.account) returns true), this implies that the user wishes that this stack will synthesize into a account-agnostic template. In this case, your code should either fail (throw an error, emit a synth error using Annotations.of(construct).addError()) or implement some other region-agnostic behavior.

    ArtifactId

    The ID of the cloud assembly artifact for this stack.

    public virtual string ArtifactId { get; }
    Property Value

    System.String

    AvailabilityZones

    Returns the list of AZs that are available in the AWS environment (account/region) associated with this stack.

    public virtual string[] AvailabilityZones { get; }
    Property Value

    System.String[]

    Remarks

    If the stack is environment-agnostic (either account and/or region are tokens), this property will return an array with 2 tokens that will resolve at deploy-time to the first two availability zones returned from CloudFormation's Fn::GetAZs intrinsic function.

    If they are not available in the context, returns a set of dummy values and reports them as missing, and let the CLI resolve them by calling EC2 DescribeAvailabilityZones on the target environment.

    To specify a different strategy for selecting availability zones override this method.

    Dependencies

    Return the stacks this stack depends on.

    public virtual Stack[] Dependencies { get; }
    Property Value

    Stack[]

    Environment

    The environment coordinates in which this stack is deployed.

    public virtual string Environment { get; }
    Property Value

    System.String

    Remarks

    In the form aws://account/region. Use stack.account and stack.region to obtain the specific values, no need to parse.

    You can use this value to determine if two stacks are targeting the same environment.

    If either stack.account or stack.region are not concrete values (e.g. Aws.account or Aws.region) the special strings unknown-account and/or unknown-region will be used respectively to indicate this stack is region/account-agnostic.

    Nested

    Indicates if this is a nested stack, in which case parentStack will include a reference to it's parent.

    public virtual bool Nested { get; }
    Property Value

    System.Boolean

    NestedStackParent

    If this is a nested stack, returns it's parent stack.

    public virtual Stack NestedStackParent { get; }
    Property Value

    Stack

    NestedStackResource

    (experimental) If this is a nested stack, this represents its AWS::CloudFormation::Stack resource.

    public virtual CfnResource NestedStackResource { get; }
    Property Value

    CfnResource

    Remarks

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

    Stability: Experimental

    NotificationArns

    Returns the list of notification Amazon Resource Names (ARNs) for the current stack.

    public virtual string[] NotificationArns { get; }
    Property Value

    System.String[]

    ParentStack

    (deprecated) Returns the parent of a nested stack.

    public virtual Stack ParentStack { get; }
    Property Value

    Stack

    Remarks

    Stability: Deprecated

    Partition

    The partition in which this stack is defined.

    public virtual string Partition { get; }
    Property Value

    System.String

    Region

    The AWS region into which this stack will be deployed (e.g. us-west-2).

    public virtual string Region { get; }
    Property Value

    System.String

    Remarks

    This value is resolved according to the following rules:

      Preferably, you should use the return value as an opaque string and not attempt to parse it to implement your logic. If you do, you must first check that it is a concerete value an not an unresolved token. If this value is an unresolved token (Token.isUnresolved(stack.region) returns true), this implies that the user wishes that this stack will synthesize into a region-agnostic template. In this case, your code should either fail (throw an error, emit a synth error using Annotations.of(construct).addError()) or implement some other region-agnostic behavior.

      StackId

      The ID of the stack.

      public virtual string StackId { get; }
      Property Value

      System.String

      Examples
      // Example automatically generated. See https://github.com/aws/jsii/issues/826
      // After resolving, looks like
      "arn:aws:cloudformation:us-west-2:123456789012:stack/teststack/51af3dc0-da77-11e4-872e-1234567db123";

      StackName

      The concrete CloudFormation physical stack name.

      public virtual string StackName { get; }
      Property Value

      System.String

      Remarks

      This is either the name defined explicitly in the stackName prop or allocated based on the stack's location in the construct tree. Stacks that are directly defined under the app use their construct id as their stack name. Stacks that are defined deeper within the tree will use a hashed naming scheme based on the construct path to ensure uniqueness.

      If you wish to obtain the deploy-time AWS::StackName intrinsic, you can use Aws.stackName directly.

      Synthesizer

      (experimental) Synthesis method for this stack.

      public virtual IStackSynthesizer Synthesizer { get; }
      Property Value

      IStackSynthesizer

      Remarks

      Stability: Experimental

      Tags

      Tags to be applied to the stack.

      public virtual TagManager Tags { get; }
      Property Value

      TagManager

      TemplateFile

      The name of the CloudFormation template file emitted to the output directory during synthesis.

      public virtual string TemplateFile { get; }
      Property Value

      System.String

      Examples
      // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
      "MyStack.template.json";

      TemplateOptions

      Options for CloudFormation template (like version, transform, description).

      public virtual ITemplateOptions TemplateOptions { get; }
      Property Value

      ITemplateOptions

      TerminationProtection

      Whether termination protection is enabled for this stack.

      public virtual Nullable<bool> TerminationProtection { get; }
      Property Value

      System.Nullable<System.Boolean>

      UrlSuffix

      The Amazon domain suffix for the region in which this stack is defined.

      public virtual string UrlSuffix { get; }
      Property Value

      System.String

      Methods

      AddDependency(Stack, String)

      Add a dependency between this stack and another stack.

      public virtual void AddDependency(Stack target, string reason = null)
      Parameters
      target Stack
      reason System.String
      Remarks

      This can be used to define dependencies between any two stacks within an app, and also supports nested stacks.

      AddDockerImageAsset(IDockerImageAssetSource)

      (deprecated) Register a docker image asset on this Stack.

      public virtual IDockerImageAssetLocation AddDockerImageAsset(IDockerImageAssetSource asset)
      Parameters
      asset IDockerImageAssetSource
      Returns

      IDockerImageAssetLocation

      Remarks

      Stability: Deprecated

      AddFileAsset(IFileAssetSource)

      (deprecated) Register a file asset on this Stack.

      public virtual IFileAssetLocation AddFileAsset(IFileAssetSource asset)
      Parameters
      asset IFileAssetSource
      Returns

      IFileAssetLocation

      Remarks

      Stability: Deprecated

      AddTransform(String)

      Add a Transform to this stack. A Transform is a macro that AWS CloudFormation uses to process your template.

      public virtual void AddTransform(string transform)
      Parameters
      transform System.String

      The transform to add.

      Remarks

      Duplicate values are removed when stack is synthesized.

      See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html

      Examples
      // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
      stack.AddTransform("AWS::Serverless-2016-10-31");

      AllocateLogicalId(CfnElement)

      Returns the naming scheme used to allocate logical IDs.

      protected virtual string AllocateLogicalId(CfnElement cfnElement)
      Parameters
      cfnElement CfnElement

      The element for which the logical ID is allocated.

      Returns

      System.String

      Remarks

      By default, uses the HashedAddressingScheme but this method can be overridden to customize this behavior.

      In order to make sure logical IDs are unique and stable, we hash the resource construct tree path (i.e. toplevel/secondlevel/.../myresource) and add it as a suffix to the path components joined without a separator (CloudFormation IDs only allow alphanumeric characters).

      The result will be:

      <path.join('')><md5(path.join('/')> "human" "hash"

      If the "human" part of the ID exceeds 240 characters, we simply trim it so the total ID doesn't exceed CloudFormation's 255 character limit.

      We only take 8 characters from the md5 hash (0.000005 chance of collision).

      Special cases:

        ExportValue(Object, IExportValueOptions)

        Create a CloudFormation Export for a value.

        public virtual string ExportValue(object exportedValue, IExportValueOptions options = null)
        Parameters
        exportedValue System.Object
        options IExportValueOptions
        Returns

        System.String

        Remarks

        Returns a string representing the corresponding Fn.importValue() expression for this Export. You can control the name for the export by passing the name option.

        If you don't supply a value for name, the value you're exporting must be a Resource attribute (for example: bucket.bucketName) and it will be given the same name as the automatic cross-stack reference that would be created if you used the attribute in another Stack.

        One of the uses for this method is to remove the relationship between two Stacks established by automatic cross-stack references. It will temporarily ensure that the CloudFormation Export still exists while you remove the reference from the consuming stack. After that, you can remove the resource and the manual export.

        Example

        Here is how the process works. Let's say there are two stacks, producerStack and consumerStack, and producerStack has a bucket called bucket, which is referenced by consumerStack (perhaps because an AWS Lambda Function writes into it, or something like that).

        It is not safe to remove producerStack.bucket because as the bucket is being deleted, consumerStack might still be using it.

        Instead, the process takes two deployments:

        Deployment 1: break the relationship

          Deployment 2: remove the bucket resource

            FormatArn(IArnComponents)

            Creates an ARN from components.

            public virtual string FormatArn(IArnComponents components)
            Parameters
            components IArnComponents
            Returns

            System.String

            Remarks

            If partition, region or account are not specified, the stack's partition, region and account will be used.

            If any component is the empty string, an empty string will be inserted into the generated ARN at the location that component corresponds to.

            The ARN will be formatted as follows:

            arn:{partition}:{service}:{region}:{account}:{resource}{sep}}{resource-name}

            The required ARN pieces that are omitted will be taken from the stack that the 'scope' is attached to. If all ARN pieces are supplied, the supplied scope can be 'undefined'.

            GetLogicalId(CfnElement)

            Allocates a stack-unique CloudFormation-compatible logical identity for a specific resource.

            public virtual string GetLogicalId(CfnElement element)
            Parameters
            element CfnElement

            The CloudFormation element for which a logical identity is needed.

            Returns

            System.String

            Remarks

            This method is called when a CfnElement is created and used to render the initial logical identity of resources. Logical ID renames are applied at this stage.

            This method uses the protected method allocateLogicalId to render the logical ID for an element. To modify the naming scheme, extend the Stack class and override this method.

            IsStack(Object)

            Return whether the given object is a Stack.

            public static bool IsStack(object x)
            Parameters
            x System.Object
            Returns

            System.Boolean

            Remarks

            We do attribute detection since we can't reliably use 'instanceof'.

            Of(IConstruct)

            Looks up the first stack scope in which construct is defined.

            public static Stack Of(IConstruct construct)
            Parameters
            construct Constructs.IConstruct

            The construct to start the search from.

            Returns

            Stack

            Remarks

            Fails if there is no stack up the tree.

            ParseArn(String, String, Nullable<Boolean>)

            Given an ARN, parses it and returns components.

            public virtual IArnComponents ParseArn(string arn, string sepIfToken = null, Nullable<bool> hasName = null)
            Parameters
            arn System.String

            The ARN string to parse.

            sepIfToken System.String

            The separator used to separate resource from resourceName.

            hasName System.Nullable<System.Boolean>

            Whether there is a name component in the ARN at all.

            Returns

            IArnComponents

            an ArnComponents object which allows access to the various components of the ARN.

            Remarks

            IF THE ARN IS A CONCRETE STRING...

            ...it will be parsed and validated. The separator (sep) will be set to '/' if the 6th component includes a '/', in which case, resource will be set to the value before the '/' and resourceName will be the rest. In case there is no '/', resource will be set to the 6th components and resourceName will be set to the rest of the string.

            IF THE ARN IS A TOKEN...

            ...it cannot be validated, since we don't have the actual value yet at the time of this function call. You will have to supply sepIfToken and whether or not ARNs of the expected format usually have resource names in order to parse it properly. The resulting ArnComponents object will contain tokens for the subexpressions of the ARN, not string literals.

            If the resource name could possibly contain the separator char, the actual resource name cannot be properly parsed. This only occurs if the separator char is '/', and happens for example for S3 object ARNs, IAM Role ARNs, IAM OIDC Provider ARNs, etc. To properly extract the resource name from a Tokenized ARN, you must know the resource type and call Arn.extractResourceName.

            PrepareCrossReference(Stack, Reference)

            (deprecated) Deprecated.

            protected virtual IResolvable PrepareCrossReference(Stack sourceStack, Reference reference)
            Parameters
            sourceStack Stack
            reference Reference
            Returns

            IResolvable

            reference itself without any change

            Remarks

            Stability: Deprecated

            See: https://github.com/aws/aws-cdk/pull/7187

            RenameLogicalId(String, String)

            Rename a generated logical identities.

            public virtual void RenameLogicalId(string oldId, string newId)
            Parameters
            oldId System.String
            newId System.String
            Remarks

            To modify the naming scheme strategy, extend the Stack class and override the allocateLogicalId method.

            ReportMissingContext(IMissingContext)

            Indicate that a context key was expected.

            public virtual void ReportMissingContext(IMissingContext report)
            Parameters
            report IMissingContext

            The set of parameters needed to obtain the context.

            Remarks

            Contains instructions which will be emitted into the cloud assembly on how the key should be supplied.

            Resolve(Object)

            Resolve a tokenized value in the context of the current stack.

            public virtual object Resolve(object obj)
            Parameters
            obj System.Object
            Returns

            System.Object

            ToJsonString(Object, Nullable<Double>)

            Convert an object, potentially containing tokens, to a JSON string.

            public virtual string ToJsonString(object obj, Nullable<double> space = null)
            Parameters
            obj System.Object
            space System.Nullable<System.Double>
            Returns

            System.String

            Implements

            IConstruct
            Constructs.IConstruct
            IDependable
            ITaggable
            Back to top Generated by DocFX