Stack
- Implements: ITaggable
A root construct which represents a single ROS stack.
Initializers
import com.aliyun.ros.cdk.core.Stack;
Stack.Builder.create(Construct scope, java.lang.String id)
// .description(java.lang.String)
// .enableResourcePropertyConstraint(java.lang.Boolean)
// .env(Environment)
// .metadata(java.util.Map<java.lang.String, java.lang.Object>)
// .stackName(java.lang.String)
// .synthesizer(IStackSynthesizer)
// .tags(java.util.Map<java.lang.String, java.lang.String>)
// .version(java.lang.String)
.build();
| Name | Type | Description |
|---|---|---|
scope | Construct | Parent of this stack, usually a Program instance. |
id | java.lang.String | The construct ID of this stack. |
description | java.lang.String | A description of the stack. |
enableResourcePropertyConstraint | java.lang.Boolean | No description. |
env | Environment | The ALIYUN environment (account/region) where this stack will be deployed. |
metadata | java.util.Map | No description. |
stackName | java.lang.String | Name to deploy the stack with. |
synthesizer | IStackSynthesizer | Synthesis method to use while deploying this stack. |
tags | java.util.Map | Stack tags that will be applied to all the taggable resources and the stack itself. |
version | java.lang.String | No description. |
scopeOptional
- Type: Construct
Parent of this stack, usually a Program instance.
idOptional
- Type: java.lang.String
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: java.lang.String
- Default: No description.
A description of the stack.
enableResourcePropertyConstraintOptional
- Type: java.lang.Boolean
envOptional
- Type: Environment
- Default: The environment of the containing
Stageif 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.
// 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(Map.of(
"account", "123456789012",
"region", "cn-hangzhou"))
.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(Map.of(
"account", process.getEnv().getCDK_DEFAULT_ACCOUNT(),
"region", process.getEnv().getCDK_DEFAULT_REGION()))
.build();
// Define multiple stacks stage associated with an environment
Object myStage = Stage.Builder.create(app, "MyStage")
.env(Map.of(
"account", "123456789012",
"region", "cn-hangzhou"))
.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": "ALIYUN::AccountId" }` and `{ "Ref": "ALIYUN::Region" }` respectively.
// which will only resolve to actual values by ROS during deployment.
// 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.
new MyStack(app, "Stack1");
metadataOptional
- Type: java.util.Map
stackNameOptional
- Type: java.lang.String
- Default: Derived from construct path.
Name to deploy the stack with.
synthesizerOptional
- Type: IStackSynthesizer
- Default:
DefaultStackSynthesizer
Synthesis method to use while deploying this stack.
tagsOptional
- Type: java.util.Map
- Default: {}
Stack tags that will be applied to all the taggable resources and the stack itself.
versionOptional
- Type: java.lang.String
Methods
| Name | Description |
|---|---|
toString | Returns a string representation of this construct. |
synthesize | Allows this construct to emit artifacts into the cloud assembly during synthesis. |
addDependency | Add a dependency between this stack and another stack. |
getLogicalId | Allocates a stack-unique logical identity for a specific resource. |
renameLogicalId | Rename a generated logical identities. |
resolve | Resolve a tokenized value in the context of the current stack. |
splitArn | Splits the provided ARN into its components. |
toJsonString | Convert an object, potentially containing tokens, to a JSON string. |
toString
public java.lang.String toString()
Returns a string representation of this construct.
synthesize
public void synthesize(ISynthesisSession session)
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.
- Type: ISynthesisSession
addDependency
public void addDependency(Stack target)
public void addDependency(Stack target, java.lang.String reason)
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.
- Type: Stack
- Type: java.lang.String
getLogicalId
public java.lang.String getLogicalId(RosElement element)
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.
- Type: RosElement
The ROS element for which a logical identity is needed.
renameLogicalId
public void renameLogicalId(java.lang.String oldId, java.lang.String newId)
Rename a generated logical identities.
To modify the naming scheme strategy, extend the Stack class and override the allocateLogicalId method.
- Type: java.lang.String
- Type: java.lang.String
resolve
public java.lang.Object resolve(java.lang.Object obj)
Resolve a tokenized value in the context of the current stack.
- Type: java.lang.Object
splitArn
public ArnComponents splitArn(java.lang.String OR IResolvable arn, ArnFormat arnFormat)
Splits the provided ARN into its components.
Works both if 'arn' is a string like 'acs:ram::123456789012****:role/RoleName', and a Token representing a dynamic ROS expression (in which case the returned components will also be dynamic ROS expressions, encoded as Tokens).
- Type: java.lang.String OR IResolvable
the ARN to split into its components.
- Type: ArnFormat
the expected format of 'arn' - depends on what format the service 'arn' represents uses.
toJsonString
public java.lang.String toJsonString(java.lang.Object obj)
public java.lang.String toJsonString(java.lang.Object obj, java.lang.Number space)
Convert an object, potentially containing tokens, to a JSON string.
- Type: java.lang.Object
- Type: java.lang.Number
Static Functions
| Name | Description |
|---|---|
isConstruct | Return whether the given object is a Construct. |
isStack | Return whether the given object is a Stack. |
of | Looks up the first stack scope in which construct is defined. |
isConstruct
import com.aliyun.ros.cdk.core.Stack;
Stack.isConstruct(java.lang.Object x)
Return whether the given object is a Construct.
- Type: java.lang.Object
isStack
import com.aliyun.ros.cdk.core.Stack;
Stack.isStack(java.lang.Object x)
Return whether the given object is a Stack.
We do attribute detection since we can't reliably use 'instanceof'.
- Type: java.lang.Object
of
import com.aliyun.ros.cdk.core.Stack;
Stack.of(IConstruct construct)
Looks up the first stack scope in which construct is defined.
Fails if there is no stack up the tree.
- Type: IConstruct
The construct to start the search from.
Properties
| Name | Type | Description |
|---|---|---|
node | ConstructNode | The construct tree node associated with this construct. |
account | java.lang.String | The ALIYUN account into which this stack will be deployed. |
artifactId | java.lang.String | The ID of the cloud assembly artifact for this stack. |
bundlingRequired | java.lang.Boolean | Indicates whether the stack requires bundling or not. |
dependencies | java.util.List<Stack> | Return the stacks this stack depends on. |
enableResourcePropertyConstraint | java.lang.Boolean | No description. |
nested | java.lang.Boolean | Indicates if this is a nested stack, in which case parentStack will include a reference to it's parent. |
region | java.lang.String | The ALIYUN region into which this stack will be deployed (e.g. cn-beijing). |
stackId | java.lang.String | The ID of the stack. |
stackName | java.lang.String | The concrete ROS physical stack name. |
synthesizer | IStackSynthesizer | Synthesis method for this stack. |
tags | TagManager | Tags to be applied to the stack. |
templateFile | java.lang.String | The name of the ROS template file emitted to the output directory during synthesis. |
templateOptions | ITemplateOptions | Options for ROS template (like version, description). |
nestedStackParent | Stack | If this is a nested stack, returns it's parent stack. |
nestedStackResource | RosResource | If this is a nested stack, this represents its ALIYUN::ROS::Stack resource. |
parentStack | Stack | Returns the parent of a nested stack. |
roles | RamRoles | No description. |
nodeRequired
public ConstructNode getNode();
- Type: ConstructNode
The construct tree node associated with this construct.
accountRequired
public java.lang.String getAccount();
- Type: java.lang.String
The ALIYUN account into which this stack will be deployed.
This value is resolved according to the following rules:
- The value provided to
env.accountwhen the stack is defined. This can either be a concrete account or theALIYUN.ACCOUNT_IDtoken. 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.
artifactIdRequired
public java.lang.String getArtifactId();
- Type: java.lang.String
The ID of the cloud assembly artifact for this stack.
bundlingRequiredRequired
public java.lang.Boolean getBundlingRequired();
- Type: java.lang.Boolean
Indicates whether the stack requires bundling or not.
dependenciesRequired
public java.util.List<Stack> getDependencies();
- Type: java.util.List<Stack>
Return the stacks this stack depends on.
enableResourcePropertyConstraintRequired
public java.lang.Boolean getEnableResourcePropertyConstraint();
- Type: java.lang.Boolean
nestedRequired
public java.lang.Boolean getNested();
- Type: java.lang.Boolean
Indicates if this is a nested stack, in which case parentStack will include a reference to it's parent.
regionRequired
public java.lang.String getRegion();
- Type: java.lang.String
The ALIYUN region into which this stack will be deployed (e.g. cn-beijing).
This value is resolved according to the following rules:
- The value provided to
env.regionwhen the stack is defined. This can either be a concrete region or theALIYUN.REGIONtoken. 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.
stackIdRequired
public java.lang.String getStackId();
- Type: java.lang.String
The ID of the stack.
stackNameRequired
public java.lang.String getStackName();
- Type: java.lang.String
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
public IStackSynthesizer getSynthesizer();
- Type: IStackSynthesizer
Synthesis method for this stack.
tagsRequired
public TagManager getTags();
- Type: TagManager
Tags to be applied to the stack.
templateFileRequired
public java.lang.String getTemplateFile();
- Type: java.lang.String
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.getTemplate().getJson();
templateOptionsRequired
public ITemplateOptions getTemplateOptions();
- Type: ITemplateOptions
Options for ROS template (like version, description).
nestedStackParentOptional
public Stack getNestedStackParent();
- Type: Stack
If this is a nested stack, returns it's parent stack.
nestedStackResourceOptional
public RosResource getNestedStackResource();
- Type: RosResource
If this is a nested stack, this represents its ALIYUN::ROS::Stack resource.
undefined for top-level (non-nested) stacks.
~~parentStack~~Optional
- Deprecated: use
nestedStackParent
public Stack getParentStack();
- Type: Stack
Returns the parent of a nested stack.
rolesOptional
public RamRoles getRoles();
- Type: RamRoles