简体   繁体   English

如何解决“AmazonTextractException:请求中包含的安全令牌无效”错误?

[英]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.我有一小段 .NET 核心代码,用于与 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.该代码不使用凭证做任何事情,一切都是通过 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 AmazonTextractException:请求中包含的安全令牌无效

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 .创建一个新的 AWS 密钥/密钥对,删除任何以前存在的环境变量(AWS_SECRET_KEY 等),删除~\.aws\config~\.aws\credentials Re-run aws configure with the new credentials.使用新凭证重新运行 aws configure。 Same exception.同样的例外。

  • Re-use the same AWS key/secret pair that is working on one dev machine, after performing the above sanitation steps again.再次执行上述清理步骤后,重新使用在一台开发机器上工作的相同 AWS 密钥/密钥对。

  • Ensured that MFA is turned off on the AWS account确保在 AWS 账户上关闭了 MFA

The ~\.aws\config and ~\.aws\credentials are identical between both machines. ~\.aws\config~\.aws\credentials在两台机器之间是相同的。

return await this.textract.AnalyzeDocumentAsync(request);

On one machine, my code works great and it extracts text from my documents using OCR.在一台机器上,我的代码运行良好,它使用 OCR 从我的文档中提取文本。 On another machine it results in this error:在另一台机器上,它会导致此错误:

Amazon.Textract.AmazonTextractException: The security token included in the request is invalid Amazon.Textract.AmazonTextractException:请求中包含的安全令牌无效

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?是否有任何其他我不知道的秘密 AWS 设置,或者在某些系统上可能需要任何其他步骤?

We figured out what the problem was - in this case it was related to Visual Studio version issues.我们找出了问题所在——在这种情况下,它与 Visual Studio 版本问题有关。 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.一台开发机器(正常工作的机器)安装了 Visual Studio 2019,而另一台(不工作)安装了 Visual Studio 2017。两台机器都安装了 AWS 工具包,但似乎只有 2019 版本正确地从机器的 AWS CLI 配置。 So, on the 2019 machine, we had a valid profile inside of the VS AWS Toolkit - on the 2017 machine, we didn't.因此,在 2019 年的机器上,我们在 VS AWS Toolkit 中有一个有效的配置文件——在 2017 年的机器上,我们没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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