如何从〜/ .aws / config加载配置

时间:2017-06-08 10:42:46

标签: amazon-web-services aws-sdk aws-sdk-nodejs

change logLoad config from ~/.aws/config if AWS_SDK_LOAD_CONFIG is set. 无法找到有关如何加载配置的任何示例或文档。任何帮助!

3 个答案:

答案 0 :(得分:8)

aws-sdk如何加载配置

有一点神奇之处

设置env变量

C:\Users\Kevin>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "D:\Python3.6\lib\site-packages\numpy\core\__init__.py", line 16, in 
<module>
from . import multiarray
ImportError: DLL load failed: The specified procedure could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python3.6\lib\site-packages\numpy\__init__.py", line 142, in 
<module>
    from . import add_newdocs
  File "D:\Python3.6\lib\site-packages\numpy\add_newdocs.py", line 13, in 
<module>
    from numpy.lib import add_newdoc
  File "D:\Python3.6\lib\site-packages\numpy\lib\__init__.py", line 8, in 
<module>
    from .type_check import *
  File "D:\Python3.6\lib\site-packages\numpy\lib\type_check.py", line 11, in 
<module>
    import numpy.core.numeric as _nx
  File "D:\Python3.6\lib\site-packages\numpy\core\__init__.py", line 26, in 
<module>
    raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: DLL load failed: The specified procedure could not be 
found.

或在加载aws-sdk set之前

export AWS_SDK_LOAD_CONFIG="true"

然后加载aws模块;

process.env.AWS_SDK_LOAD_CONFIG = true; 

您可以通过

直接访问该地区
var AWS = require('aws-sdk');

答案 1 :(得分:0)

有这方面的文件:

我建议安装awscli工具进行设置,然后在终端中运行aws configure。默认情况下,您在本地主机上运行的任何内容都将采用config文件中列出的凭据,除非指定采用其他配置文件。

来自第一个链接的示例:

AWS.config.credentials = new AWS.SharedIniFileCredentials( { profile: 'work-account' } );

如果您使用CLI运行脚本:

AWS_PROFILE=work-account node script.js

如果您只使用CLI工具而不使用JavaScript:

aws s3 ls --profile work-account

<强>更新

configcredentials同时 制作并引用。当您运行aws configure时,它会生成两个文件。包含AccessKey和SecretKey的credentials文件 - 以及包含响应类型和区域的config文件。没有必要明确定义或引用config文件。

答案 2 :(得分:0)

The answer of sreenivas是正确的。这似乎也是不编写自定义函数即可做到这一点的唯一方法。

我已经在source code中找到了它,并且它加载~/.aws/config的方式与此伪代码类似:

if process.env.AWS_SDK_LOAD_CONFIG:
  return load('~/.aws/credentials').overwrite('~/.aws/config')
else:
  return load('~/.aws/credentials')

这也意味着您可以在require('aws-sdk')之后设置环境变量,只要您在new SharedIniFileCredentials({..})credentials.refresh()之前设置即可。请注意,credentials.get()在会话令牌过期之前将无法工作。