【发布时间】:2018-04-30 08:07:30
【问题描述】:
我的同事成功地执行了以下代码,显示了表格,而没有在本地环境中设置凭据,但是当我执行它时,它在我的本地机器上显示了这样的错误。请帮忙。
请在下面找到我的代码:
控制器:
AWS.config.update({
region: 'localhost',
endpoint: new AWS.Endpoint('http://localhost:8008'),
})
var params = {
TableName: 'history',
KeySchema: [{
AttributeName: 'b_id',
KeyType: 'HASH'
},{
AttributeName: 'e_id',
KeyType: 'RANGE'
}],
AttributeDefinitions: [{
AttributeName: 'b_id',
AttributeType: 'S',
},{
AttributeName: 'e_id',
AttributeType: 'N',
}],
ProvisionedThroughput: { // required provisioned throughput for the table
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
}
response.implicitEnd = false
AWS.query('history',params, function(err, data){
if(err) console.log(err)
else response.json(data)
})
错误信息:
{ 错误:连接 EHOSTUNREACH 169.254.169.254:80 - Local () at _exceptionWithHostPort 处的 Object._errnoException (util.js:1022:11) (util.js:1044:20) 在 internalConnect (net.js:971:16) 在 net.js:1065:9 在 _combinedTickCallback (internal/process/next_tick.js:131:7) 在 process._tickDomainCallback (internal/process/next_tick.js:218:9) 消息:'配置中缺少凭据',代码:'CredentialsError', errno:'EHOSTUNREACH',系统调用:'connect',地址:'169.254.169.254', 端口:80,时间:2018-04-30T04:34:53.218Z,原始错误:{消息: “无法从任何提供商加载凭据”,代码: 'CredentialsError',errno:'EHOSTUNREACH',系统调用:'connect', 地址:'169.254.169.254',端口:80,时间:2018-04-30T04:34:53.218Z, originalError:{代码:'EHOSTUNREACH',errno:'EHOSTUNREACH',系统调用: '连接',地址:'169.254.169.254',端口:80,消息:'连接 EHOSTUNREACH 169.254.169.254:80 - 本地 ()' } } }
> which python
/usr/bin/python
> pip install --upgrade pip
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages (10.0.1)
metplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.
> pip --version
pip 10.0.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
> python --version
Python 2.7.10
【问题讨论】:
-
Error: connect EHOSTUNREACH 169.254.169.254:80是连接到 EC2 实例元数据服务失败,这是意料之中的,因为您没有在 EC2 中运行此代码。最可能的解释是您的同事确实在其本地环境中配置了凭据。 -
感谢您的输入@Michael-sqlbot,但是如何配置我的本地环境?是不是像下面萧的回答和cmets所说的那样?我未能执行最后一步,因为我找不到我的 .bash_profile,即使在我
touch之后它仍然不起作用(抱歉我缺乏 bash 知识) -
也可能只是
.profile。如果你有 sudo 访问权限,你可以sudo pip install awscli并且你不必重新定义路径。 -
是的,我想我安装了它,但它仍然无法工作,错误消息仍然存在:
awc: command not found -
也没有
.profile
标签: amazon-web-services amazon-dynamodb