Skip to content

Commit

Permalink
Validate security credentials obtained from Instance Metadata Service
Browse files Browse the repository at this point in the history
Getting security credentials from Instance Metadata Service fails
when an EC2 instance does not have permissions to assume a role.
When that happens, we get a very unhelpful error message
"Value cannot be null. (Parameter 'awsAccessKeyId')"
Do response validation so that we get better exception message.

See also aws/aws-cli#2060
  • Loading branch information
Olli Pottonen committed Feb 28, 2024
1 parent 22c8103 commit 143f296
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ protected static T GetObjectFromResponse<T, TC>(Uri uri, IWebProxy proxy, Dictio
Amazon.Util.Internal.JsonSerializerContext,
#endif
new()
where T : SecurityBase
{
string json = GetContents(uri, proxy, headers);
return JsonSerializerHelper.Deserialize<T>(json, new TC());
var result = JsonSerializerHelper.Deserialize<T>(json, new TC());
ValidateResponse(result);
return result;
}

protected static void ValidateResponse(SecurityBase response)
Expand Down

0 comments on commit 143f296

Please sign in to comment.