【问题标题】:boto3 UnrecognizedClientException when querying Athena查询 Athena 时出现 boto3 UnrecognizedClientException
【发布时间】:2019-11-23 17:04:13
【问题描述】:

我正在使用下面列出的代码创建 Athena 客户端 -

client = boto3.client('athena',aws_access_key_id='<access key id>',aws_secret_access_key='<secret access key>',region_name='us-east-1')

那我用这个客户端去查询雅典娜-

response = client.start_query_execution(QueryString=query_string,QueryExecutionContext={'Database': database},WorkGroup=workgroup)

我看到以下错误。你能告诉我我可能缺少什么吗?

botocore.exceptions.ClientError:发生错误 (UnrecognizedClientException) 调用 StartQueryExecution 时 operation: 请求中包含的安全令牌无效。

【问题讨论】:

  • 您确定凭据有效吗?他们是否可以与使用 boto3 的其他服务一起正常工作?检查凭据是否属于您要查询的区域。
  • @Imran ,有没有办法检查与凭据关联的角色?
  • 您可以使用 sts get-caller-identity (docs.aws.amazon.com/cli/latest/reference/sts/…)。您还可以查看stackoverflow.com/questions/31836816/… 了解其他方法。
  • 最后是 IAM 策略模拟器:docs.aws.amazon.com/IAM/latest/UserGuide/…
  • 使用 AWS CLI。您可以尝试提供UserNameaws iam get-user(使用默认凭据),然后您可以获得附加到特定用户的策略。例如-aws iam list-user-policies --user-name myuser。如果您想使用boto3,那么herehere 是您可以尝试使用IAM 服务的方法。

标签: python amazon-web-services amazon-s3 boto3 amazon-athena


【解决方案1】:

您能检查一下您的 aws 密钥详细信息吗?错误表示 aws 键无效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 2019-05-21
    • 2018-08-03
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    相关资源
    最近更新 更多