Skip to content

Commit d4f2828

Browse files
committed
fix: detach managed policies in EC2 demo teardown
Signed-off-by: Kyle Hounslow <kylhouns@amazon.com>
1 parent 1897382 commit d4f2828

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

aws/cli-installer/src/ec2-demo.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ export async function teardownDemoInstance(cfg) {
313313
await iam.send(new RemoveRoleFromInstanceProfileCommand({ InstanceProfileName: roleName, RoleName: roleName }));
314314
await iam.send(new DeleteInstanceProfileCommand({ InstanceProfileName: roleName }));
315315
await iam.send(new DeleteRolePolicyCommand({ RoleName: roleName, PolicyName: 'osis-ingest' }));
316+
// Detach any managed policies
317+
const { ListAttachedRolePoliciesCommand, DetachRolePolicyCommand } = await import('@aws-sdk/client-iam');
318+
const { AttachedPolicies } = await iam.send(new ListAttachedRolePoliciesCommand({ RoleName: roleName }));
319+
for (const p of AttachedPolicies || []) {
320+
await iam.send(new DetachRolePolicyCommand({ RoleName: roleName, PolicyArn: p.PolicyArn }));
321+
}
316322
await iam.send(new DeleteRoleCommand({ RoleName: roleName }));
317323
printSuccess('Instance profile and role deleted');
318324
} catch (e) {

0 commit comments

Comments
 (0)