File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments