简体   繁体   English

在 NodeJS ExpressJS 应用程序中本地使用共享的 AWS 配置/凭证文件

[英]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.

相关问题 在 NodeJS 中使用“无服务器调用本地”命令时,AWS.config.credentials 返回 null - AWS.config.credentials returns null when using `serverless invoke local` command in NodeJS AWS - nodejs SDK - CognitoIdentityServiceProvider.initiateAuth - CredentialsError:配置中缺少凭据 - AWS - nodejs SDK - CognitoIdentityServiceProvider.initiateAuth - CredentialsError: Missing credentials in config CredentialsError:Node.js AWS-SDK中的配置中缺少凭据 - CredentialsError: Missing credentials in config in nodejs aws-sdk 在NodeJS应用程序中跨多个不同文件使用ExpressJS中间件的最佳实践 - Best practices for using ExpressJS middleware across a number of different files in NodeJS app aws:使用 systemd 时配置中缺少凭据 - aws: missing credentials in config when using systemd 无法在本地使用 NodeJS 连接到 AWS DocumentDB - Cannot connect to AWS DocumentDB using NodeJS locally Nodejs / Expressjs app结构 - Nodejs/Expressjs app structure 使用ExpressJS部署Node.js应用 - Deploying a nodejs app with ExpressJS 从本地反应应用程序进行调用时出现 AWS 凭据错误“配置中缺少凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1” - AWS creds error when making calls from local react app “Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1” AWS Dynamodb 配置中缺少凭证,如果使用 AWS_CONFIG_FILE,则设置 AWS_SDK_LOAD_CONFIG=1 - AWS Dynamodb Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM