

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 將資料上傳至 Amazon S3 Express One Zone
<a name="emr-express-one-zone"></a>

## 概觀
<a name="emr-express-one-zone-overview"></a>

使用 Amazon EMR 6.15.0 及更高版本時，您可以將 Amazon EMR 搭配 Apache Spark，並與 [Amazon S3 Express One Zone](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-one-zone.html) 儲存類別結合使用，以提高 Spark 作業的效能。Amazon EMR 7.2.0 版和更新版本也支援 HBase、Flink 和 Hive，因此如果您使用這些應用程式，也可以受益於 S3 Express One Zone。*S3 Express One Zone* 是 S3 儲存類別，適用於頻繁存取資料的應用程式 (每秒有數十萬個請求)。在發布時，S3 Express One Zone 提供 Amazon S3 中最低延遲和最高效能的雲端物件儲存。

## 先決條件
<a name="emr-express-one-zone-prereqs"></a>
+ **S3 Express One Zone 許可**：當 S3 Express One Zone 最初在 S3 物件上執行 `GET`、`LIST` 或 `PUT` 等動作時，儲存類別會代表您呼叫 `CreateSession`。您的 IAM 政策必須允許 `s3express:CreateSession` 許可，S3A 連接器才能調用 `CreateSession` API。如需具有此許可的範例政策，請參閱 [開始使用 Amazon S3 Express One Zone](#emr-express-one-zone-start)。
+ **S3A 連接器**：若要將 Spark 叢集設定為存取使用 S3 Express One Zone 儲存類別的 Amazon S3 儲存貯體中的資料，您必須使用 Apache Hadoop 連接器 S3A。若要使用該連接器，請確保所有 S3 URI 均使用 `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"
    }
  }
]
```

## 開始使用 Amazon S3 Express One Zone
<a name="emr-express-one-zone-start"></a>

**Topics**
+ [建立許可政策](#emr-express-one-zone-permissions)
+ [建立和設定叢集](#emr-express-one-zone-create)
+ [組態概觀](#emr-express-one-zone-configs)

### 建立許可政策
<a name="emr-express-one-zone-permissions"></a>

在建立使用 Amazon S3 Express One Zone 的叢集之前，您必須先建立 IAM 政策以連接至該叢集的 Amazon EC2 執行個體設定檔。該 IAM 政策必須具有 S3 Express One Zone 儲存類別的存取許可。下列範例政策示範如何授予所需的許可。建立政策後，將政策連接至用於建立 EMR 叢集的執行個體設定檔角色，如 [建立和設定叢集](#emr-express-one-zone-create) 一節中所述。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Resource": [
        "arn:aws:s3express:*:123456789012:bucket/example-s3-bucket"
      ],
      "Action": [
        "s3express:CreateSession"
      ],
      "Sid": "AllowS3EXPRESSCreatesession"
    }
  ]
}
```

------

### 建立和設定叢集
<a name="emr-express-one-zone-create"></a>

接著，建立執行 Spark、HBase、Flink 或 Hive 搭配 S3 Express One Zone 的叢集。下列步驟說明在 AWS 管理主控台中建立叢集的高階概觀：

1. 導覽至 Amazon EMR 主控台，然後從側邊欄中選取**叢集**。然後選擇**建立叢集**。

1. 如果您使用 Spark，請選取 Amazon EMR 發行版本 `emr-6.15.0` 或更高版本。如果您使用 HBase、Flink 或 Hive，請選取 `emr-7.2.0` 或更高版本。

1. 選取您要包含在叢集上的應用程式，例如 Spark、HBase 或 Flink。

1. 若要啟用 Amazon S3 Express One Zone，請在**軟體設定**區段中輸入類似下列範例的組態。在本程序後的 [組態概觀](#emr-express-one-zone-configs) 一節中會說明組態和建議值。

   ```
   [
     {
       "Classification": "core-site",
       "Properties": {
         "fs.s3a.aws.credentials.provider": "software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider",
         "fs.s3a.change.detection.mode": "none",
         "fs.s3a.endpoint.region": "aa-example-1",
         "fs.s3a.select.enabled": "false"
       }
     },
     {
       "Classification": "spark-defaults",
       "Properties": {
         "spark.sql.sources.fastS3PartitionDiscovery.enabled": "false"
       }
     }
   ]
   ```

1. 在**適用於 Amazon EMR 的 EC2 執行個體設定檔**區段中，選擇使用現有角色，並使用具有您在上述 [建立許可政策](#emr-express-one-zone-permissions) 一節建立之所連接政策的角色。

1. 根據您的應用程式進行其餘叢集設定，然後選取**建立叢集**。

### 組態概觀
<a name="emr-express-one-zone-configs"></a>

下列表格說明您在設定將 S3 Express One Zone 與 Amazon EMR 搭配使用的叢集時應指定的組態和建議值，如 [建立和設定叢集](#emr-express-one-zone-create) 一節中所述。

**S3A 組態**


| 參數 | 預設值 | 建議值 | 說明 | 
| --- | --- | --- | --- | 
|  `fs.s3a.aws.credentials.provider`  |  如果未指定，請依以下順序使用 `AWSCredentialProviderList`：`TemporaryAWSCredentialsProvider`、`SimpleAWSCredentialsProvider`、`EnvironmentVariableCredentialsProvider`、`IAMInstanceCredentialsProvider`。  |  <pre>software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider</pre>  |  Amazon EMR 執行個體設定檔角色應具有允許 S3A 檔案系統呼叫 `s3express:CreateSession` 的政策。具有 S3 Express One Zone 許可的其他憑證提供者也適用。  | 
|  `fs.s3a.endpoint.region`  |  null  |  您建立儲存貯 AWS 區域 體的 。  |  區域解析邏輯不適用於 S3 Express One Zone 儲存類別。  | 
|  `fs.s3a.select.enabled`  |  `true`  |  `false`  |  S3 Express One Zone 儲存類別不支援 Amazon S3 `select`。  | 
|  `fs.s3a.change.detection.mode`  |  `server`  |  無  |  S3A 的變更偵測是透過檢查 MD5 型的 `etags` 來運作。S3 Express One Zone 儲存類別不支援 MD5 `checksums`。  | 

**Spark 組態**


| 參數 | 預設值 | 建議值 | 說明 | 
| --- | --- | --- | --- | 
|  `spark.sql.sources.fastS3PartitionDiscovery.enabled`  |  `true`  |  false  |  內部優化使用 S3 Express One Zone 儲存類別不支援的 S3 API 參數。  | 

**Hive 組態**


| 參數 | 預設值 | 建議值 | 說明 | 
| --- | --- | --- | --- | 
|  `hive.exec.fast.s3.partition.discovery.enabled`  |  `true`  |  false  |  內部優化使用 S3 Express One Zone 儲存類別不支援的 S3 API 參數。  | 

## 考量事項
<a name="emr-express-one-zone-considerations"></a>

將 Amazon EMR 上的 Apache Spark 與 S3 Express One Zone 儲存類別整合時請考量以下事項：
+ 需要 S3A 連接器才能將 S3 Express One Zone 與 Amazon EMR 搭配使用。只有 S3A 具有與 S3 Express One Zone 互動所需的功能和儲存類別。如需了解設定該連接器的步驟，請參閱 [先決條件](#emr-express-one-zone-prereqs)。
+ Amazon S3 Express One Zone 儲存類別支援 SSE-S3 和 SSE-KMS 加密。如需詳細資訊，請參閱[使用 Amazon S3 進行伺服器端加密](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-data-protection.html#s3-express-ecnryption)。
+ Amazon S3 Express One Zone 儲存類別不支援使用 S3A `FileOutputCommitter` 寫入。在 S3 Express One Zone 儲存貯體上使用 S3A `FileOutputCommitter` 寫入會導致錯誤：*InvalidStorageClass: The storage class you specified is not valid*。
+ 在 EC2 上的 EMR 上，Amazon EMR 6.15.0 版及更高版本支援 Amazon S3 Express One Zone。此外，Amazon EMR 7.2.0 版及更新版本支援 Amazon EMR on EKS 和 Amazon EMR Serverless。