Skip to content

Commit 97b856e

Browse files
committed
Fix intermittent IAM permission failures in delete-deployment command
1 parent 0094629 commit 97b856e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "AWS.Deploy.CLI",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Fixed intermittent IAM permission failures in delete-deployment command by ensuring CloudFormation client is created after AWS credentials are configured"
8+
]
9+
}
10+
]
11+
}

src/AWS.Deploy.CLI/Commands/DeleteDeploymentCommand.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public class DeleteDeploymentCommand : CancellableAsyncCommand<DeleteDeploymentC
2828

2929
private readonly IAWSClientFactory _awsClientFactory;
3030
private readonly IToolInteractiveService _interactiveService;
31-
private readonly IAmazonCloudFormation _cloudFormationClient;
3231
private readonly IConsoleUtilities _consoleUtilities;
3332
private readonly ILocalUserSettingsEngine _localUserSettingsEngine;
3433
private readonly IAWSUtilities _awsUtilities;
3534
private readonly IProjectParserUtility _projectParserUtility;
3635
private readonly IAWSResourceQueryer _awsResourceQueryer;
36+
private IAmazonCloudFormation? _cloudFormationClient;
3737
private const int MAX_RETRIES = 4;
3838

3939
/// <summary>
@@ -51,7 +51,6 @@ public DeleteDeploymentCommand(
5151
_awsClientFactory = awsClientFactory;
5252
_interactiveService = interactiveService;
5353
_consoleUtilities = consoleUtilities;
54-
_cloudFormationClient = _awsClientFactory.GetAWSClient<IAmazonCloudFormation>();
5554
_localUserSettingsEngine = localUserSettingsEngine;
5655
_awsUtilities = awsUtilities;
5756
_projectParserUtility = projectParserUtility;
@@ -80,6 +79,9 @@ public override async Task<int> ExecuteAsync(CommandContext context, DeleteDeplo
8079
awsOption.Region = RegionEndpoint.GetBySystemName(awsRegion);
8180
});
8281

82+
// Create CloudFormation client after credentials are configured
83+
_cloudFormationClient = _awsClientFactory.GetAWSClient<IAmazonCloudFormation>();
84+
8385
if (string.IsNullOrEmpty(settings.DeploymentName))
8486
{
8587
_interactiveService.WriteErrorLine(string.Empty);
@@ -123,7 +125,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, DeleteDeplo
123125

124126
try
125127
{
126-
await _cloudFormationClient.DeleteStackAsync(new DeleteStackRequest
128+
await _cloudFormationClient!.DeleteStackAsync(new DeleteStackRequest
127129
{
128130
StackName = settings.DeploymentName
129131
});
@@ -218,7 +220,7 @@ private async Task WaitForStackDelete(string stackName)
218220
{
219221
await Task.Delay(waitTime);
220222

221-
var response = await _cloudFormationClient.DescribeStacksAsync(new DescribeStacksRequest
223+
var response = await _cloudFormationClient!.DescribeStacksAsync(new DescribeStacksRequest
222224
{
223225
StackName = stackName
224226
});

0 commit comments

Comments
 (0)