CloudFormationCreateUpdateStackAction Class
CodePipeline action to deploy a stack.
Creates the stack if the specified stack doesn't exist. If the stack exists, AWS CloudFormation updates the stack. Use this action to update existing stacks.
AWS CodePipeline won't replace the stack, and will fail deployment if the stack is in a failed state. Use ReplaceOnFailure for an action that will delete and recreate the stack to try and recover from failed states.
Use this action to automatically replace failed stacks without recovering or troubleshooting them. You would typically choose this mode for testing.
Example
ts
import { PhysicalName } from 'aws-cdk-lib';
// in stack for account 123456789012...
declare const otherAccountStack: Stack;
const actionRole = new iam.Role(otherAccountStack, 'ActionRole', {
assumedBy: new iam.AccountPrincipal('123456789012'),
// the role has to have a physical name set
roleName: PhysicalName.GENERATE_IF_NEEDED,
});
// in the pipeline stack...
const sourceOutput = new codepipeline.Artifact();
new codepipeline_actions.CloudFormationCreateUpdateStackAction({
actionName: 'CloudFormationCreateUpdate',
stackName: 'MyStackName',
adminPermissions: true,
templatePath: sourceOutput.atPath('template.yaml'),
role: actionRole, // this action will be cross-account as well
});
python
from aws_cdk import PhysicalName
# in stack for account 123456789012...
# other_account_stack: Stack
action_role = iam.Role(other_account_stack, "ActionRole",
assumed_by=iam.AccountPrincipal("123456789012"),
# the role has to have a physical name set
role_name=PhysicalName.GENERATE_IF_NEEDED
)
# in the pipeline stack...
source_output = codepipeline.Artifact()
codepipeline_actions.CloudFormationCreateUpdateStackAction(
action_name="CloudFormationCreateUpdate",
stack_name="MyStackName",
admin_permissions=True,
template_path=source_output.at_path("template.yaml"),
role=action_role
)
java
import software.amazon.awscdk.PhysicalName;
// in stack for account 123456789012...
Stack otherAccountStack;
Role actionRole = Role.Builder.create(otherAccountStack, "ActionRole")
.assumedBy(new AccountPrincipal("123456789012"))
// the role has to have a physical name set
.roleName(PhysicalName.GENERATE_IF_NEEDED)
.build();
// in the pipeline stack...
Artifact sourceOutput = new Artifact();
CloudFormationCreateUpdateStackAction.Builder.create()
.actionName("CloudFormationCreateUpdate")
.stackName("MyStackName")
.adminPermissions(true)
.templatePath(sourceOutput.atPath("template.yaml"))
.role(actionRole)
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK;
// in stack for account 123456789012...
Stack otherAccountStack;
var actionRole = new Role(otherAccountStack, "ActionRole", new RoleProps {
AssumedBy = new AccountPrincipal("123456789012"),
// the role has to have a physical name set
RoleName = PhysicalName.GENERATE_IF_NEEDED
});
// in the pipeline stack...
var sourceOutput = new Artifact();
new CloudFormationCreateUpdateStackAction(new CloudFormationCreateUpdateStackActionProps {
ActionName = "CloudFormationCreateUpdate",
StackName = "MyStackName",
AdminPermissions = true,
TemplatePath = sourceOutput.AtPath("template.yaml"),
Role = actionRole
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
// in stack for account 123456789012...
var otherAccountStack Stack
actionRole := iam.NewRole(otherAccountStack, jsii.String("ActionRole"), &RoleProps{
AssumedBy: iam.NewAccountPrincipal(jsii.String("123456789012")),
// the role has to have a physical name set
RoleName: awscdk.PhysicalName_GENERATE_IF_NEEDED(),
})
// in the pipeline stack...
sourceOutput := codepipeline.NewArtifact()
codepipeline_actions.NewCloudFormationCreateUpdateStackAction(&CloudFormationCreateUpdateStackActionProps{
ActionName: jsii.String("CloudFormationCreateUpdate"),
StackName: jsii.String("MyStackName"),
AdminPermissions: jsii.Boolean(true),
TemplatePath: sourceOutput.AtPath(jsii.String("template.yaml")),
Role: actionRole,
})
Initializer
ts
new CloudFormationCreateUpdateStackAction(props: CloudFormationCreateUpdateStackActionProps)
python
CloudFormationCreateUpdateStackAction(props: CloudFormationCreateUpdateStackActionProps)
java
new CloudFormationCreateUpdateStackAction(CloudFormationCreateUpdateStackActionProps props)
csharp
new CloudFormationCreateUpdateStackAction(CloudFormationCreateUpdateStackActionProps props)
go
NewCloudFormationCreateUpdateStackAction(Props CloudFormationCreateUpdateStackActionProps)
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
addToDeploymentRolePolicy(statement: PolicyStatement): booleandef add_to_deployment_role_policy(self, statement: PolicyStatement) -> boolpublic Boolean addToDeploymentRolePolicy(PolicyStatement statement)public bool AddToDeploymentRolePolicy(PolicyStatement statement)func AddToDeploymentRolePolicy(Statement PolicyStatement) *bool#Add statement to the service role assumed by CloudFormation while executing this action.
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.