

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

# 利用 EMR Serverless 将数据导入 S3 Express One Zone
<a name="upload-data"></a>

对于 Amazon EMR 7.2.0 及更高版本，请将 EMR Serverless 与 [Amazon S3 Express One Zone](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-one-zone.html) 存储类别结合使用，以提高运行作业和工作负载时的性能。S3 Express One Zone 是一种高性能的单区 Amazon S3 存储类，可为大多数延迟敏感型应用程序提供一致的个位数毫秒级数据访问。S3 Express One Zone 在其发布时，提供了 Amazon S3 中延迟最低、性能最高的云对象存储。

## 先决条件
<a name="upload-data-prereqs"></a>
+ S3 Express One Zone 权限：当 S3 Express One Zone 最初在 S3 对象上调用 `GET`、`LIST` 或 `PUT` 等操作时，存储类会代表您调用 `CreateSession`。您的 IAM policy 必须允许 `s3express:CreateSession` 权限，S3A 连接器才能调用 `CreateSession` API。有关使用此权限的示例策略，请参阅[开始使用 S3 Express One Zone](#upload-data-get-started)。
+ S3A 连接器：要将 Spark 配置为从使用 S3 Express One Zone 存储类的 Amazon S3 存储桶中访问数据，请使用 Apache Hadoop 连接器 S3A。要使用连接器，请确保所有 S3 都 URIs 使用该`s3a`方案。如果没有，请更改用于 `s3` 和 `s3n` 方案的文件系统实施。

要更改 `s3` 方案，请指定以下集群配置：

```
[
  {
    "Classification": "core-site",
    "Properties": {
      "fs.s3.impl": "org.apache.hadoop.fs.s3a.S3AFileSystem",
      "fs.AbstractFileSystem.s3.impl": "org.apache.hadoop.fs.s3a.S3A"
    }
  }
]
```

要更改 `s3n` 方案，请指定以下集群配置：

```
[
  {
    "Classification": "core-site",
    "Properties": {
      "fs.s3n.impl": "org.apache.hadoop.fs.s3a.S3AFileSystem",
      "fs.AbstractFileSystem.s3n.impl": "org.apache.hadoop.fs.s3a.S3A"
    }
  }
]
```

## 开始使用 S3 Express One Zone
<a name="upload-data-get-started"></a>

按照以下步骤开始使用 S3 Express One Zone。

1. [创建 VPC 端点](https://docs.aws.amazon.com/vpc/latest/privatelink/create-interface-endpoint.html#create-interface-endpoint-aws)。将端点 ` com.amazonaws.us-west-2.s3express` 添加到 VPC 端点。

1. 按照[开始使用 Amazon EMR Serverless](https://docs.aws.amazon.com/emr/latest/EMR-Serverless-UserGuide/getting-started.html)，创建 Amazon EMR 7.2.0 或更高版本的应用程序。

1. [配置应用程序](https://docs.aws.amazon.com/emr/latest/EMR-Serverless-UserGuide/vpc-access.html)以使用新建的 VPC 端点、私有子网组和安全组。

1. 为作业执行角色添加 `CreateSession` 权限。

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Resource": [
           "*"
         ],
         "Action": [
           "s3express:CreateSession"
         ],
         "Sid": "AllowS3EXPRESSCreatesession"
       }
     ]
   }
   ```

------

1. 运行作业。请注意，请使用 `S3A` 方案访问 S3 Express One Zone 存储桶。

   ```
   aws emr-serverless start-job-run \      
   --application-id <application-id> \          
   --execution-role-arn <job-role-arn> \
   --name <job-run-name> \
   --job-driver '{
    "sparkSubmit": {                                                                                                                                                                                      
    "entryPoint": "s3a://<DOC-EXAMPLE-BUCKET>/scripts/wordcount.py", 
    "entryPointArguments":["s3a://<DOC-EXAMPLE-BUCKET>/emr-serverless-spark/output"],
    "sparkSubmitParameters": "--conf spark.executor.cores=4 
    --conf spark.executor.memory=8g --conf spark.driver.cores=4 
    --conf spark.driver.memory=8g --conf spark.executor.instances=2 
    --conf spark.hadoop.fs.s3a.change.detection.mode=none 
    --conf spark.hadoop.fs.s3a.endpoint.region={<AWS_REGION>}
    --conf spark.hadoop.fs.s3a.select.enabled=false 
    --conf spark.sql.sources.fastS3PartitionDiscovery.enabled=false 
    }'
   ```