简体   繁体   English

AWS Glue 作业错误 boto3 版本

[英]AWS Glue Job Wrong boto3 Version

I'm trying to run the latest version of boto3 in an AWS Glue spark job to access methods that aren't available in the default version in Glue.我正在尝试在 AWS Glue 火花作业中运行最新版本的 boto3 以访问 Glue 的默认版本中不可用的方法。

To get the default version of boto3 and verify the method I want to access isn't available I run this block of code which is all boilerplate except for my print statements:为了获得 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()

which returns返回

1.12.4 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.回溯(最后一次调用):文件“/tmp/another_sample”,第 20 行,在 print(athena.list_table_metadata) 文件“/home/spark/.local/lib/python3.7/site-packages/botocore/client. py",第 566 行,在getattr self. class . class name , item) AttributeError: 'Athena' object has no attribute 'list_table_metadata' name , item) AttributeError: 'Athena' object has no attribute 'list_table_metadata'

Ok, as expected with an older version of boto3.好的,正如旧版本的 boto3 所期望的那样。 Let's try and import the latest version...让我们尝试导入最新版本...

I perform the following steps:我执行以下步骤:

  1. Go to https://pypi.org/project/boto3/#files Go 到https://pypi.org/project/boto3/#files
  2. Download the boto3-1.17.13-py2.py3-none-any.whl file下载boto3-1.17.13-py2.py3-none-any.whl文件
  3. Place it in S3 location将其放置在 S3 位置
  4. Go back to the Glue Job and under the Security configuration, script libraries, and job parameters (optional) section I update the Python library path with the S3 location from step 3 Go 返回 Glue 作业并在安全配置、脚本库和作业参数(可选)部分下,我使用步骤 3 中的 S3 位置更新Python 库路径
  5. Rerun block of code from above从上面重新运行代码块

which returns返回

1.17.9 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.回溯(最后一次调用):文件“/tmp/another_sample”,第 20 行,在 print(athena.list_table_metadata) 文件“/home/spark/.local/lib/python3.7/site-packages/botocore/client. py",第 566 行,在getattr self. class . class name , item) AttributeError: 'Athena' object has no attribute 'list_table_metadata' name , item) AttributeError: 'Athena' object has no attribute 'list_table_metadata'

If I run this same script locally, which is running 1.17.9 I can find the method:如果我在本地运行相同的脚本,它正在运行 1.17.9,我可以找到该方法:

1.17.9 1.17.9

<bound method ClientCreator._create_api_method.._api_call of <botocore.client.Athena object at 0x7efd8a4f4710>> <botocore.client.Athena object at 0x7efd8a4f4710的<绑定方法ClientCreator._create_api_method.._api_call>>

Any ideas on what's going on here and how to access the methods that I would expect should be imported in the upgraded version?关于这里发生了什么以及如何访问我期望应该在升级版本中导入的方法的任何想法?

Ended up finding a work-around solution in the AWS documentation .最终在AWS 文档中找到了解决方案。

Added the following Key/Value pair in the Glue Job parameters under the Security configuration, script libraries, and job parameters (optional) section of the job:在作业的安全配置、脚本库和作业参数(可选)部分下的 Glue作业参数中添加了以下键/值对:

Key :关键

--additional-python-modules --additional-python-modules

Value :价值

botocore>=1.20.12,boto3>=1.17.12 botocore>=1.20.12,boto3>=1.17.12

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM