Advanced stack transformation and refactoring operations for reorganizing CloudFormation infrastructure. Stack refactoring allows you to move resources between stacks, split large stacks into smaller ones, or merge multiple stacks while maintaining resource continuity.
Creates a refactor operation across multiple stacks, defining how resources should be moved between them.
/**
* Creates a refactor across multiple stacks, with the list of stacks
* and resources that are affected
*/
class CreateStackRefactorCommand {
constructor(input: CreateStackRefactorCommandInput);
}
interface CreateStackRefactorCommandInput {
/** Description of the refactor operation */
Description?: string;
/** Whether to enable creation of new stacks during refactor */
EnableStackCreation?: boolean;
/** Resource mappings defining how resources move between stacks */
ResourceMappings?: ResourceMapping[];
/** Stack definitions for target stacks */
StackDefinitions: StackDefinition[];
}
interface CreateStackRefactorCommandOutput {
/** Unique identifier for the refactor operation */
StackRefactorId: string;
}
interface ResourceMapping {
/** Source location of the resource */
Source: ResourceLocation;
/** Destination location for the resource */
Destination: ResourceLocation;
}
interface ResourceLocation {
/** Name of the stack containing the resource */
StackName: string;
/** Logical resource ID within the stack */
LogicalResourceId: string;
}
interface StackDefinition {
/** Name of the target stack */
StackName?: string;
/** CloudFormation template as JSON/YAML string */
TemplateBody?: string;
/** S3 URL containing the CloudFormation template */
TemplateURL?: string;
}Usage Example:
import { CloudFormationClient, CreateStackRefactorCommand } from "@aws-sdk/client-cloudformation";
const client = new CloudFormationClient({ region: "us-east-1" });
const command = new CreateStackRefactorCommand({
Description: "Split monolithic stack into microservice stacks",
EnableStackCreation: true,
ResourceMappings: [
{
Source: {
StackName: "monolithic-stack",
LogicalResourceId: "UserServiceEC2Instance"
},
Destination: {
StackName: "user-service-stack",
LogicalResourceId: "UserServiceEC2Instance"
}
},
{
Source: {
StackName: "monolithic-stack",
LogicalResourceId: "OrderServiceDatabase"
},
Destination: {
StackName: "order-service-stack",
LogicalResourceId: "OrderServiceDatabase"
}
}
],
StackDefinitions: [
{
StackName: "user-service-stack",
TemplateBody: JSON.stringify({
AWSTemplateFormatVersion: "2010-09-09",
Resources: {
UserServiceEC2Instance: {
Type: "AWS::EC2::Instance",
Properties: {
ImageId: "ami-12345678",
InstanceType: "t2.micro"
}
}
}
})
},
{
StackName: "order-service-stack",
TemplateBody: JSON.stringify({
AWSTemplateFormatVersion: "2010-09-09",
Resources: {
OrderServiceDatabase: {
Type: "AWS::RDS::DBInstance",
Properties: {
DBInstanceClass: "db.t2.micro",
Engine: "mysql"
}
}
}
})
}
]
});
const response = await client.send(command);
console.log("Refactor ID:", response.StackRefactorId);Executes a previously created stack refactor operation.
/**
* Executes a stack refactor operation that was previously created
*/
class ExecuteStackRefactorCommand {
constructor(input: ExecuteStackRefactorCommandInput);
}
interface ExecuteStackRefactorCommandInput {
/** ID of the refactor operation to execute */
StackRefactorId: string;
/** Optional client request token for idempotency */
ClientRequestToken?: string;
}
interface ExecuteStackRefactorCommandOutput {
/** ID of the executed refactor operation */
StackRefactorId?: string;
/** Execution status */
Status?: StackRefactorStatus;
}
type StackRefactorStatus =
| "CreatePending"
| "CreateInProgress"
| "CreateComplete"
| "CreateFailed"
| "ExecutePending"
| "ExecuteInProgress"
| "ExecuteComplete"
| "ExecuteFailed"
| "DeletePending"
| "DeleteInProgress"
| "DeleteComplete"
| "DeleteFailed";Retrieves detailed information about a stack refactor operation.
/**
* Describes a stack refactor operation including its current status and details
*/
class DescribeStackRefactorCommand {
constructor(input: DescribeStackRefactorCommandInput);
}
interface DescribeStackRefactorCommandInput {
/** ID of the refactor operation to describe */
StackRefactorId: string;
}
interface DescribeStackRefactorCommandOutput {
/** Refactor operation ID */
StackRefactorId?: string;
/** Description of the refactor operation */
Description?: string;
/** Current status of the refactor */
Status?: StackRefactorStatus;
/** Reason for the current status */
StatusReason?: string;
/** Timestamp when refactor was created */
CreationTime?: Date;
/** Timestamp of last status update */
LastUpdatedTime?: Date;
/** Resource mappings for the refactor */
ResourceMappings?: ResourceMapping[];
/** Stack definitions */
StackDefinitions?: StackDefinition[];
/** Whether stack creation is enabled */
EnableStackCreation?: boolean;
/** Progress information */
Progress?: RefactorProgress;
}
interface RefactorProgress {
/** Number of resources successfully processed */
ResourcesSucceeded?: number;
/** Number of resources that failed processing */
ResourcesFailed?: number;
/** Number of resources currently being processed */
ResourcesProcessing?: number;
/** Number of resources pending processing */
ResourcesPending?: number;
/** Total number of resources in the refactor */
TotalResources?: number;
}Cancels a stack refactor operation that is in progress.
/**
* Cancels a stack refactor operation
*/
class CancelStackRefactorCommand {
constructor(input: CancelStackRefactorCommandInput);
}
interface CancelStackRefactorCommandInput {
/** ID of the refactor operation to cancel */
StackRefactorId: string;
}
interface CancelStackRefactorCommandOutput {
/** ID of the canceled refactor operation */
StackRefactorId?: string;
/** Updated status after cancellation */
Status?: StackRefactorStatus;
}Deletes a stack refactor definition and its associated metadata.
/**
* Deletes a stack refactor operation
*/
class DeleteStackRefactorCommand {
constructor(input: DeleteStackRefactorCommandInput);
}
interface DeleteStackRefactorCommandInput {
/** ID of the refactor operation to delete */
StackRefactorId: string;
}
interface DeleteStackRefactorCommandOutput {}Lists all stack refactor operations in the current region.
/**
* Returns a list of stack refactor operations
*/
class ListStackRefactorsCommand {
constructor(input: ListStackRefactorsCommandInput);
}
interface ListStackRefactorsCommandInput {
/** Filter by refactor status */
Status?: StackRefactorStatus;
/** Pagination token for subsequent requests */
NextToken?: string;
/** Maximum number of results to return */
MaxResults?: number;
}
interface ListStackRefactorsCommandOutput {
/** List of refactor operation summaries */
Summaries?: StackRefactorSummary[];
/** Pagination token for next page */
NextToken?: string;
}
interface StackRefactorSummary {
/** Refactor operation ID */
StackRefactorId?: string;
/** Description of the refactor */
Description?: string;
/** Current status */
Status?: StackRefactorStatus;
/** Status reason */
StatusReason?: string;
/** Creation timestamp */
CreationTime?: Date;
/** Last updated timestamp */
LastUpdatedTime?: Date;
/** Number of resource mappings */
NumberOfResourceMappings?: number;
/** Number of affected stacks */
NumberOfStacks?: number;
}Usage Example:
import {
CloudFormationClient,
ExecuteStackRefactorCommand,
DescribeStackRefactorCommand
} from "@aws-sdk/client-cloudformation";
const client = new CloudFormationClient({ region: "us-east-1" });
// Execute the refactor
const executeCommand = new ExecuteStackRefactorCommand({
StackRefactorId: "12345678-1234-1234-1234-123456789012"
});
const executeResponse = await client.send(executeCommand);
console.log("Execution started:", executeResponse.Status);
// Monitor progress
const describeCommand = new DescribeStackRefactorCommand({
StackRefactorId: "12345678-1234-1234-1234-123456789012"
});
const statusResponse = await client.send(describeCommand);
console.log("Progress:", statusResponse.Progress);
console.log("Status:", statusResponse.Status);