[英]Using shared AWS config/credentials files locally in NodeJS ExpressJS app
Im asking this question because I spent a long time trawling google trying to find an answer to it and finally stumbled upon a single line in an AWS doc that pointed me to the correct answer, but it is not obvious, so hope this helps someone save some time.我问这个问题是因为我花了很长时间在谷歌上寻找答案,最后偶然发现了 AWS 文档中的一行,指出了正确的答案,但这并不明显,所以希望这可以帮助某人节省一段时间。
Problem: I am trying to call AWS services via the AWS SDK in my NodeJS Express app, but the SDK is not loading the profile and key details I have in my ~/.aws/credentials and ~/.aws/config files.问题:我试图通过我的 NodeJS Express 应用程序中的 AWS SDK 调用 AWS 服务,但是 SDK 没有加载我在 ~/.aws/credentials 和 ~/.aws/config 文件中的配置文件和关键详细信息。 When I try and log the credentials object it is empty.
当我尝试记录凭据 object 时,它是空的。 I am trying to use a profile which I have set using the AWS_PROFILE environment variable, set in a.env file.
我正在尝试使用我使用 AWS_PROFILE 环境变量设置的配置文件,该变量设置在 a.env 文件中。 Looking at the AWS docs the SDK should look in these files under ~/.aws, but it doesnt seem to be doing this.
查看 AWS 文档 SDK 应该在 ~/.aws 下的这些文件中查看,但它似乎没有这样做。
So the answer lies in a single line in one of the AWS docs: http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-started-nodejs.html因此,答案在于 AWS 文档之一中的一行: http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-started-nodejs.html
Similarly, if you have set your region correctly in your config file, you can display that value by setting the AWS_SDK_LOAD_CONFIG environment variable to a truthy value
同样,如果您在配置文件中正确设置了区域,则可以通过将 AWS_SDK_LOAD_CONFIG 环境变量设置为真值来显示该值
Adding AWS_SDK_LOAD_CONFIG=true
to my.env file caused the SDK to start using the credentials stored in the ~/.aws/config and ~/.aws/credentials files.将
AWS_SDK_LOAD_CONFIG=true
添加到 my.env 文件会导致 SDK 开始使用存储在 ~/.aws/config 和 ~/.aws/credentials 文件中的凭证。
I dont know why the docs dont make it more explicit that you need to do this (that page suggests you only need to set this to get the region to pass), everything I read suggested that these files would be checked by the SDK regardless.我不知道为什么文档没有更明确地说明您需要执行此操作(该页面建议您只需要设置它以使该区域通过),我读到的所有内容都表明这些文件将由 SDK 无论如何检查。
Hopefully this helps save someone else a lot of frustration and Googling!希望这有助于为其他人节省很多挫败感和谷歌搜索!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.