'How to use Awswrangler inside a Glue Job?
For some reasons, I want to use the python package awswrangler inside a Python 3 Glue Job. There are two main ways I've considered for installing awswrangler:
Specify additional libraries to a glue job. By considering
.whlfile and then passing it to the Glue Job through the--extra-py-filesInstalling inside the python script with
subprocessoros. For example, the code example withosis the following
import os
os.system('python -m pip install --user awswrangler==0.0.b0')
Notice in the last case, that I've gone down to even use the first pre-release version of awswrangler. Full list of versions can be found here. However, even with the first prelease I'm unable to use awswrangler on a Glue script. Is there a way to achieve this?
Solution 1:[1]
It turns out that the official Awswrangler Documentation provides you with a .whl file, that contains the desired version of the package, to specify on the Python library path field of the Glue Job. According to the documentation, the steps to follow are:
Download the
.whlfile related to the version that you want to install ofawswranglerfrom here.Upload the
.whlfile to an s3 bucket, notice that the role you assign to your glue job should have access to read this bucket.In the in the Python library path field specify the location of the wheel file. For example, for the current 1.9.3 version it is
s3://your-bucket/glue_wheels/awswrangler-1.9.3-py3-none-any.whl
Solution 2:[2]
It works for me below to install and use awswrangler. Add key/values in Glue Job parameters.
key: --additional-python-modules
value: pyarrow==2,awswrangler==2.4.0
Solution 3:[3]
use this it work for me
import os
import sys
import subprocess
subprocess.call('pip3 install awswrangler -t /tmp/ --no-cache-dir'.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
sys.path.insert(1, '/tmp/')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Miguel Trejo |
| Solution 2 | Jin |
| Solution 3 | foreverska |
