

# 开发蓝图的先决条件
<a name="developing-blueprints-prereq"></a>

要开发蓝图，您应熟悉使用 AWS Glue 和为 Apache Spark ETL 任务或 Python shell 任务编写脚本。此外，您还必须完成以下设置任务。
+ 下载 4 个 AWS Python 库，以在蓝图布局脚本中使用。
+ 设置 AWS SDK。
+ 设置 AWS CLI。

## 下载 Python 库
<a name="prereqs-get-libes"></a>

从 GitHub 下载以下库，并将它们安装到您的项目中：
+ [https://github.com/awslabs/aws-glue-blueprint-libs/tree/master/awsglue/blueprint/base\$1resource.py](https://github.com/awslabs/aws-glue-blueprint-libs/tree/master/awsglue/blueprint/base_resource.py)
+ [https://github.com/awslabs/aws-glue-blueprint-libs/tree/master/awsglue/blueprint/workflow.py](https://github.com/awslabs/aws-glue-blueprint-libs/tree/master/awsglue/blueprint/workflow.py)
+ [https://github.com/awslabs/aws-glue-blueprint-libs/tree/master/awsglue/blueprint/crawler.py](https://github.com/awslabs/aws-glue-blueprint-libs/tree/master/awsglue/blueprint/crawler.py)
+ [https://github.com/awslabs/aws-glue-blueprint-libs/tree/master/awsglue/blueprint/job.py](https://github.com/awslabs/aws-glue-blueprint-libs/tree/master/awsglue/blueprint/job.py)

## 设置 AWS Java SDK
<a name="prereqs-java-preview-sdk"></a>

对于 AWS Java SDK，您必须添加 `jar` 文件，其中包含适用于蓝图的 API。

1. 如果您还没有这样做，请设置 AWS SDK for Java。
   + 对于 Java 1.x，请遵循*《适用于 Java 的 AWS SDK 开发人员指南》*中的[设置 适用于 Java 的 AWS SDK](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-install.html)。
   + 对于 Java 2.x，请遵循*《AWS SDK for Java 2.x 开发人员指南》*中的[设置 AWS SDK for Java 2.x](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup.html)。

1. 下载客户端 `jar` 文件，该文件拥有访问适用于蓝图的 API 权限。
   + 对于 Java 1.x：s3://awsglue-custom-blueprints-preview-artifacts/awsglue-java-sdk-preview/AWSGlueJavaClient-1.11.x.jar
   + 对于 Java 2.x：s3://awsglue-custom-blueprints-preview-artifacts/awsglue-java-sdk-v2-preview/AwsJavaSdk-Glue-2.0.jar

1. 将客户端 `jar` 添加到 Java 类路径前，覆盖由 AWS Java SDK 提供的 AWS Glue 客户端。

   ```
   export CLASSPATH=<path-to-preview-client-jar>:$CLASSPATH
   ```

1. （可选）使用以下 Java 应用程序测试 SDK。应用程序应输出空列表。

   将 `accessKey` 和 `secretKey` 替换为您的凭证，然后将 `us-east-1` 替换为您的区域。

   ```
   import com.amazonaws.auth.AWSCredentials;
   import com.amazonaws.auth.AWSCredentialsProvider;
   import com.amazonaws.auth.AWSStaticCredentialsProvider;
   import com.amazonaws.auth.BasicAWSCredentials;
   import com.amazonaws.services.glue.AWSGlue;
   import com.amazonaws.services.glue.AWSGlueClientBuilder;
   import com.amazonaws.services.glue.model.ListBlueprintsRequest;
   
   public class App{
       public static void main(String[] args) {
           AWSCredentials credentials = new BasicAWSCredentials("accessKey", "secretKey");
           AWSCredentialsProvider provider = new AWSStaticCredentialsProvider(credentials);
           AWSGlue glue = AWSGlueClientBuilder.standard().withCredentials(provider)
                   .withRegion("us-east-1").build();
           ListBlueprintsRequest request = new ListBlueprintsRequest().withMaxResults(2);
           System.out.println(glue.listBlueprints(request));
       }
   }
   ```

## 设置 AWS Python SDK
<a name="prereqs-python-preview-sdk"></a>

以下步骤假定您的计算机上已安装 Python 版本 2.7 或更高版本，或者版本 3.9 或更高版本。

1. 下载下面的 boto3 wheel 文件。如果提示打开或保存文件，请保存文件 s3://awsglue-custom-blueprints-preview-artifacts/aws-python-sdk-preview/boto3-1.17.31-py2.py3-none-any.whl

1. 下载以下 botocore wheel 文件：s3://awsglue-custom-blueprints-preview-artifacts/aws-python-sdk-preview/botocore-1.20.31-py2.py3-none-any.whl

1. 检查您的 Python 版本。

   ```
   python --version
   ```

1. 根据您的 Python 版本，输入以下命令（适用于 Linux）：
   + 对于 Python 2.7 或更高版本。

     ```
     python3 -m pip install --user virtualenv
     source env/bin/activate
     ```
   + 对于 Python 3.9 或更高版本。

     ```
     python3 -m venv python-sdk-test
     source python-sdk-test/bin/activate
     ```

1. 安装 botocore wheel 文件。

   ```
   python3 -m pip install <download-directory>/botocore-1.20.31-py2.py3-none-any.whl
   ```

1. 安装 boto3 wheel 文件。

   ```
   python3 -m pip install <download-directory>/boto3-1.17.31-py2.py3-none-any.whl
   ```

1. 在 `~/.aws/credentials` 和 `~/.aws/config` 文件中配置您的凭证和默认区域。有关更多信息，请参阅《AWS Command Line Interface 用户指南》**中的[配置 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)。

1. （可选）测试您的设置。以下命令应该返回空列表。

   将 `us-east-1` 替换为您的区域。

   ```
   $ python
   >>> import boto3
   >>> glue = boto3.client('glue', 'us-east-1')
   >>> glue.list_blueprints()
   ```

## 设置预览 AWS CLI
<a name="prereqs-setup-cli"></a>

1. 如果您还没有这样做，请安装和/或更新适用于电脑的 AWS Command Line Interface（AWS CLI）。执行该操作的最简单方法是使用 `pip`，Python 实用安装程序：

   ```
   pip install awscli --upgrade --user
   ```

   您可在此处查找 AWS CLI 的完整安装说明：[安装 AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/installing.html)。

1. 下载 AWS CLI wheel 文件：s3://awsglue-custom-blueprints-preview-artifacts/awscli-preview-build/awscli-1.19.31-py2.py3-none-any.whl

1. 安装 AWS CLI wheel 文件。

   ```
   python3 -m pip install awscli-1.19.31-py2.py3-none-any.whl
   ```

1. 运行 `aws configure` 命令。配置 AWS 凭证（包括访问密钥和私有密钥）和 AWS 区域。您可在此处找到有关配置 AWS CLI 的信息：[配置 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)。

1. 测试 AWS CLI。以下命令应该返回空列表。

   将 `us-east-1` 替换为您的区域。

   ```
   aws glue list-blueprints --region us-east-1
   ```