我尝试将 Amazon AWS DynamoDB 与 python 结合使用。首先,我浏览了亚马逊的本指南: http://docs.aws.amazon.com/de_de/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.01.html
然后我运行 Amazons 代码时出现错误: botocore.exceptions.NoCredentialsError:无法找到凭据
我拥有的凭据位于“~/.aws/credentials”,它们看起来像这样:
[profile-name]
aws_access_key_id=XXXX
aws_secret_access_key=YYYYYYY
我还尝试设置一个配置文件,其中包括
[profile profile-name]
aws_access_key_id=XXXX
aws_secret_access_key=YYYYYYY
在我的 IntelliJ 应用程序中,使用此凭据一切正常。刚刚使用 PyCharm。
我也设置了这个记录器,但是这些信息对我帮助不大:
boto3.set_stream_logger('botocore', level='DEBUG')
调试信息是:
2016-05-04 11:58:18,162 botocore.credentials [DEBUG] Skipping environment variable credential check because profile name was explicitly set.
2016-05-04 11:58:18,162 botocore.credentials [DEBUG] Looking for credentials via: env
2016-05-04 11:58:18,162 botocore.credentials [DEBUG] Looking for credentials via: assume-role
2016-05-04 11:58:18,162 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file
2016-05-04 11:58:18,163 botocore.credentials [DEBUG] Looking for credentials via: config-file
2016-05-04 11:58:18,163 botocore.credentials [DEBUG] Looking for credentials via: ec2-credentials-file
2016-05-04 11:58:18,163 botocore.credentials [DEBUG] Looking for credentials via: boto-config
2016-05-04 11:58:18,163 botocore.credentials [DEBUG] Looking for credentials via: aim-role
最后:我的代码(与教程相同,只是带有调试器):
from __future__ import print_function # Python 2/3 compatibility
import boto3
boto3.set_stream_logger('botocore', level='DEBUG')
dynamodb = boto3.resource('dynamodb', region_name='eu-central-1', endpoint_url="http://localhost:8000")
table = dynamodb.create_table(
TableName='Movies',
KeySchema=[
{
'AttributeName': 'year',
'KeyType': 'HASH' #Partition key
},
{
'AttributeName': 'title',
'KeyType': 'RANGE' #Sort key
}
],
AttributeDefinitions=[
{
'AttributeName': 'year',
'AttributeType': 'N'
},
{
'AttributeName': 'title',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
}
)
print("Table status:", table.table_status)
编辑:如果我更改凭据中的 [profile-name] 部分 du [default],我会收到连接错误。
最佳答案
尝试从您的代码中删除 endpoint_url。不知道为什么,但对我有用:)
关于python - botocore.exceptions.NoCredentialsError : Unable to locate credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37024581/