AWS Assume Role via .Net SDK gives Access Denied but works with CLI #2059
-
I am trying to upload a file in S3 by AWS Assume Role. When I am trying to access it from CLI it works fine but from .Net SDK it gives me Access Denied error. Here are the steps I followed in CLI -
Now I am trying to access it from .Net core App - Here is the code snippet- Note that I am using same Access and Secret key as CLI from my local.
The method to get temp credentials is as follow - GetTemporaryCredentialsAsync
I am getting back the temp credentials but it gives me Access Denied while uploading the file. Not sure if I am missing anything here. Also noted that the token generated via SDK is shorter than that from CLI. I tried pasting these temp credentials to local profile and then tried to access the bucket and getting the Access Denied error then too. I enabled the AWS Logging and here are the additional logs. - EnvironmentVariableInternalConfiguration 1|2022-06-15T22:06:47.379Z|INFO|The environment variable AWS_ENABLE_ENDPOINT_DISCOVERY was not set with a value. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@mahesh-cognologix Good morning. Your .NET logic to use temporary credentials with assumed role appears to be incorrect. The call to AssumeRole service API operation itself returns the temporary session credentials. But in your code you are executing the await stsClient.AssumeRoleAsync(
new AssumeRoleRequest()
{
RoleArn = roleARN,
RoleSessionName = "mySession"
}); without consuming the returned credentials. Then you are just constructing new session credentials with no role attached and hence you get Access Denied error while executing .NET code. If your compare your .NET logic with AWS CLI calls, both are different. For guidance on using |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
@mahesh-cognologix Good morning. Your .NET logic to use temporary credentials with assumed role appears to be incorrect. The call to AssumeRole service API operation itself returns the temporary session credentials. But in your code you are executing the
AssumeRoleAsync
:without consuming the returned credentials. Then you are just constructing new session credentials with no role attached and hence you get Access Denied error while executing .NET code. If your compare you…