# CloudFormationCreateReplaceChangeSetAction

CodePipeline action to prepare a change set.

Creates the change set if it doesn't exist based on the stack name and template that you submit.
If the change set exists, AWS CloudFormation deletes it, and then creates a new one.

Extends: Action › Action › CloudFormationCreateReplaceChangeSetAction
Implements: IAction

- Source: [`aws-codepipeline-actions/lib/cloudformation/pipeline-actions.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-codepipeline-actions/lib/cloudformation/pipeline-actions.ts#L379)

## Example

```ts
// Source stage: read from repository
const repo = new codecommit.Repository(stack, 'TemplateRepo', {
  repositoryName: 'template-repo',
});
const sourceOutput = new codepipeline.Artifact('SourceArtifact');
const source = new cpactions.CodeCommitSourceAction({
  actionName: 'Source',
  repository: repo,
  output: sourceOutput,
  trigger: cpactions.CodeCommitTrigger.POLL,
});
const sourceStage = {
  stageName: 'Source',
  actions: [source],
};

// Deployment stage: create and deploy changeset with manual approval
const stackName = 'OurStack';
const changeSetName = 'StagedChangeSet';

const prodStage = {
  stageName: 'Deploy',
  actions: [
    new cpactions.CloudFormationCreateReplaceChangeSetAction({
      actionName: 'PrepareChanges',
      stackName,
      changeSetName,
      adminPermissions: true,
      templatePath: sourceOutput.atPath('template.yaml'),
      runOrder: 1,
    }),
    new cpactions.ManualApprovalAction({
      actionName: 'ApproveChanges',
      runOrder: 2,
    }),
    new cpactions.CloudFormationExecuteChangeSetAction({
      actionName: 'ExecuteChanges',
      stackName,
      changeSetName,
      runOrder: 3,
    }),
  ],
};

new codepipeline.Pipeline(stack, 'Pipeline', {
  crossAccountKeys: true,
  stages: [
    sourceStage,
    prodStage,
  ],
});
```

## Initializer

```ts
new CloudFormationCreateReplaceChangeSetAction(props: CloudFormationCreateReplaceChangeSetActionProps)
```

## Properties

- `actionProperties`: [ActionProperties](/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.ActionProperties.html) — The simple properties of the Action, like its Owner, name, etc.

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

- `deploymentRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html)

## Methods

- `addToDeploymentRolePolicy(statement: PolicyStatement): boolean` — Add statement to the service role assumed by CloudFormation while executing this action.

- `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): Rule` — Creates an Event that will be triggered whenever the state of this Action changes.
