From 6c87b1d9b60743eeae2b141497a7e8724cfe5a84 Mon Sep 17 00:00:00 2001 From: Kevin BEAUGRAND Date: Sun, 25 Jun 2023 19:57:38 +0200 Subject: [PATCH] Fix Delete AWS deployment issue --- .../Services/AWS/AwsConfigService.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs b/src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs index b92a36919..1cda4046b 100644 --- a/src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs +++ b/src/IoTHub.Portal.Infrastructure/Services/AWS/AwsConfigService.cs @@ -219,11 +219,20 @@ public Task GetConfigItem(string id) public async Task DeleteConfiguration(string modelId) { - var modules = await GetConfigModuleList(modelId); - - //Deprecate Deployment Thing type + // Deprecate Deployment Thing type await DeprecateDeploymentThingType(modelId); + IEnumerable modules = Array.Empty(); + + try + { + modules = await GetConfigModuleList(modelId); + } + catch (InternalServerErrorException e) + { + this.logger.LogError($"Failed to get model modules when deleting. Some resources might persist in AWS for model {modelId}."); + } + foreach (var module in modules.Where(c => string.IsNullOrEmpty(c.Id))) { try @@ -261,9 +270,7 @@ public async Task DeleteConfiguration(string modelId) catch (AmazonGreengrassV2Exception e) { throw new InternalServerErrorException("The deletion of the deployment failed due to an error in the Amazon IoT API.", e); - } - } private async Task DeprecateDeploymentThingType(string modelId) @@ -387,7 +394,6 @@ public async Task> GetConfigModuleList(string modelId) catch (Amazon.GreengrassV2.Model.ResourceNotFoundException) { throw new InternalServerErrorException("Unable to find the deployment due to an error in the Amazon IoT API. "); - } }