Skip to content

Stack

A root construct which represents a single ROS stack.

Initializers

import ros_cdk_core
ros_cdk_core.Stack(
  scope: Construct = None,
  id: str = None,
  description: str = None,
  enable_resource_property_constraint: bool = None,
  env: Environment = None,
  metadata: typing.Mapping[typing.Any] = None,
  stack_name: str = None,
  synthesizer: IStackSynthesizer = None,
  tags: typing.Mapping[str] = None,
  version: str = None
)
Name Type Description
scope Construct Parent of this stack, usually a Program instance.
id str The construct ID of this stack.
description str A description of the stack.
enable_resource_property_constraint bool No description.
env Environment The ALIYUN environment (account/region) where this stack will be deployed.
metadata typing.Mapping[typing.Any] No description.
stack_name str Name to deploy the stack with.
synthesizer IStackSynthesizer Synthesis method to use while deploying this stack.
tags typing.Mapping[str] Stack tags that will be applied to all the taggable resources and the stack itself.
version str No description.

scopeOptional

Parent of this stack, usually a Program instance.


idOptional

  • Type: str

The construct ID of this stack.

If stackName is not explicitly defined, this id (and any parent IDs) will be used to determine the physical ID of the stack.


descriptionOptional

  • Type: str
  • Default: No description.

A description of the stack.


enable_resource_property_constraintOptional

  • Type: bool

envOptional

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

The ALIYUN 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 ALIYUN 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.


Example

# Example automatically generated from non-compiling source. May contain errors.
# Use a concrete account and region to deploy this stack to:
# `.account` and `.region` will simply return these values.
Stack(app, "Stack1",
    env={
        "account": "123456789012",
        "region": "cn-hangzhou"
    }
)
# 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(app, "Stack2",
    env={
        "account": process.env.CDK_DEFAULT_ACCOUNT,
        "region": process.env.CDK_DEFAULT_REGION
    }
)
# Define multiple stacks stage associated with an environment
my_stage = Stage(app, "MyStage",
    env={
        "account": "123456789012",
        "region": "cn-hangzhou"
    }
)
# both of these stacks will use the stage's account/region:
# `.account` and `.region` will resolve to the concrete values as above
MyStack(my_stage, "Stack1")
YourStack(my_stage, "Stack2")
# Define an environment-agnostic stack:
# `.account` and `.region` will resolve to `{ "Ref": "ALIYUN::AccountId" }` and `{ "Ref": "ALIYUN::Region" }` respectively.
# which will only resolve to actual values by ROS during deployment.
MyStack(app, "Stack1")

metadataOptional

  • Type: typing.Mapping[typing.Any]

stack_nameOptional

  • Type: str
  • Default: Derived from construct path.

Name to deploy the stack with.


synthesizerOptional

Synthesis method to use while deploying this stack.


tagsOptional

  • Type: typing.Mapping[str]
  • Default: {}

Stack tags that will be applied to all the taggable resources and the stack itself.


versionOptional

  • Type: str

Methods

Name Description
to_string Returns a string representation of this construct.
synthesize Allows this construct to emit artifacts into the cloud assembly during synthesis.
add_dependency Add a dependency between this stack and another stack.
get_logical_id Allocates a stack-unique logical identity for a specific resource.
rename_logical_id Rename a generated logical identities.
resolve Resolve a tokenized value in the context of the current stack.
to_json_string Convert an object, potentially containing tokens, to a JSON string.

to_string

def to_string() -> str

Returns a string representation of this construct.

synthesize

def synthesize(
  session: ISynthesisSession
) -> None

Allows this construct to emit artifacts into the cloud assembly during synthesis.

This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

sessionRequired


add_dependency

def add_dependency(
  target: Stack,
  reason: str = None
) -> None

Add a dependency between this stack and another stack.

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

targetRequired


reasonOptional

  • Type: str

get_logical_id

def get_logical_id(
  element: RosElement
) -> str

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

This method is called when a RosElement 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.

elementRequired

The ROS element for which a logical identity is needed.


rename_logical_id

def rename_logical_id(
  old_id: str,
  new_id: str
) -> None

Rename a generated logical identities.

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

old_idRequired

  • Type: str

new_idRequired

  • Type: str

resolve

def resolve(
  obj: typing.Any
) -> typing.Any

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

objRequired

  • Type: typing.Any

to_json_string

def to_json_string(
  obj: typing.Any,
  space: typing.Union[int, float] = None
) -> str

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

objRequired

  • Type: typing.Any

spaceOptional

  • Type: typing.Union[int, float]

Static Functions

Name Description
is_construct Return whether the given object is a Construct.
is_stack Return whether the given object is a Stack.
of Looks up the first stack scope in which construct is defined.

is_construct

import ros_cdk_core
ros_cdk_core.Stack.is_construct(
  x: typing.Any
)

Return whether the given object is a Construct.

xRequired

  • Type: typing.Any

is_stack

import ros_cdk_core
ros_cdk_core.Stack.is_stack(
  x: typing.Any
)

Return whether the given object is a Stack.

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

xRequired

  • Type: typing.Any

of

import ros_cdk_core
ros_cdk_core.Stack.of(
  construct: IConstruct
)

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

Fails if there is no stack up the tree.

constructRequired

The construct to start the search from.


Properties

Name Type Description
node ConstructNode The construct tree node associated with this construct.
account str The ALIYUN account into which this stack will be deployed.
artifact_id str The ID of the cloud assembly artifact for this stack.
bundling_required bool Indicates whether the stack requires bundling or not.
dependencies typing.List[Stack] Return the stacks this stack depends on.
enable_resource_property_constraint bool No description.
nested bool Indicates if this is a nested stack, in which case parentStack will include a reference to it's parent.
region str The ALIYUN region into which this stack will be deployed (e.g. cn-beijing).
stack_id str The ID of the stack.
stack_name str The concrete ROS physical stack name.
synthesizer IStackSynthesizer Synthesis method for this stack.
tags TagManager Tags to be applied to the stack.
template_file str The name of the ROS template file emitted to the output directory during synthesis.
template_options ITemplateOptions Options for ROS template (like version, description).
nested_stack_parent Stack If this is a nested stack, returns it's parent stack.
nested_stack_resource RosResource If this is a nested stack, this represents its ALIYUN::ROS::Stack resource.
parent_stack Stack Returns the parent of a nested stack.
roles RamRoles No description.

nodeRequired

node: ConstructNode

The construct tree node associated with this construct.


accountRequired

account: str
  • Type: str

The ALIYUN account into which this stack will be deployed.

This value is resolved according to the following rules:

  1. The value provided to env.account when the stack is defined. This can either be a concrete account or the ALIYUN.ACCOUNT_ID token.
  2. ALIYUN.ACCOUNT_ID, which represents the ROS intrinsic reference { "Ref": "ALIYUN::AccountId" } encoded as a string token.

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 concrete 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.


artifact_idRequired

artifact_id: str
  • Type: str

The ID of the cloud assembly artifact for this stack.


bundling_requiredRequired

bundling_required: bool
  • Type: bool

Indicates whether the stack requires bundling or not.


dependenciesRequired

dependencies: typing.List[Stack]
  • Type: typing.List[Stack]

Return the stacks this stack depends on.


enable_resource_property_constraintRequired

enable_resource_property_constraint: bool
  • Type: bool

nestedRequired

nested: bool
  • Type: bool

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


regionRequired

region: str
  • Type: str

The ALIYUN region into which this stack will be deployed (e.g. cn-beijing).

This value is resolved according to the following rules:

  1. The value provided to env.region when the stack is defined. This can either be a concrete region or the ALIYUN.REGION token.
  2. ALIYUN.REGION, which is represents the ROS intrinsic reference { "Ref": "ALIYUN::Region" } encoded as a string token.

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 concrete 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.


stack_idRequired

stack_id: str
  • Type: str

The ID of the stack.


stack_nameRequired

stack_name: str
  • Type: str

The concrete ROS physical stack name.

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.


synthesizerRequired

synthesizer: IStackSynthesizer

Synthesis method for this stack.


tagsRequired

tags: TagManager

Tags to be applied to the stack.


template_fileRequired

template_file: str
  • Type: str

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


Example

# Example automatically generated from non-compiling source. May contain errors.
MyStack.template.json

template_optionsRequired

template_options: ITemplateOptions

Options for ROS template (like version, description).


nested_stack_parentOptional

nested_stack_parent: Stack

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


nested_stack_resourceOptional

nested_stack_resource: RosResource

If this is a nested stack, this represents its ALIYUN::ROS::Stack resource.

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


~~parent_stack~~Optional

  • Deprecated: use nestedStackParent
parent_stack: Stack

Returns the parent of a nested stack.


rolesOptional

roles: RamRoles