Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fuzzy-mails-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sst": patch
---

Passing cdk role to stack remove
2 changes: 1 addition & 1 deletion packages/sst/src/stacks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async function addInUseExports(
}
}

async function createCdkDeployments() {
export async function createCdkDeployments() {
const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib");
const cdkToolkitPath = fileURLToPath(cdkToolkitUrl);
const { Deployments } = await import(
Expand Down
15 changes: 13 additions & 2 deletions packages/sst/src/stacks/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import { useBus } from "../bus.js";
import { useAWSClient, useAWSProvider } from "../credentials.js";
import { Logger } from "../logger.js";
import { StackDeploymentResult, monitor, isFailed } from "./monitor.js";
import { createCdkDeployments } from "./deploy.js";
import { ConfigOptions, useProject } from "../project.js";

export async function removeMany(stacks: CloudFormationStackArtifact[]) {
await useAWSProvider();
const bus = useBus();
const { cdk } = useProject().config;
const deployment = await createCdkDeployments();
const complete = new Set<string>();
const todo = new Set(stacks.map((s) => s.id));

Expand All @@ -35,7 +39,7 @@ export async function removeMany(stacks: CloudFormationStackArtifact[]) {
continue;
}

remove(stack).then((result) => {
remove(deployment, stack, cdk).then((result) => {
results[stack.id] = result;
complete.add(stack.id);

Expand Down Expand Up @@ -71,14 +75,21 @@ export async function removeMany(stacks: CloudFormationStackArtifact[]) {
}

export async function remove(
stack: CloudFormationStackArtifact
deployment: Awaited<ReturnType<typeof createCdkDeployments>>,
stack: CloudFormationStackArtifact,
cdkOptions?: ConfigOptions["cdk"]
): Promise<StackDeploymentResult> {
Logger.debug("Removing stack", stack.id);
const cfn = useAWSClient(CloudFormationClient);

const env = await deployment.envs.accessStackForMutableStackOperations(stack);
const executionRoleArn = cdkOptions?.cloudFormationExecutionRole ?? await env.replacePlaceholders(stack.cloudFormationExecutionRoleArn);

try {
await cfn.send(
new DeleteStackCommand({
StackName: stack.stackName,
RoleARN: executionRoleArn,
})
);
return monitor(stack.stackName);
Expand Down