【问题标题】:Boto3 getting Error "botocore.exceptions.NoCredentialsError: Unable to locate credentials"Boto3 出现错误“botocore.exceptions.NoCredentialsError:无法找到凭据”
【发布时间】:2022-07-20 07:11:03
【问题描述】:

import boto3
import os

os.environ['AWS_DEFAULT_REGION'] = "us-east-1"


def get_secret_value():
    
    """Gets the value of a secret.

    Version (if defined) is used to retrieve a particular version of
    the secret.

    """

    secrets_client = boto3.clie("secretsmanager", region_name = "us-east-1")
    kwargs = {'SecretId': "DBName"}
   # if version is not None:
   #     kwargs['VersionStage'] = version
    response = secrets_client.get_secret_value(**kwargs)
    print(response)
    return response

get_secret_value()

这是帮助检索机密的示例设计,它给我提供了无法找到凭据的致命错误。

【问题讨论】:

  • 您在哪里以及如何运行代码?您是如何配置凭据的?
  • 我正在通过 cmd 运行我的代码,并在 aws s3 中为 secretManager 配置我的凭据
  • 您需要配置 IAM 访问密钥才能使用 AWS API。见:docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html
  • 您好,我也有访问密钥。
  • 请编辑您的帖子以包含您看到的完整错误消息,以及您正在运行的代码,而不是带有语法错误的 with 版本。

标签: python python-3.x amazon-s3 pip boto3


【解决方案1】:

如果您在 Amazon EC2 实例上运行此代码,则应为该实例分配一个 IAM 角色。凭据将通过 boto3 自动提供给您的程序。

如果您在自己的计算机上运行此代码,则应运行 AWS Command-Line Interface (CLI) aws configure 命令并提供您的访问密钥和秘密密钥。它将这些凭据存储在~/.aws/credentials 文件中,boto3 将自动检索它们。

【讨论】:

    猜你喜欢
    • 2016-01-22
    • 2020-06-03
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 2022-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多