简体   繁体   中英

How to solve “AmazonTextractException: The security token included in the request is invalid” error?

I have a small piece of .NET Core code written to interact with the Amazon Textract API. The code itself is small and is working fine on one of my development machines. The code doesn't do anything with credentials, everything is configured through the AWS CLI. When I run the same code on other development machine I receive the following error:

AmazonTextractException: The security token included in the request is invalid

So far here is what I've tried:

  • Create a new AWS key/secret pair, remove any previously existing environment variables (AWS_SECRET_KEY, etc.), remove ~\.aws\config and ~\.aws\credentials . Re-run aws configure with the new credentials. Same exception.

  • Re-use the same AWS key/secret pair that is working on one dev machine, after performing the above sanitation steps again.

  • Ensured that MFA is turned off on the AWS account

The ~\.aws\config and ~\.aws\credentials are identical between both machines.

return await this.textract.AnalyzeDocumentAsync(request);

On one machine, my code works great and it extracts text from my documents using OCR. On another machine it results in this error:

Amazon.Textract.AmazonTextractException: The security token included in the request is invalid

I would expect the code to work in the same way on each system, given the configurations.

What else on this machine might be causing things to behave differently? Are there any other secret AWS settings I am unaware of, or any additional steps that might be required on certain systems?

We figured out what the problem was - in this case it was related to Visual Studio version issues. One dev machine (the working one) had Visual Studio 2019 installed, while the other (not working) had Visual Studio 2017. Both of the machines had the AWS Toolkits installed, but only the 2019 version seemed to properly import the user account profile from the AWS CLI configuration of the machine. So, on the 2019 machine, we had a valid profile inside of the VS AWS Toolkit - on the 2017 machine, we didn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM