python - botocore.exceptions.NoCredentialsError : Unable to locate credentials

标签 python amazon-web-services amazon-dynamodb

我尝试将 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/

相关文章:

python - HTTP 错误 403 : Forbidden urlib2 Python 2. 7

python - Zinnia 在 MySQL 后端的 QuerySet.datetimes() 中返回了无效值

python - 如何在 Google App Engine 中为模型定义唯一属性?

amazon-web-services - Amazon RDS - 仅在需要时才在线?

javascript - 使用 Promises 从 DynamoDB 异步检索数据

amazon-dynamodb - 在 DynamoDB 中存储非唯一数组

amazon-web-services - 使用无服务器框架时如何从 AWS Lambda 访问 DynamoDB?

python - type(1) 是否等同于 type.__call__(1)?

amazon-web-services - 如何将弹性 IP 与 Fargate 容器关联?

python - 在AWS lambda函数中获取日志两次