Skip to content
v2.274.0

Stage L2 construct ​

An abstract application modeling unit consisting of Stacks that should be deployed together.

Derive a subclass of Stage and use it to model a single instance of your application.

You can then instantiate your subclass multiple times to model multiple copies of your application which should be deployed to different environments.

Example ​

ts
declare const synth: pipelines.ShellStep;
const stage = new MyApplicationStage(this, 'MyApplication');
const pipeline = new pipelines.CodePipeline(this, 'Pipeline', { synth });

pipeline.addStage(stage, {
  post: [
    new pipelines.ShellStep('Approve', {
      // Use the contents of the 'integ' directory from the synth step as the input
      input: synth.addOutputDirectory('integ'),
      commands: ['cd integ && ./run.sh'],
    }),
  ],
});
python
# synth: pipelines.ShellStep

stage = MyApplicationStage(self, "MyApplication")
pipeline = pipelines.CodePipeline(self, "Pipeline", synth=synth)

pipeline.add_stage(stage,
    post=[
        pipelines.ShellStep("Approve",
            # Use the contents of the 'integ' directory from the synth step as the input
            input=synth.add_output_directory("integ"),
            commands=["cd integ && ./run.sh"]
        )
    ]
)
java
ShellStep synth;

MyApplicationStage stage = new MyApplicationStage(this, "MyApplication");
CodePipeline pipeline = CodePipeline.Builder.create(this, "Pipeline").synth(synth).build();

pipeline.addStage(stage, AddStageOpts.builder()
        .post(List.of(
            ShellStep.Builder.create("Approve")
                    // Use the contents of the 'integ' directory from the synth step as the input
                    .input(synth.addOutputDirectory("integ"))
                    .commands(List.of("cd integ && ./run.sh"))
                    .build()))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
ShellStep synth;

var stage = new MyApplicationStage(this, "MyApplication");
var pipeline = new CodePipeline(this, "Pipeline", new CodePipelineProps { Synth = synth });

pipeline.AddStage(stage, new AddStageOpts {
    Post = new [] {
        new ShellStep("Approve", new ShellStepProps {
            // Use the contents of the 'integ' directory from the synth step as the input
            Input = synth.AddOutputDirectory("integ"),
            Commands = new [] { "cd integ && ./run.sh" }
        }) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var synth ShellStep

stage := NewMyApplicationStage(this, jsii.String("MyApplication"))
pipeline := pipelines.NewCodePipeline(this, jsii.String("Pipeline"), &CodePipelineProps{
	Synth: Synth,
})

pipeline.AddStage(stage, &AddStageOpts{
	Post: []Step{
		pipelines.NewShellStep(jsii.String("Approve"), &ShellStepProps{
			// Use the contents of the 'integ' directory from the synth step as the input
			Input: synth.AddOutputDirectory(jsii.String("integ")),
			Commands: []*string{
				jsii.String("cd integ && ./run.sh"),
			},
		}),
	},
})

Initializer ​

ts
new Stage(scope: Construct, id: string, props?: StageProps)
python
Stage(scope: Construct, id: str, props: typing.Optional[StageProps] = None)
java
new Stage(Construct scope, String id, StageProps props)
csharp
new Stage(Construct scope, string id, StageProps? props = null)
go
NewStage(Scope Construct, Id *string, Props StageProps)

Construct Props ​

Default AWS environment (account/region) for `Stack`s in this `Stage`.

Default: The environments should be configured on the Stacks.

notes · example

Stacks defined inside this Stage with either region or account missing from its env will use the corresponding field given here.

If either region or accountis is not configured for Stack (either on the Stack itself or on the containing Stage), the Stack will be environment-agnostic.

Environment-agnostic stacks can be deployed to any environment, 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, will not automatically translate Service Principals to the right format based on the environment's AWS partition, and other such enhancements.

ts
// Use a concrete account and region to deploy this Stage to
new Stage(app, 'Stage1', {
  env: { account: '123456789012', region: 'us-east-1' },
});

// Use the CLI's current credentials to determine the target environment
new Stage(app, 'Stage2', {
  env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
});
outdirstringoutdirstroutdirStringOutdirstringOutdir*string#
The output directory into which to emit synthesized artifacts.

Default: for nested stages, outdir will be determined as a relative directory to the outdir of the app. For apps, if outdir is not specified, a temporary directory will be created.

Can only be specified if this stage is the root stage (the app). If this is specified and this stage is nested within another stage, an error will be thrown.

permissionsBoundaryPermissionsBoundarypermissions_boundaryPermissionsBoundarypermissionsBoundaryPermissionsBoundaryPermissionsBoundaryPermissionsBoundaryPermissionsBoundaryPermissionsBoundary#
Options for applying a permissions boundary to all IAM Roles and Users created within this Stage.

Default: no permissions boundary is applied

notes

Be aware that this feature uses Aspects, and the Aspects are applied at the Stack level with a priority of MUTATING (if the feature flag @aws-cdk/core:aspectPrioritiesMutating is set) or DEFAULT (if the flag is not set). This is relevant if you are both using your own Aspects to assign Permissions Boundaries, as well as specifying this property. The Aspect added by this property will overwrite the Permissions Boundary assigned by your own Aspect if both: (a) your Aspect has a lower or equal priority to the automatic Aspect, and (b) your Aspect is applied above the Stack level. If either of those conditions are not true, your own Aspect will win.

We recommend assigning Permissions Boundaries only using the provided APIs, and not using custom Aspects.

policyValidationBeta1IPolicyValidationPluginBeta1[]policy_validation_beta1typing.List[IPolicyValidationPluginBeta1]policyValidationBeta1List<IPolicyValidationPluginBeta1>PolicyValidationBeta1IPolicyValidationPluginBeta1[]PolicyValidationBeta1*[]IPolicyValidationPluginBeta1deprecated#
Use `Validations.of(stage).addPlugins()` instead.

Default: no validation plugins are used

If any plugin reports any violation, synthesis will be interrupted and the report displayed to the user.

propertyInjectorsIPropertyInjector[]property_injectorstyping.List[IPropertyInjector]propertyInjectorsList<IPropertyInjector>PropertyInjectorsIPropertyInjector[]PropertyInjectors*[]IPropertyInjector#
A list of IPropertyInjector attached to this Stage.

Default: no PropertyInjectors

stageNamestringstage_namestrstageNameStringStageNamestringStageName*string#
Name of this stage.

Default: Derived from the id.

Properties ​

accountstringaccountstraccountStringAccountstringAccount*string#
The default account for all resources defined within this stage.
artifactIdstringartifact_idstrartifactIdStringArtifactIdstringArtifactId*stringrequired#
Artifact ID of the assembly if it is a nested stage. The root stage (app) will return an empty string.

Derived from the construct path.

assetOutdirstringasset_outdirstrassetOutdirStringAssetOutdirstringAssetOutdir*stringrequired#
The cloud assembly asset output directory.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
outdirstringoutdirstroutdirStringOutdirstringOutdir*stringrequired#
The cloud assembly output directory.
parentStageStageparent_stageStageparentStageStageParentStageStageParentStageStage#
The parent stage or `undefined` if this is the app.
policyValidationBeta1IPolicyValidationPluginBeta1[]policy_validation_beta1typing.List[IPolicyValidationPluginBeta1]policyValidationBeta1List<IPolicyValidationPluginBeta1>PolicyValidationBeta1IPolicyValidationPluginBeta1[]PolicyValidationBeta1*[]IPolicyValidationPluginBeta1requireddeprecated#
Do not use this function to look up validation plugins. Use `Validations.of(stage).plugins` instead.

Default: no validation plugins are used

If any plugin reports any violation, synthesis will be interrupted and the report displayed to the user.

regionstringregionstrregionStringRegionstringRegion*string#
The default region for all resources defined within this stage.
stageNamestringstage_namestrstageNameStringStageNamestringStageName*stringrequired#
The name of the stage.

Based on names of the parent stages separated by hypens.

Methods ​

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isStage(x: any): boolean@staticmethod def is_stage(x: Any) -> boolpublic static Boolean isStage(Object x)public static bool IsStage(object x)func IsStage(X interface{}) *boolstatic#
Test whether the given construct is a stage.
of(construct: IConstruct): Stage // chainable@staticmethod def of(construct: IConstruct) -> Stagepublic static Stage of(IConstruct construct)public static Stage Of(IConstruct construct)func Of(Construct IConstruct) Stagestatic#
Return the stage this construct is contained with, if available.

If called on a nested stage, returns its parent.

synth(options?: StageSynthesisOptions): CloudAssemblydef synth(self, options: typing.Optional[StageSynthesisOptions] = None) -> CloudAssemblypublic CloudAssembly synth(StageSynthesisOptions options)public CloudAssembly Synth(StageSynthesisOptions? options = null)func Synth(Options StageSynthesisOptions) CloudAssembly#
Synthesize this stage into a cloud assembly.

Once an assembly has been synthesized, it cannot be modified. Subsequent calls will return the same assembly.

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining