From d989475c0e715caa1dfaa5749a58fd6ba1fad404 Mon Sep 17 00:00:00 2001 From: 1101-1 <70093559+1101-1@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:39:55 +0500 Subject: [PATCH] [aws][fix] Handle AWS server errors properly (#2236) --- .../aws/fix_plugin_aws/resource/bedrock.py | 19 ++++++++++--------- .../aws/fix_plugin_aws/resource/dynamodb.py | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/aws/fix_plugin_aws/resource/bedrock.py b/plugins/aws/fix_plugin_aws/resource/bedrock.py index 621edbae3c..6fcddb36d5 100644 --- a/plugins/aws/fix_plugin_aws/resource/bedrock.py +++ b/plugins/aws/fix_plugin_aws/resource/bedrock.py @@ -207,7 +207,7 @@ def add_tags(job: AwsResource) -> None: service_name, "list-tags-for-resource", "tags", - expected_errors=["ResourceNotFoundException"], + expected_errors=["ResourceNotFoundException", "AccessDenied"], resourceARN=job.arn, ) if tags: @@ -490,7 +490,7 @@ def add_tags(job: AwsResource) -> None: service_name, "list-tags-for-resource", "tags", - expected_errors=["ResourceNotFoundException"], + expected_errors=["ResourceNotFoundException", "AccessDenied"], resourceARN=job.arn, ) if tags: @@ -623,7 +623,7 @@ def add_tags(job: AwsResource) -> None: service_name, "list-tags-for-resource", "tags", - expected_errors=["ResourceNotFoundException"], + expected_errors=["ResourceNotFoundException", "AccessDenied"], resourceARN=job.arn, ) if tags: @@ -767,7 +767,8 @@ class AwsBedrockEvaluationJob(BedrockTaggable, BaseAIJob, AwsResource): "bedrock", "list-evaluation-jobs", "jobSummaries", - expected_errors=["AccessDeniedException"], + # `InternalServerException` is ignored because some AWS regions may not support retrieving evaluation jobs + expected_errors=["AccessDeniedException", "InternalServerException"], ) mapping: ClassVar[Dict[str, Bender]] = { "id": S("jobArn"), @@ -823,7 +824,7 @@ def add_tags(job: AwsResource) -> None: service_name, "list-tags-for-resource", "tags", - expected_errors=["ResourceNotFoundException"], + expected_errors=["ResourceNotFoundException", "AccessDenied"], resourceARN=job.arn, ) if tags: @@ -1022,7 +1023,7 @@ def add_tags(agent: AwsResource) -> None: "bedrock-agent", "list-tags-for-resource", "tags", - expected_errors=["ResourceNotFoundException"], + expected_errors=["ResourceNotFoundException", "AccessDenied"], resourceArn=agent.arn, ) if tags: @@ -1419,7 +1420,7 @@ def add_tags(knowledge_base: AwsResource) -> None: "bedrock-agent", "list-tags-for-resource", "tags", - expected_errors=["ResourceNotFoundException"], + expected_errors=["ResourceNotFoundException", "AccessDenied"], resourceArn=knowledge_base.arn, ) if tags: @@ -1586,7 +1587,7 @@ def add_tags(prompt: AwsResource) -> None: "bedrock-agent", "list-tags-for-resource", "tags", - expected_errors=["ResourceNotFoundException"], + expected_errors=["ResourceNotFoundException", "AccessDenied"], resourceArn=prompt.arn, ) if tags: @@ -1914,7 +1915,7 @@ def add_tags(flow: AwsResource) -> None: "bedrock-agent", "list-tags-for-resource", "tags", - expected_errors=["ResourceNotFoundException"], + expected_errors=["ResourceNotFoundException", "AccessDenied"], resourceArn=flow.arn, ) if tags: diff --git a/plugins/aws/fix_plugin_aws/resource/dynamodb.py b/plugins/aws/fix_plugin_aws/resource/dynamodb.py index c7bbfbf4fb..a06a5355b2 100644 --- a/plugins/aws/fix_plugin_aws/resource/dynamodb.py +++ b/plugins/aws/fix_plugin_aws/resource/dynamodb.py @@ -443,6 +443,7 @@ def add_dynamodb_policy(table: AwsDynamoDbTable) -> None: "get-resource-policy", "Policy", ResourceArn=table.arn, + expected_errors=["PolicyNotFoundException"], ): table.dynamodb_policy = sort_json(json_loads(raw_policy), sort_list=True) # type: ignore