设置 VPC 以连接到 PyPI for Amazon Glue - Amazon Glue
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

设置 VPC 以连接到 PyPI for Amazon Glue

Python Package Index(PyPI)是 Python 编程语言的软件库。本主题介绍支持使用 pip install 的软件包所需的详细信息(由会话创建者使用 --additional-python-modules 标志指定)。

使用与连接器的 Amazon Glue 交互式会话会导致通过为连接器指定的子网使用 VPC 网络。因此,除非您设置特殊配置,否则 Amazon 服务和其他网络目标不可用。

该问题的解决方法包括:

  • 使用您的会话可以访问的互联网网关。

  • 设置并使用带有 PyPI/simple 存储库的 S3 存储桶,其中包含软件包集依赖关系的传递闭包。

  • 使用镜像 PyPI 并连接到您的 VPC 的 CodeArtifact 存储库。

设置互联网网关

技术方面在 NAT 网关用例中有详细介绍,但请注意使用 --additional-python-modules 的这些要求。具体而言,--additional-python-modules 需要访问 pypi.org,这取决于您的 VPC 的配置。请注意以下要求:

  1. 要求通过 pip install 为用户会话安装其他 python 模块。如果会话使用连接器,则您的配置可能会受到影响。

  2. 当连接器与 --additional-python-modules 一起使用时,启动会话时,与该连接器的 PhysicalConnectionRequirements 关联的子网必须提供到达 pypi.org 的网络路径。

  3. 您必须确定配置是否正确。

设置 Amazon S3 存储桶以托管目标 PyPI/simple 存储库

此示例在 Amazon S3 中为一组软件包及其依赖关系设置了 PyPI 镜像。

要为一组软件包设置 PyPI 镜像,请执行以下操作:

# pip download all the dependencies pip download -d s3pypi --only-binary :all: plotly gglplot pip download -d s3pypi --platform manylinux_2_17_x86_64 --only-binary :all: psycopg2-binary # create and upload the pypi/simple index and wheel files to the s3 bucket s3pypi -b test-domain-name --put-root-index -v s3pypi/*

如果您已经有现有构件存储库,它将有一个索引 URL 供 pip 使用,您可以提供该索引 URL 来代替上述 Amazon S3 存储桶的示例 URL。

要使用自定义 index-url,请使用一些示例包:

%%configure { "--additional-python-modules": "psycopg2_binary==2.9.5", "python-modules-installer-option": "--no-cache-dir --verbose --index-url https://test-domain-name.s3.amazonaws.com/ --trusted-host test-domain-name.s3.amazonaws.com" }

设置连接到您的 VPC 的 pypi 的 CodeArtifact 镜像

要设置镜像,请执行以下操作:

  1. 在与连接器使用的子网相同的区域中创建存储库。

    选择 Public upstream repositories,然后选择 pypi-store

  2. 提供从 VPC 访问子网存储库的权限。

  3. 使用 python-modules-installer-option 指定正确的 --index-url

    %%configure { "--additional-python-modules": "psycopg2_binary==2.9.5", "python-modules-installer-option": "--no-cache-dir --verbose --index-url https://test-domain-name.s3.amazonaws.com/ --trusted-host test-domain-name.s3.amazonaws.com" }

有关更多信息,请参阅 Use CodeArtifact from a VPC