Jupyter Notebook 中的 Pyathena 找不到 aws 配置文件

问题描述 投票:0回答:1

我正在使用 jupyter 笔记本,并且我正在尝试通过笔记本使用 PyAthena 模块查询 AWS athena。

我在项目中的第一行是:

athena = pyathena.connect(profile_name="NAME")

它可以在我的计算机上的任何其他平台(iPython、Pycharm..)上运行,但不能在 Jupyter Notebook 上运行,并返回:

ProfileNotFound: The config profile (core) could not be found

我尝试像这样更改环境变量:

!set AWS_CONFIG_FILE="~/.aws/config"
但它不起作用。

有什么想法吗?

python amazon-web-services jupyter-notebook amazon-athena pyathena
1个回答
0
投票

您很可能混淆了 AWS 配置和凭证文件的角色(请参阅此处的文档:https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html

  • 您应该首先尝试在 bash 中使用 AWS CLI 通过一个非常简单的命令进行身份验证,以确认您的命名配置文件设置正确。

作为参考,您可以使用 Jupyter Notebook 单元格内的

!
(感叹号)来运行 bash 命令。有关参考,请参阅此处的 Jupyter Magics:https://ipython.readthedocs.io/en/stable/interactive/magics.html#line-magics

!aws sts get-caller-identity --profile <YOUR_NAMED_PROFILE_HERE>

假设返回成功响应,您应该能够像下面这样使用 PyAthena:

from pyathena import connect

conn = connect(profile_name='<YOUR_NAMED_PROFILE_HERE>',
               work_group='<YOUR_WORKGROUP_HERE>', 
               region_name='<YOUR_REGION_HERE>')

您也可以选择

work_group
或将 S3 存储桶输出位置设置为
s3_staging_dir

如果仍然失败,可能是因为您没有在

~/.aws/credentials

中正确设置命名配置文件
© www.soinside.com 2019 - 2024. All rights reserved.