Skip to content

Commit ec0aca7

Browse files
authored
Fix integ tests to make sure IAM role is cleaned up after test run (#2275)
1 parent cca0f6e commit ec0aca7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Libraries/test/Amazon.Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.IntegrationTests/BaseCustomRuntimeTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ protected async Task CleanUpTestResources(AmazonS3Client s3Client, AmazonLambdaC
8181
{
8282
try
8383
{
84+
var listAttachedPoliciesRequest = new ListAttachedRolePoliciesRequest
85+
{
86+
RoleName = ExecutionRoleName
87+
};
88+
var attachedPolicies = await iamClient.ListAttachedRolePoliciesAsync(listAttachedPoliciesRequest);
89+
90+
foreach (var policy in attachedPolicies.AttachedPolicies)
91+
{
92+
await iamClient.DetachRolePolicyAsync(new DetachRolePolicyRequest
93+
{
94+
RoleName = ExecutionRoleName,
95+
PolicyArn = policy.PolicyArn
96+
});
97+
}
98+
8499
var deleteRoleRequest = new DeleteRoleRequest
85100
{
86101
RoleName = ExecutionRoleName

0 commit comments

Comments
 (0)