Skip to content
v2.273.0

CloudFormationDeployStackSetAction Class ​

CodePipeline action to deploy a stackset.

CodePipeline offers the ability to perform AWS CloudFormation StackSets operations as part of your CI/CD process. You use a stack set to create stacks in AWS accounts across AWS Regions by using a single AWS CloudFormation template. All the resources included in each stack are defined by the stack set’s AWS CloudFormation template. When you create the stack set, you specify the template to use, as well as any parameters and capabilities that the template requires.

For more information about concepts for AWS CloudFormation StackSets, see StackSets concepts in the AWS CloudFormation User Guide.

If you use this action to make an update that includes adding stack instances, the new instances are deployed first and the update is completed last. The new instances first receive the old version, and then the update is applied to all instances.

As a best practice, you should construct your pipeline so that the stack set is created and initially deploys to a subset or a single instance. After you test your deployment and view the generated stack set, then add the CloudFormationStackInstances action so that the remaining instances are created and updated.

Example ​

ts
declare const pipeline: codepipeline.Pipeline;
declare const sourceOutput: codepipeline.Artifact;

pipeline.addStage({
  stageName: 'DeployStackSets',
  actions: [
    // First, update the StackSet itself with the newest template
    new codepipeline_actions.CloudFormationDeployStackSetAction({
      actionName: 'UpdateStackSet',
      runOrder: 1,
      stackSetName: 'MyStackSet',
      template: codepipeline_actions.StackSetTemplate.fromArtifactPath(sourceOutput.atPath('template.yaml')),

      // Change this to 'StackSetDeploymentModel.organizations()' if you want to deploy to OUs
      deploymentModel: codepipeline_actions.StackSetDeploymentModel.selfManaged(),
      // This deploys to a set of accounts
      stackInstances: codepipeline_actions.StackInstances.inAccounts(['111111111111'], ['us-east-1', 'eu-west-1']),
    }),

    // Afterwards, update/create additional instances in other accounts
    new codepipeline_actions.CloudFormationDeployStackInstancesAction({
      actionName: 'AddMoreInstances',
      runOrder: 2,
      stackSetName: 'MyStackSet',
      stackInstances: codepipeline_actions.StackInstances.inAccounts(
        ['222222222222', '333333333333'],
        ['us-east-1', 'eu-west-1']
      ),
    }),
  ],
});
python
# pipeline: codepipeline.Pipeline
# source_output: codepipeline.Artifact


pipeline.add_stage(
    stage_name="DeployStackSets",
    actions=[
        # First, update the StackSet itself with the newest template
        codepipeline_actions.CloudFormationDeployStackSetAction(
            action_name="UpdateStackSet",
            run_order=1,
            stack_set_name="MyStackSet",
            template=codepipeline_actions.StackSetTemplate.from_artifact_path(source_output.at_path("template.yaml")),

            # Change this to 'StackSetDeploymentModel.organizations()' if you want to deploy to OUs
            deployment_model=codepipeline_actions.StackSetDeploymentModel.self_managed(),
            # This deploys to a set of accounts
            stack_instances=codepipeline_actions.StackInstances.in_accounts(["111111111111"], ["us-east-1", "eu-west-1"])
        ),

        # Afterwards, update/create additional instances in other accounts
        codepipeline_actions.CloudFormationDeployStackInstancesAction(
            action_name="AddMoreInstances",
            run_order=2,
            stack_set_name="MyStackSet",
            stack_instances=codepipeline_actions.StackInstances.in_accounts(["222222222222", "333333333333"], ["us-east-1", "eu-west-1"])
        )
    ]
)
java
Pipeline pipeline;
Artifact sourceOutput;


pipeline.addStage(StageOptions.builder()
        .stageName("DeployStackSets")
        .actions(List.of(
            // First, update the StackSet itself with the newest template
            CloudFormationDeployStackSetAction.Builder.create()
                    .actionName("UpdateStackSet")
                    .runOrder(1)
                    .stackSetName("MyStackSet")
                    .template(StackSetTemplate.fromArtifactPath(sourceOutput.atPath("template.yaml")))

                    // Change this to 'StackSetDeploymentModel.organizations()' if you want to deploy to OUs
                    .deploymentModel(StackSetDeploymentModel.selfManaged())
                    // This deploys to a set of accounts
                    .stackInstances(StackInstances.inAccounts(List.of("111111111111"), List.of("us-east-1", "eu-west-1")))
                    .build(),

            // Afterwards, update/create additional instances in other accounts
            CloudFormationDeployStackInstancesAction.Builder.create()
                    .actionName("AddMoreInstances")
                    .runOrder(2)
                    .stackSetName("MyStackSet")
                    .stackInstances(StackInstances.inAccounts(List.of("222222222222", "333333333333"), List.of("us-east-1", "eu-west-1")))
                    .build()))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Pipeline pipeline;
Artifact sourceOutput;


pipeline.AddStage(new StageOptions {
    StageName = "DeployStackSets",
    Actions = new [] {
        // First, update the StackSet itself with the newest template
        new CloudFormationDeployStackSetAction(new CloudFormationDeployStackSetActionProps {
            ActionName = "UpdateStackSet",
            RunOrder = 1,
            StackSetName = "MyStackSet",
            Template = StackSetTemplate.FromArtifactPath(sourceOutput.AtPath("template.yaml")),

            // Change this to 'StackSetDeploymentModel.organizations()' if you want to deploy to OUs
            DeploymentModel = StackSetDeploymentModel.SelfManaged(),
            // This deploys to a set of accounts
            StackInstances = StackInstances.InAccounts(new [] { "111111111111" }, new [] { "us-east-1", "eu-west-1" })
        }),

        // Afterwards, update/create additional instances in other accounts
        new CloudFormationDeployStackInstancesAction(new CloudFormationDeployStackInstancesActionProps {
            ActionName = "AddMoreInstances",
            RunOrder = 2,
            StackSetName = "MyStackSet",
            StackInstances = StackInstances.InAccounts(new [] { "222222222222", "333333333333" }, new [] { "us-east-1", "eu-west-1" })
        }) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var pipeline Pipeline
var sourceOutput Artifact


pipeline.AddStage(&StageOptions{
	StageName: jsii.String("DeployStackSets"),
	Actions: []IAction{
		// First, update the StackSet itself with the newest template
		codepipeline_actions.NewCloudFormationDeployStackSetAction(&CloudFormationDeployStackSetActionProps{
			ActionName: jsii.String("UpdateStackSet"),
			RunOrder: jsii.Number(1),
			StackSetName: jsii.String("MyStackSet"),
			Template: codepipeline_actions.StackSetTemplate_FromArtifactPath(sourceOutput.AtPath(jsii.String("template.yaml"))),

			// Change this to 'StackSetDeploymentModel.organizations()' if you want to deploy to OUs
			DeploymentModel: codepipeline_actions.StackSetDeploymentModel_SelfManaged(),
			// This deploys to a set of accounts
			StackInstances: codepipeline_actions.StackInstances_InAccounts([]*string{
				jsii.String("111111111111"),
			}, []*string{
				jsii.String("us-east-1"),
				jsii.String("eu-west-1"),
			}),
		}),

		// Afterwards, update/create additional instances in other accounts
		codepipeline_actions.NewCloudFormationDeployStackInstancesAction(&CloudFormationDeployStackInstancesActionProps{
			ActionName: jsii.String("AddMoreInstances"),
			RunOrder: jsii.Number(2),
			StackSetName: jsii.String("MyStackSet"),
			StackInstances: codepipeline_actions.StackInstances_*InAccounts([]*string{
				jsii.String("222222222222"),
				jsii.String("333333333333"),
			}, []*string{
				jsii.String("us-east-1"),
				jsii.String("eu-west-1"),
			}),
		}),
	},
})

Initializer ​

ts
new CloudFormationDeployStackSetAction(props: CloudFormationDeployStackSetActionProps)
python
CloudFormationDeployStackSetAction(props: CloudFormationDeployStackSetActionProps)
java
new CloudFormationDeployStackSetAction(CloudFormationDeployStackSetActionProps props)
csharp
new CloudFormationDeployStackSetAction(CloudFormationDeployStackSetActionProps props)
go
NewCloudFormationDeployStackSetAction(Props CloudFormationDeployStackSetActionProps)

Properties ​

actionPropertiesActionPropertiesaction_propertiesActionPropertiesactionPropertiesActionPropertiesActionPropertiesActionPropertiesActionPropertiesActionPropertiesrequired#
The simple properties of the Action, like its Owner, name, etc.

Note that this accessor will be called before the bind callback.

Methods ​

bind(scope: Construct, stage: IStage, options: ActionBindOptions): ActionConfigdef bind(self, scope: Construct, stage: IStage, options: ActionBindOptions) -> ActionConfigpublic ActionConfig bind(Construct scope, IStage stage, ActionBindOptions options)public ActionConfig Bind(Construct scope, IStage stage, ActionBindOptions options)func Bind(Scope Construct, Stage IStage, Options ActionBindOptions) ActionConfig#
The callback invoked when this Action is added to a Pipeline.
onStateChange(name: string, target?: IRuleTarget, options?: RuleProps): Ruledef on_state_change(self, name: str, target: typing.Optional[IRuleTarget] = None, options: typing.Optional[RuleProps] = None) -> Rulepublic Rule onStateChange(String name, IRuleTarget target, RuleProps options)public Rule OnStateChange(string name, IRuleTarget? target = null, RuleProps? options = null)func OnStateChange(Name *string, Target IRuleTarget, Options RuleProps) Rule#
Creates an Event that will be triggered whenever the state of this Action changes.