简体   繁体   English

如何更改.aws凭据路径? nodejs(aws-sdk)

[英]How can I change .aws credentials path ? nodejs (aws-sdk)

To connect aws-sdk (nodejs) to aws I have to create credentials file then add accessKeyId and secretAccessKey at 要将aws-sdk(nodejs)连接到aws,我必须创建凭据文件,然后在以下位置添加accessKeyId和secretAccessKey

C:\\Users{username}.aws\\credentials C:\\用户{用户名} .aws \\凭据

But I would like to change path .aws to somewhere else or create const variables of accessKeyId and secretAccessKey in js. 但是我想将路径.aws更改为其他位置,或在js中创建accessKeyId和secretAccessKey的const变量。

Can someone show me how can I change path ? 有人可以告诉我如何改变道路吗? or add accessKeyId and secretAccessKey somewhere inside js. 或在js内的某处添加accessKeyId和secretAccessKey。

thank you. 谢谢。

You can create a JSON file containing your credentials like this 您可以创建一个包含您的凭证的JSON文件,如下所示

{
    "accessKeyId": " Your Access Key Id", 
    "secretAccessKey": "Your Secret Access Key",
    "region": "Your Region"
}

and save it. 并保存。 then give path of this JSON file using 然后使用以下命令提供此JSON文件的路径

var AWS = require('aws-sdk');
AWS.config.loadFromPath('File_Path/file_name.json');

Another solution is to user AWS Environment variables: 另一个解决方案是使用用户AWS环境变量:

https://docs.aws.amazon.com/cli/latest/userguide/cli-environment.html https://docs.aws.amazon.com/cli/latest/userguide/cli-environment.html

Using this way you warantee AWS Runtime environment compatibility. 使用这种方式可以保证AWS Runtime环境的兼容性。

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

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