我正在使用 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"
但它不起作用。
有什么想法吗?
您很可能混淆了 AWS 配置和凭证文件的角色(请参阅此处的文档:https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)
作为参考,您可以使用 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>')
您也可以选择
或将 S3 存储桶输出位置设置为work_group
s3_staging_dir
如果仍然失败,可能是因为您没有在
~/.aws/credentials
中正确设置命名配置文件