python - 如何使用当前版本的 boto3 运行 AWS Glue Python Spark 作业?

标签 python amazon-web-services configuration boto3 aws-glue

我正在尝试在 AWS Glue spark 作业中运行最新版本的 boto3,以访问 Glue 的默认版本中不可用的方法。

要获取 boto3 的默认版本并验证我想要访问的方法不可用,我运行了这段代码,除了我的 print 语句之外,它都是样板:

import sys
import boto3
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])

sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)

athena = boto3.client('athena')
print(boto3.__version__) # verify the default version boto3 imports
print(athena.list_table_metadata) # method I want to verify I can access in Glue

job.commit()

返回

1.12.4

Traceback (most recent call last): File "/tmp/another_sample", line 20, in print(athena.list_table_metadata) File "/home/spark/.local/lib/python3.7/site-packages/botocore/client.py", line 566, in getattr self.class.name, item) AttributeError: 'Athena' object has no attribute 'list_table_metadata'

好的,正如预期的旧版本的 boto3。让我们尝试导入最新版本...

我执行以下步骤:

  1. 转至 https://pypi.org/project/boto3/#files
  2. 下载boto3-1.17.13-py2.py3-none-any.whl文件
  3. 将其放置在 S3 位置
  4. 返回 Glue 作业并在 安全配置、脚本库和作业参数(可选) 部分下,我使用 S3 位置更新 Python 库路径第三步
  5. 从上面重新运行代码块

返回

1.17.9

Traceback (most recent call last): File "/tmp/another_sample", line 20, in print(athena.list_table_metadata) File "/home/spark/.local/lib/python3.7/site-packages/botocore/client.py", line 566, in getattr self.class.name, item) AttributeError: 'Athena' object has no attribute 'list_table_metadata'

如果我在本地运行相同的脚本,它正在运行 1.17.9,我可以找到方法:

1.17.9

<bound method ClientCreator._create_api_method.._api_call of <botocore.client.Athena object at 0x7efd8a4f4710>>

关于这里发生了什么以及如何访问我期望应该在升级版本中导入的方法的任何想法?

最佳答案

最终在 AWS documentation 中找到了解决方法.

在作业的安全配置、脚本库和作业参数(可选)部分下的 Glue 作业参数中添加了以下键/值对: p>

:

--additional-python-modules

值(value):

botocore>=1.20.12,boto3>=1.17.12

enter image description here

关于python - 如何使用当前版本的 boto3 运行 AWS Glue Python Spark 作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66337922/

相关文章:

mysql 慢日志查询

php - 亚马逊 Ubuntu 服务器上的 Rain 框架

build - 有没有办法在 C# 代码中获取事件解决方案配置名称?

visual-studio - opencv中的链接器问题

python - 当我尝试通过单击图像按钮打开文件选择器时发生错误

python - Pycharm 1.2 忽略名为 cvs 的目录

php - 将Amazon ElasticSearch Service用作PHP应用程序的Web服务

django - 运行PyCharm测试时,如何解决“django.core.exceptions.ImproperlyConfigured:找不到GDAL库”?

python - Python 中的循环

python - unicode 字符名称列表