

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

# 使用 S3 on Outposts 物件
<a name="S3OutpostsWorkingObjects"></a>

使用 Amazon S3 on Outposts，您可以在 AWS Outposts 上建立 S3 儲存貯體，並針對需要本機資料存取、本機資料處理和資料駐留的應用程式，在內部部署輕鬆存放和擷取物件。S3 on Outposts 提供新的儲存類別 S3 Outposts (`OUTPOSTS`)，其使用 Amazon S3 APIs，旨在在您的多個裝置和伺服器上以持久且備援的方式存放資料 AWS Outposts。您可以使用存取點和透過 Virtual Private Cloud (VPC) 的端點連線，與您的 Outpost 儲存貯體進行通訊。就像在 Amazon S3 儲存貯體一樣，您在 Outpost 儲存貯體上可以使用同樣的 API 和功能，包括存取政策、加密和標記。您可以透過 AWS 管理主控台、 AWS Command Line Interface (AWS CLI)、SDK 或 REST API 使用 S3 on Outposts。 AWS SDKs 

物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時，您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊，請參閱 [針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名](s3-outposts-access-points-alias.md)。

下列範例顯示 S3 on Outposts 存取點的 ARN 格式，其中包含 Outpost 所在區域的 AWS 區域 程式碼、 AWS 帳戶 ID、Outpost ID 和存取點名稱：

```
arn:aws:s3-outposts:region:account-id:outpost/outpost-id/accesspoint/accesspoint-name
```

如需 S3 on Outposts ARN 的詳細資訊，請參閱 [適用於 S3 on Outposts 的資源 ARN](S3OutpostsIAM.md#S3OutpostsARN)。

物件 ARNs使用下列格式，其中包括 AWS 區域 Outpost 所在的 、 AWS 帳戶 ID、Outpost ID、儲存貯體名稱和物件金鑰：

```
arn:aws:s3-outposts:us-west-2:123456789012:​outpost/op-01ac5d28a6a232904/bucket/amzn-s3-demo-bucket1/object/myobject
```

對於 Amazon S3 on Outposts，物件資料始終存放在 Outpost 上。當 AWS 安裝 Outpost 機架時，您的資料會保留在 Outpost 的本機，以符合資料駐留需求。您的物件永遠不會離開您的 Outpost，也不會在 AWS 區域中。由於 AWS 管理主控台 是在 區域中託管，因此您無法使用 主控台來上傳或管理 Outpost 中的物件。不過，您可以使用 REST API、 AWS Command Line Interface (AWS CLI) 和 AWS SDKs 透過存取點上傳和管理物件。

**Topics**
+ [將物件上傳至 S3 on Outposts 儲存貯體](S3OutpostsUploadObjects.md)
+ [使用 在 Amazon S3 on Outposts 儲存貯體中複製物件 適用於 Java 的 AWS SDK](S3OutpostsCopyObject.md)
+ [從 Amason S3 on Outposts 儲存貯體取得物件](S3OutpostsGetObject.md)
+ [列出 Amazon S3 on Outposts 儲存貯體中的物件](S3OutpostsListObjects.md)
+ [刪除 Amazon S3 on Outposts 儲存貯體中的物件](S3OutpostsDeleteObject.md)
+ [使用 HeadBucket 判斷 S3 on Outposts 儲存貯體是否存在，並且您是否擁有存取許可](S3OutpostsHeadBucket.md)
+ [使用適用於 Java 的開發套件執行和管理分段上傳](S3OutpostsMPU.md)
+ [使用適用於 S3 on OutOutposts 的預先簽章 URL](S3OutpostsPresignedURL.md)
+ [搭配使用 Amazon S3 on Outposts 和本機 Amazon EMR on Outposts](s3-outposts-emr.md)
+ [授權與身分驗證快取](s3-outposts-auth-cache.md)

# 將物件上傳至 S3 on Outposts 儲存貯體
<a name="S3OutpostsUploadObjects"></a>

物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時，您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊，請參閱 [針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名](s3-outposts-access-points-alias.md)。

下列範例顯示 S3 on Outposts 存取點的 ARN 格式，其中包含 Outpost 所在區域的 AWS 區域 程式碼、 AWS 帳戶 ID、Outpost ID 和存取點名稱：

```
arn:aws:s3-outposts:region:account-id:outpost/outpost-id/accesspoint/accesspoint-name
```

如需 S3 on Outposts ARN 的詳細資訊，請參閱 [適用於 S3 on Outposts 的資源 ARN](S3OutpostsIAM.md#S3OutpostsARN)。

對於 Amazon S3 on Outposts，物件資料始終存放在 Outpost 上。當 AWS 安裝 Outpost 機架時，您的資料會保留在 Outpost 的本機，以符合資料駐留需求。您的物件永遠不會離開您的 Outpost，也不會在 AWS 區域中。由於 AWS 管理主控台 是在 區域中託管，因此您無法使用 主控台來上傳或管理 Outpost 中的物件。不過，您可以使用 REST API、 AWS Command Line Interface (AWS CLI) 和 AWS SDKs 透過存取點上傳和管理物件。

下列 AWS CLI 和 適用於 Java 的 AWS SDK 範例示範如何使用存取點將物件上傳至 S3 on Outposts 儲存貯體。

------
#### [ AWS CLI ]

**Example**  
下列範例使用 AWS CLI將名稱為 `sample-object.xml` 的物件放置在 S3 on Outposts 儲存貯體 (`s3-outposts:PutObject`) 上。若要執行此命令，請以您自己的資訊取代每個 `user input placeholder`。如需此命令的詳細資訊，請參閱 *AWS CLI 參考*中的 [put-object](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/put-object.html)。  

```
aws s3api put-object --bucket arn:aws:s3-outposts:Region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point --key sample-object.xml --body sample-object.xml
```

------
#### [ SDK for Java ]

**Example**  
如需如何使用適用於 Java 的 AWS SDK 將物件上傳至 S3 Outposts 儲存貯體的範例，請參閱*AWS 適用於 Java 的 SDK 2.x 程式碼範例*中的 [PutObjectOnOutpost.java](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/s3/src/main/java/com/example/s3/outposts/PutObjectOnOutpost.java)。

------

# 使用 在 Amazon S3 on Outposts 儲存貯體中複製物件 適用於 Java 的 AWS SDK
<a name="S3OutpostsCopyObject"></a>

物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時，您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊，請參閱 [針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名](s3-outposts-access-points-alias.md)。

下列範例顯示 S3 on Outposts 存取點的 ARN 格式，其中包含 Outpost 所在區域的 AWS 區域 程式碼、 AWS 帳戶 ID、Outpost ID 和存取點名稱：

```
arn:aws:s3-outposts:region:account-id:outpost/outpost-id/accesspoint/accesspoint-name
```

如需 S3 on Outposts ARN 的詳細資訊，請參閱 [適用於 S3 on Outposts 的資源 ARN](S3OutpostsIAM.md#S3OutpostsARN)。

對於 Amazon S3 on Outposts，物件資料始終存放在 Outpost 上。當 AWS 安裝 Outpost 機架時，您的資料會保留在 Outpost 的本機，以符合資料備援需求。您的物件永遠不會離開您的 Outpost，也不會在 AWS 區域中。由於 AWS 管理主控台 是在 區域中託管，因此您無法使用 主控台來上傳或管理 Outpost 中的物件。不過，您可以使用 REST API、 AWS Command Line Interface (AWS CLI) 和 AWS SDKs 透過存取點上傳和管理物件。

下列範例示範如何使用 適用於 Java 的 AWS SDK複製 S3 on Outposts 儲存貯體中的物件。

## 使用適用於 Java 的 AWS 開發套件
<a name="S3OutpostsCopyObjectJava"></a>

下列 S3 on Outposts 範例使用適用於 Java 的開發套件，將物件複製到同一儲存貯體中的新物件。若要使用此範例，請以您自己的資訊取代 `user input placeholders`。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.CopyObjectRequest;

public class CopyObject {
    public static void main(String[] args) {
        String accessPointArn = "*** access point ARN ***";
        String sourceKey = "*** Source object key ***";
        String destinationKey = "*** Destination object key ***";

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            // Copy the object into a new object in the same bucket.
            CopyObjectRequest copyObjectRequest = new CopyObjectRequest(accessPointArn, sourceKey, accessPointArn, destinationKey);
            s3Client.copyObject(copyObjectRequest);
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

# 從 Amason S3 on Outposts 儲存貯體取得物件
<a name="S3OutpostsGetObject"></a>

物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時，您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊，請參閱 [針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名](s3-outposts-access-points-alias.md)。

下列範例顯示 S3 on Outposts 存取點的 ARN 格式，其中包含 Outpost 所在區域的 AWS 區域 程式碼、 AWS 帳戶 ID、Outpost ID 和存取點名稱：

```
arn:aws:s3-outposts:region:account-id:outpost/outpost-id/accesspoint/accesspoint-name
```

如需 S3 on Outposts ARN 的詳細資訊，請參閱 [適用於 S3 on Outposts 的資源 ARN](S3OutpostsIAM.md#S3OutpostsARN)。

對於 Amazon S3 on Outposts，物件資料始終存放在 Outpost 上。當 AWS 安裝 Outpost 機架時，您的資料會保留在 Outpost 的本機，以符合資料駐留需求。您的物件永遠不會離開您的 Outpost，也不會在 AWS 區域中。由於 AWS 管理主控台 是在 區域中託管，因此您無法使用 主控台來上傳或管理 Outpost 中的物件。不過，您可以使用 REST API、 AWS Command Line Interface (AWS CLI) 和 AWS SDKs 透過存取點上傳和管理物件。

下列範例示範如何使用 AWS Command Line Interface (AWS CLI) 和 適用於 Java 的 AWS SDK下載 (取得) 物件。

## 使用 AWS CLI
<a name="S3OutpostsGetObjectCLI"></a>

下列範例使用 AWS CLI從 S3 on Outposts 儲存貯體 (`s3-outposts:GetObject`) 取得名稱為 `sample-object.xml` 的物件。若要執行此命令，請以您自己的資訊取代每個 `user input placeholder`。如需此命令的詳細資訊，請參閱 *AWS CLI 參考*中的 [get-object](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/get-object.html)。

```
aws s3api get-object --bucket arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point --key testkey sample-object.xml
```

## 使用適用於 Java 的 AWS 開發套件
<a name="S3OutpostsGetObjectJava"></a>

下列 S3 on Outposts 範例使用適用於 Java 的開發套件取得物件。若要使用此範例，請以您自己的資訊取代每個 `user input placeholder`。如需詳細資訊，請參閱《Amazon Simple Storage Service API 參考》**中的 [GetObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html)。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ResponseHeaderOverrides;
import com.amazonaws.services.s3.model.S3Object;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class GetObject {
    public static void main(String[] args) throws IOException {
        String accessPointArn = "*** access point ARN ***";
        String key = "*** Object key ***";

        S3Object fullObject = null, objectPortion = null, headerOverrideObject = null;
        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            // Get an object and print its contents.
            System.out.println("Downloading an object");
            fullObject = s3Client.getObject(new GetObjectRequest(accessPointArn, key));
            System.out.println("Content-Type: " + fullObject.getObjectMetadata().getContentType());
            System.out.println("Content: ");
            displayTextInputStream(fullObject.getObjectContent());

            // Get a range of bytes from an object and print the bytes.
            GetObjectRequest rangeObjectRequest = new GetObjectRequest(accessPointArn, key)
                    .withRange(0, 9);
            objectPortion = s3Client.getObject(rangeObjectRequest);
            System.out.println("Printing bytes retrieved.");
            displayTextInputStream(objectPortion.getObjectContent());

            // Get an entire object, overriding the specified response headers, and print the object's content.
            ResponseHeaderOverrides headerOverrides = new ResponseHeaderOverrides()
                    .withCacheControl("No-cache")
                    .withContentDisposition("attachment; filename=example.txt");
            GetObjectRequest getObjectRequestHeaderOverride = new GetObjectRequest(accessPointArn, key)
                    .withResponseHeaders(headerOverrides);
            headerOverrideObject = s3Client.getObject(getObjectRequestHeaderOverride);
            displayTextInputStream(headerOverrideObject.getObjectContent());
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        } finally {
            // To ensure that the network connection doesn't remain open, close any open input streams.
            if (fullObject != null) {
                fullObject.close();
            }
            if (objectPortion != null) {
                objectPortion.close();
            }
            if (headerOverrideObject != null) {
                headerOverrideObject.close();
            }
        }
    }

    private static void displayTextInputStream(InputStream input) throws IOException {
        // Read the text input stream one line at a time and display each line.
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        String line = null;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        System.out.println();
    }
}
```

# 列出 Amazon S3 on Outposts 儲存貯體中的物件
<a name="S3OutpostsListObjects"></a>

物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時，您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊，請參閱 [針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名](s3-outposts-access-points-alias.md)。

以下範例顯示了 S3 on Outposts 存取點的 ARN 格式，其中包括 Outpost 所在區域的 AWS 區域代碼、AWS 帳戶 ID、Outposts ID，以及存取點名稱：

```
arn:aws:s3-outposts:region:account-id:outpost/outpost-id/accesspoint/accesspoint-name
```

如需 S3 on Outposts ARN 的詳細資訊，請參閱 [適用於 S3 on Outposts 的資源 ARN](S3OutpostsIAM.md#S3OutpostsARN)。

**注意**  
對於 Amazon S3 on Outposts，物件資料始終存放在 Outpost 上。當 AWS 安裝 Outpost 機架時，您的資料將保留在本機 Outpost 上，以滿足資料落地的要求。您的物件永遠不會離開您的 Outpost，也不會在 AWS 區域 中。由於 AWS 管理主控台 託管在區域內，您無法使用主控台上傳或管理 Outpost 中的物件。然而，您可以使用 REST API、AWS Command Line Interface (AWS CLI) 以及 AWS SDK 透過存取點上傳和管理您的物件。

下列範例示範如何使用 AWS CLI 和 適用於 Java 的 AWS SDK 列出 S3 on Outposts 儲存貯體中的物件。

## 使用 AWS CLI
<a name="S3OutpostsListObjectsCLI"></a>

下列範例使用 AWS CLI 列出 S3 on Outposts 儲存貯體 (`s3-outposts:ListObjectsV2`) 中的物件。若要執行此命令，請以您自己的資訊取代每個 `user input placeholder`。如需此命令的詳細資訊，請參閱 *AWS CLI 參考*中的 [list-objects-v2](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/list-objects-v2.html)。

```
aws s3api list-objects-v2 --bucket arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point
```

**注意**  
透過 AWS SDK 將此動作與 Amazon S3 on Outposts 搭配使用時，您可以提供 Outposts 存取點 ARN 取代儲存貯體名稱，格式如下：`arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-Outposts-Access-Point`。如需 S3 on Outposts ARN 的詳細資訊，請參閱 [適用於 S3 on Outposts 的資源 ARN](S3OutpostsIAM.md#S3OutpostsARN)。

## 使用適用於 Java 的 AWS 軟體開發套件
<a name="S3OutpostsListObjectsJava"></a>

下列 S3 on Outposts 範例使用適用於 Java 的開發套件，在儲存貯體中列出物件。若要使用此範例，請以您自己的資訊取代每個 `user input placeholder`。

**重要**  
此範例使用 [ListObjectsV2](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html)，這是 `ListObjects` API 操作的最新修訂版。建議您使用此修訂版本後的 API 操作進行應用程式進行開發。為了回溯相容性，Amazon S3 會繼續支援此 API 操作的舊版本。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ListObjectsV2Request;
import com.amazonaws.services.s3.model.ListObjectsV2Result;
import com.amazonaws.services.s3.model.S3ObjectSummary;

public class ListObjectsV2 {

    public static void main(String[] args) {
        String accessPointArn = "*** access point ARN ***";

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            System.out.println("Listing objects");

            // maxKeys is set to 2 to demonstrate the use of
            // ListObjectsV2Result.getNextContinuationToken()
            ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(accessPointArn).withMaxKeys(2);
            ListObjectsV2Result result;

            do {
                result = s3Client.listObjectsV2(req);

                for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
                    System.out.printf(" - %s (size: %d)\n", objectSummary.getKey(), objectSummary.getSize());
                }
                // If there are more than maxKeys keys in the bucket, get a continuation token
                // and list the next objects.
                String token = result.getNextContinuationToken();
                System.out.println("Next Continuation Token: " + token);
                req.setContinuationToken(token);
            } while (result.isTruncated());
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

# 刪除 Amazon S3 on Outposts 儲存貯體中的物件
<a name="S3OutpostsDeleteObject"></a>

物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時，您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊，請參閱 [針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名](s3-outposts-access-points-alias.md)。

以下範例顯示了 S3 on Outposts 存取點的 ARN 格式，其中包括 Outpost 所在區域的 AWS 區域代碼、AWS 帳戶 ID、Outposts ID，以及存取點名稱：

```
arn:aws:s3-outposts:region:account-id:outpost/outpost-id/accesspoint/accesspoint-name
```

如需 S3 on Outposts ARN 的詳細資訊，請參閱 [適用於 S3 on Outposts 的資源 ARN](S3OutpostsIAM.md#S3OutpostsARN)。

對於 Amazon S3 on Outposts，物件資料始終存放在 Outpost 上。當 AWS 安裝 Outpost 機架時，您的資料將保留在本機 Outpost 上，以滿足資料落地的要求。您的物件永遠不會離開您的 Outpost，也不會在 AWS 區域 中。由於 AWS 管理主控台 託管在區域內，您無法使用主控台上傳或管理 Outpost 中的物件。然而，您可以使用 REST API、AWS Command Line Interface (AWS CLI) 以及 AWS SDK 透過存取點上傳和管理您的物件。

下列範例示範如何透過使用 AWS Command Line Interface (AWS CLI) 和 適用於 Java 的 AWS SDK 來刪除 S3 on Outposts 儲存貯體中的單個物件或多個物件。

## 使用 AWS CLI
<a name="S3OutpostsDeleteObjectsCLI"></a>

下列範例示範如何從 S3 on Outposts 儲存貯體中刪除單個物件或多個物件。







------
#### [ delete-object ]

下列範例使用 AWS CLI 從 S3 on Outposts 儲存貯體 (`s3-outposts:DeleteObject`) 刪除名稱為 `sample-object.xml` 的物件。若要執行此命令，請以您自己的資訊取代每個 `user input placeholder`。如需此命令的詳細資訊，請參閱 *AWS CLI 參考*中的 [delete-object](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/delete-object.html)。

```
aws s3api delete-object --bucket arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point --key sample-object.xml
```

------
#### [ delete-objects ]

下列範例使用 AWS CLI 從 S3 on Outposts 儲存貯體 (`s3-outposts:DeleteObject`) 刪除名稱為 `sample-object.xml` 和 `test1.text` 的兩個物件。若要執行此命令，請以您自己的資訊取代每個 `user input placeholder`。如需此命令的詳細資訊，請參閱 [AWS CLI 參考](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/delete-objects.html)中的 *delete-objects*。

```
aws s3api delete-objects --bucket arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point --delete file://delete.json

delete.json
{
  "Objects": [
    {
      "Key": "test1.txt"
    },
    {
      "Key": "sample-object.xml"
    }
  ],
  "Quiet": false
}
```

------

## 使用適用於 Java 的 AWS 軟體開發套件
<a name="S3OutpostsDeleteObjectsJava"></a>

下列範例示範如何從 S3 on Outposts 儲存貯體中刪除單個物件或多個物件。

------
#### [ DeleteObject ]

下列 S3 on Outposts 範例使用適用於 Java 的開發套件，在儲存貯體中刪除物件。若要使用此範例，請為 Outpost 指定存取點 ARN，並為您要刪除的物件指定金鑰名稱。如需詳細資訊，請參閱 *Amazon Simple Storage Service API 參考*中的[DeleteObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html)。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.DeleteObjectRequest;

public class DeleteObject {
    public static void main(String[] args) {
        String accessPointArn = "*** access point ARN ***";
        String keyName = "*** key name ****";

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            s3Client.deleteObject(new DeleteObjectRequest(accessPointArn, keyName));
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

------
#### [ DeleteObjects ]

下列 S3 on Outposts 範例使用適用於 Java 的開發套件，在儲存貯體中上傳，然後刪除物件。若要使用此範例，請為 Outpost 指定存取點 ARN。如需詳細資訊，請參閱 *Amazon Simple Storage Service API 參考*中的 [DeleteObjects](https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html)。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion;
import com.amazonaws.services.s3.model.DeleteObjectsResult;

import java.util.ArrayList;

public class DeleteObjects {

    public static void main(String[] args) {
       String accessPointArn = "arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point";
        

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            // Upload three sample objects.
            ArrayList<KeyVersion> keys = new ArrayList<KeyVersion>();
            for (int i = 0; i < 3; i++) {
                String keyName = "delete object example " + i;
                s3Client.putObject(accessPointArn, keyName, "Object number " + i + " to be deleted.");
                keys.add(new KeyVersion(keyName));
            }
            System.out.println(keys.size() + " objects successfully created.");

            // Delete the sample objects.
            DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(accessPointArn)
                    .withKeys(keys)
                    .withQuiet(false);

            // Verify that the objects were deleted successfully.
            DeleteObjectsResult delObjRes = s3Client.deleteObjects(multiObjectDeleteRequest);
            int successfulDeletes = delObjRes.getDeletedObjects().size();
            System.out.println(successfulDeletes + " objects successfully deleted.");
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

------

# 使用 HeadBucket 判斷 S3 on Outposts 儲存貯體是否存在，並且您是否擁有存取許可
<a name="S3OutpostsHeadBucket"></a>

物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時，您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊，請參閱 [針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名](s3-outposts-access-points-alias.md)。

下列範例顯示 S3 on Outposts 存取點的 ARN 格式，其中包含 Outpost 所在區域的 AWS 區域 程式碼、 AWS 帳戶 ID、Outpost ID 和存取點名稱：

```
arn:aws:s3-outposts:region:account-id:outpost/outpost-id/accesspoint/accesspoint-name
```

如需 S3 on Outposts ARN 的詳細資訊，請參閱 [適用於 S3 on Outposts 的資源 ARN](S3OutpostsIAM.md#S3OutpostsARN)。

**注意**  
對於 Amazon S3 on Outposts，物件資料始終存放在 Outpost 上。當 AWS 安裝 Outpost 機架時，您的資料會保留在 Outpost 的本機，以符合資料備援需求。您的物件永遠不會離開您的 Outpost，也不會在 AWS 區域中。由於 AWS 管理主控台 是在 區域中託管，因此您無法使用 主控台來上傳或管理 Outpost 中的物件。不過，您可以使用 REST API、 AWS Command Line Interface (AWS CLI) 和 AWS SDKs 透過存取點上傳和管理物件。

下列 AWS Command Line Interface (AWS CLI) 和 適用於 Java 的 AWS SDK 範例示範如何使用 HeadBucket API 操作來判斷 Amazon S3 on Outposts 儲存貯體是否存在，以及您是否具有存取它的許可。如需詳細資訊，請參閱 *Amazon Simple Storage Service API 參考*中的 [HeadBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html)。

## 使用 AWS CLI
<a name="S3OutpostsHeadBucketCLI"></a>

下列 S3 on Outposts AWS CLI 範例使用 `head-bucket`命令來判斷儲存貯體是否存在，而且您具有存取儲存貯體的許可。若要執行此命令，請以您自己的資訊取代每個 `user input placeholder`。如需此命令的詳細資訊，請參閱 *AWS CLI 參考*中的 [head-bucket](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/head-bucket.html)。

```
aws s3api head-bucket --bucket arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point
```

## 使用適用於 Java 的 AWS 開發套件
<a name="S3OutpostsHeadBucketJava"></a>

下列 S3 on Outposts 範例顯示如何判斷儲存貯體是否存在，以及您是否有存取許可。若要使用此範例，請為 Outpost 指定存取點 ARN。如需詳細資訊，請參閱 *Amazon Simple Storage Service API 參考*中的 [HeadBucket](https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html)。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.HeadBucketRequest;

public class HeadBucket {
    public static void main(String[] args) {
        String accessPointArn = "*** access point ARN ***";

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            s3Client.headBucket(new HeadBucketRequest(accessPointArn));
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

# 使用適用於 Java 的開發套件執行和管理分段上傳
<a name="S3OutpostsMPU"></a>

使用 Amazon S3 on Outposts，您可以在 AWS Outposts 資源上建立 S3 儲存貯體，並為需要本機資料存取、本機資料處理和資料駐留的應用程式在內部部署存放和擷取物件。您可以透過 AWS 管理主控台、 AWS Command Line Interface (AWS CLI)、SDK 或 REST API 使用 S3 on Outposts。 AWS SDKs 如需詳細資訊，請參閱[什麼是 Amazon S3 on Outposts？](S3onOutposts.md) 

下列範例示範如何搭配 使用 S3 on Outposts 適用於 Java 的 AWS SDK ，以執行和管理分段上傳。

**Topics**
+ [在 S3 on Outposts 儲存貯體中執行物件的分段上傳](#S3OutpostsInitiateMultipartUploadJava)
+ [使用分段上傳在 S3 on Outposts 儲存貯體中複製大型物件](#S3OutpostsCopyPartJava)
+ [列出 S3 on Outposts 儲存貯體中物件的片段](#S3OutpostsListPartsJava)
+ [擷取 S3 on Outposts 儲存貯體中進行中的分段上傳清單](#S3OutpostsListMultipartUploadsJava)

## 在 S3 on Outposts 儲存貯體中執行物件的分段上傳
<a name="S3OutpostsInitiateMultipartUploadJava"></a>

下列 S3 on Outposts 範例使用適用於 Java 的開發套件，在 Outposts 儲存貯體啟動、上傳和完成物件的分段上傳。若要使用此範例，請以您自己的資訊取代每個 `user input placeholder`。如需詳細資訊，請參閱《Amazon Simple Storage Service 使用者指南》**中的[使用分段上傳來上傳物件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-upload-object.html)。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.*;

import java.util.ArrayList;
import java.util.List;

public class MultipartUploadCopy {
    public static void main(String[] args) {
        String accessPointArn = "*** Source access point ARN ***";
        String sourceObjectKey = "*** Source object key ***";
        String destObjectKey = "*** Target object key ***";

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            // Initiate the multipart upload.
            InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(accessPointArn, destObjectKey);
            InitiateMultipartUploadResult initResult = s3Client.initiateMultipartUpload(initRequest);

            // Get the object size to track the end of the copy operation.
            GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(accessPointArn, sourceObjectKey);
            ObjectMetadata metadataResult = s3Client.getObjectMetadata(metadataRequest);
            long objectSize = metadataResult.getContentLength();

            // Copy the object using 5 MB parts.
            long partSize = 5 * 1024 * 1024;
            long bytePosition = 0;
            int partNum = 1;
            List<CopyPartResult> copyResponses = new ArrayList<CopyPartResult>();
            while (bytePosition < objectSize) {
                // The last part might be smaller than partSize, so check to make sure
                // that lastByte isn't beyond the end of the object.
                long lastByte = Math.min(bytePosition + partSize - 1, objectSize - 1);

                // Copy this part.
                CopyPartRequest copyRequest = new CopyPartRequest()
                        .withSourceBucketName(accessPointArn)
                        .withSourceKey(sourceObjectKey)
                        .withDestinationBucketName(accessPointArn)
                        .withDestinationKey(destObjectKey)
                        .withUploadId(initResult.getUploadId())
                        .withFirstByte(bytePosition)
                        .withLastByte(lastByte)
                        .withPartNumber(partNum++);
                copyResponses.add(s3Client.copyPart(copyRequest));
                bytePosition += partSize;
            }

            // Complete the upload request to concatenate all uploaded parts and make the copied object available.
            CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest(
                    accessPointArn,
                    destObjectKey,
                    initResult.getUploadId(),
                    getETags(copyResponses));
            s3Client.completeMultipartUpload(completeRequest);
            System.out.println("Multipart copy complete.");
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process 
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client  
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }

    // This is a helper function to construct a list of ETags.
    private static List<PartETag> getETags(List<CopyPartResult> responses) {
        List<PartETag> etags = new ArrayList<PartETag>();
        for (CopyPartResult response : responses) {
            etags.add(new PartETag(response.getPartNumber(), response.getETag()));
        }
        return etags;
    }
```

## 使用分段上傳在 S3 on Outposts 儲存貯體中複製大型物件
<a name="S3OutpostsCopyPartJava"></a>

下列 S3 on Outposts 範例使用適用於 Java 的開發套件在儲存貯體中複製物件。若要使用此範例，請以您自己的資訊取代每個 `user input placeholder`。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.*;

import java.util.ArrayList;
import java.util.List;

public class MultipartUploadCopy {
    public static void main(String[] args) {
        String accessPointArn = "*** Source access point ARN ***";
        String sourceObjectKey = "*** Source object key ***";
        String destObjectKey = "*** Target object key ***";

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            // Initiate the multipart upload.
            InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(accessPointArn, destObjectKey);
            InitiateMultipartUploadResult initResult = s3Client.initiateMultipartUpload(initRequest);

            // Get the object size to track the end of the copy operation.
            GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(accessPointArn, sourceObjectKey);
            ObjectMetadata metadataResult = s3Client.getObjectMetadata(metadataRequest);
            long objectSize = metadataResult.getContentLength();

            // Copy the object using 5 MB parts.
            long partSize = 5 * 1024 * 1024;
            long bytePosition = 0;
            int partNum = 1;
            List<CopyPartResult> copyResponses = new ArrayList<CopyPartResult>();
            while (bytePosition < objectSize) {
                // The last part might be smaller than partSize, so check to make sure
                // that lastByte isn't beyond the end of the object.
                long lastByte = Math.min(bytePosition + partSize - 1, objectSize - 1);

                // Copy this part.
                CopyPartRequest copyRequest = new CopyPartRequest()
                        .withSourceBucketName(accessPointArn)
                        .withSourceKey(sourceObjectKey)
                        .withDestinationBucketName(accessPointArn)
                        .withDestinationKey(destObjectKey)
                        .withUploadId(initResult.getUploadId())
                        .withFirstByte(bytePosition)
                        .withLastByte(lastByte)
                        .withPartNumber(partNum++);
                copyResponses.add(s3Client.copyPart(copyRequest));
                bytePosition += partSize;
            }

            // Complete the upload request to concatenate all uploaded parts and make the copied object available.
            CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest(
                    accessPointArn,
                    destObjectKey,
                    initResult.getUploadId(),
                    getETags(copyResponses));
            s3Client.completeMultipartUpload(completeRequest);
            System.out.println("Multipart copy complete.");
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process 
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client  
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }

    // This is a helper function to construct a list of ETags.
    private static List<PartETag> getETags(List<CopyPartResult> responses) {
        List<PartETag> etags = new ArrayList<PartETag>();
        for (CopyPartResult response : responses) {
            etags.add(new PartETag(response.getPartNumber(), response.getETag()));
        }
        return etags;
    }
}
```

## 列出 S3 on Outposts 儲存貯體中物件的片段
<a name="S3OutpostsListPartsJava"></a>

下列 S3 on Outposts 範例使用適用於 Java 的開發套件，在儲存貯體中列出物件的片段。若要使用此範例，請以您自己的資訊取代每個 `user input placeholder`。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.*;

import java.util.List;

public class ListParts {
    public static void main(String[] args) {
        String accessPointArn = "*** access point ARN ***";
        String keyName = "*** Key name ***";
        String uploadId = "*** Upload ID ***";

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            ListPartsRequest listPartsRequest = new ListPartsRequest(accessPointArn, keyName, uploadId);
            PartListing partListing = s3Client.listParts(listPartsRequest);
            List<PartSummary> partSummaries = partListing.getParts();

            System.out.println(partSummaries.size() + " multipart upload parts");
            for (PartSummary p : partSummaries) {
                System.out.println("Upload part: Part number = \"" + p.getPartNumber() + "\", ETag = " + p.getETag());
            }

        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

## 擷取 S3 on Outposts 儲存貯體中進行中的分段上傳清單
<a name="S3OutpostsListMultipartUploadsJava"></a>

下列 S3 on Outposts 範例顯示如何使用適用於 Java 的開發套件，從 Outposts 儲存貯體擷取進行中的分段上傳清單。若要使用此範例，請以您自己的資訊取代每個 `user input placeholder`。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ListMultipartUploadsRequest;
import com.amazonaws.services.s3.model.MultipartUpload;
import com.amazonaws.services.s3.model.MultipartUploadListing;

import java.util.List;

public class ListMultipartUploads {
    public static void main(String[] args) {
                String accessPointArn = "*** access point ARN ***";

        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();

            // Retrieve a list of all in-progress multipart uploads.
            ListMultipartUploadsRequest allMultipartUploadsRequest = new ListMultipartUploadsRequest(accessPointArn);
            MultipartUploadListing multipartUploadListing = s3Client.listMultipartUploads(allMultipartUploadsRequest);
            List<MultipartUpload> uploads = multipartUploadListing.getMultipartUploads();

            // Display information about all in-progress multipart uploads.
            System.out.println(uploads.size() + " multipart upload(s) in progress.");
            for (MultipartUpload u : uploads) {
                System.out.println("Upload in progress: Key = \"" + u.getKey() + "\", id = " + u.getUploadId());
            }
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

# 使用適用於 S3 on OutOutposts 的預先簽章 URL
<a name="S3OutpostsPresignedURL"></a>

若要授予對存放在本機 Outpost 上物件的有限時間存取權限，而不會更新儲存貯體政策，您可以使用預先簽章 URL。使用預先簽章 URL，身為儲存貯體擁有者的您可以與虛擬私有雲端 (VPC) 中的個人共享物件，或授予他們上傳或刪除物件的能力。

當您使用 AWS SDKs或 AWS Command Line Interface (AWS CLI) 建立預先簽章的 URL 時，您可以將 URL 與特定動作建立關聯。您也可以選擇自訂到期時間 (最低 1 秒，最高 7 天) 來授予預先簽章 URL 有限時間的存取權。當您共用預先簽章 URL 時，VPC 中的個人可以執行嵌入 URL 中的動作，如同原始簽章使用者一樣。當 URL 到達到期時間時，該 URL 就會過期且再也無法運作。

## 限制預先簽章的 URL 功能
<a name="S3OutpostsPresignedUrlUploadObjectLimitCapabilities"></a>

預先簽章的 URL 的功能，受到建立它的使用者許可所限制。實質上，預先簽章的 URL 是一種承載符記，可為擁有這些網址的客戶授與存取權。因此，我們建議您妥善保護它們。

**AWS Signature 第 4 版 (SigV4)**  
若要在使用 AWS Signature 第 4 版 (SigV4) 驗證預先簽章的 URL 請求時強制執行特定行為，您可以在儲存貯體政策和存取點政策中使用條件金鑰。例如，您可以建立儲存貯體政策，使用 `s3-outposts:signatureAge` 條件來拒絕任何 `example-outpost-bucket` 儲存貯體中物件上的 Amazon S3 on Outposts 預先簽章 URL 請求 (如果簽章超過 10 分鐘)。若要使用此範例，請以您自己的資訊取代 *`user input placeholders`*。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "Deny a presigned URL request if the signature is more than 10 minutes old",
            "Effect": "Deny",
            "Principal": {"AWS":"444455556666"},
            "Action": "s3-outposts:*",
            "Resource": "arn:aws:s3-outposts:us-east-1:111122223333:outpost/op-01ac5d28a6a232904/bucket/example-outpost-bucket/object/*",
            "Condition": {
                "NumericGreaterThan": {"s3-outposts:signatureAge": 600000},
                "StringEquals": {"s3-outposts:authType": "REST-QUERY-STRING"}
            }
        }
    ]
}
```

------

如需取得可用來強制執行特定行為 (在使用第 4 版簽署程序驗證預先簽章的 URL 請求時) 的條件金鑰和其他政策範例清單，請參閱 [AWS Signature 第 4 版 (SigV4) 身分驗證特定政策金鑰](s3-outposts-bucket-policy-s3-sigv4-conditions.md)。

**網路路徑限制**  
如果您想要限制使用預先簽章 URL 和對特定網路路徑的所有 S3 on Outposts 存取權，您可以撰寫需要特定網路路徑的政策。若要對進行呼叫的 IAM 主體設定限制，您可以使用身分型 AWS Identity and Access Management (IAM) 政策 （例如使用者、群組或角色政策）。若要在 S3 on Outposts 資源上設定的限制，您可以使以資源型政策 (例如儲存貯體和存取點政策)。

IAM 主體的網路路徑限制需要這些憑證的使用者從指定的網路發出請求。儲存貯體或存取點上的限制要求所有對該資源的請求都來自指定網路。這些限制也適用於預先簽章的 URL 案例之外。

您使用的 IAM 全域條件取決於端點類型。如果您正在使用 S3 on Outposts 的公有端點，請使用 `aws:SourceIp`。如果您正在使用 S3 on Outposts 的 VPC 端點，請使用 `aws:SourceVpc` 或 `aws:SourceVpce`。

下列 IAM 政策陳述式要求委託人 AWS 只能從指定的網路範圍存取 。由於此政策聲明，所有存取均必須源自該範圍。這包含某人使用 S3 on Outposts 預先簽章 URL 的情況。若要使用此範例，請以您自己的資訊取代 *`user input placeholders`*。

```
{
    "Sid": "NetworkRestrictionForIAMPrincipal",
    "Effect": "Deny",
    "Action": "*",
    "Resource": "*",
    "Condition": {
        "NotIpAddressIfExists": {"aws:SourceIp": "IP-address-range"},
        "BoolIfExists": {"aws:ViaAWSService": "false"}
    }
}
```

如需使用 `aws:SourceIP` AWS 全域條件金鑰將對 S3 on Outposts 儲存貯體的存取限制在特定網路範圍的範例儲存貯體政策，請參閱 [使用 S3 on Outposts 設定 IAM](S3OutpostsIAM.md)。

## 誰可以建立預先簽章的 URL
<a name="S3Outpostswho-presigned-url"></a>

任何具備有效安全憑證的使用者，均可建立預先簽章的 URL。但為了讓 VPC 中的使用者能順利存取物件，預先簽章的 URL 必須由有權執行預先簽章的 URL 做為基礎之操作的人員來建立。

您可以使用下列憑證來建立預先簽章 URL：
+ **IAM 執行個體設定檔** - 有效期限最長 6 小時。
+ **AWS Security Token Service** - 以 AWS 帳戶 根使用者或 IAM 使用者憑證等永久憑證簽章時，有效期限最長 36 小時。
+ **IAM 使用者** – 當您使用 AWS Signature 第 4 版時，有效期最長為 7 天。

  若要建立有效期限最長 7 天的預先簽章 URL，請先將 IAM 使用者憑證 (存取金鑰和私密金鑰) 委派給您在使用的 SDK。然後，使用 AWS Signature 第 4 版產生預先簽章的 URL。

**注意**  
如果使用暫時字符建立了預先簽章的 URL，則 URL 會在字符過期時過期，即使您使用較晚的過期時間建立 URL 亦然。
由於預先簽章 URL 會將 S3 on Outposts 儲存貯體的存取權授予擁有 URL 的任何人，因此我們建議您妥善保護這些 URL。如需保護預先簽章的 URL 的詳細資訊，請參閱[限制預先簽章的 URL 功能](#S3OutpostsPresignedUrlUploadObjectLimitCapabilities)。

## S3 on Outposts 何時檢查預先簽章的 URL 中的到期日期和時間？
<a name="S3Outpostspresigned-url-when-checked"></a>

S3 on Outposts 會在發出 HTTP 請求時，檢查已簽署 URL 的到期日期和時間。例如，如果用戶端在到期前一刻才開始下載大型檔案，則即使在下載期間過期了，下載也會繼續。然而，如果連線中斷並且用戶端在到期時間過後嘗試重新啟動下載，則下載會失敗。

如需使用預先簽章 URL 來共享或上傳物件的詳細資訊，請參閱下列主題。

**Topics**
+ [限制預先簽章的 URL 功能](#S3OutpostsPresignedUrlUploadObjectLimitCapabilities)
+ [誰可以建立預先簽章的 URL](#S3Outpostswho-presigned-url)
+ [S3 on Outposts 何時檢查預先簽章的 URL 中的到期日期和時間？](#S3Outpostspresigned-url-when-checked)
+ [使用預先簽章的 URL 來共用物件](S3OutpostsShareObjectPresignedURL.md)
+ [產生預先簽章 URL 以將物件上傳至 S3 on Outposts 儲存貯體](S3OutpostsPresignedUrlUploadObject.md)

# 使用預先簽章的 URL 來共用物件
<a name="S3OutpostsShareObjectPresignedURL"></a>

若要授予對存放在本機 Outpost 上物件的有限時間存取權限，而不會更新儲存貯體政策，您可以使用預先簽章 URL。使用預先簽章 URL，身為儲存貯體擁有者的您可以與虛擬私有雲端 (VPC) 中的個人共享物件，或授予他們上傳或刪除物件的能力。

當您使用 AWS SDKs或 AWS Command Line Interface (AWS CLI) 建立預先簽章的 URL 時，您可以將 URL 與特定動作建立關聯。您也可以選擇自訂到期時間 (最低 1 秒，最高 7 天) 來授予預先簽章 URL 有限時間的存取權。當您共用預先簽章 URL 時，VPC 中的個人可以執行嵌入 URL 中的動作，如同原始簽章使用者一樣。當 URL 到達到期時間時，該 URL 就會過期且再也無法運作。



當您建立預先簽章 URL 時，必須提供安全憑證，然後指定下列項目：
+ 適用於 Amazon S3 on Outposts 儲存貯體的存取點 Amazon Resource Name (ARN)
+ 物件索引鍵
+ HTTP 方法 (`GET` 用於下載物件)
+ 過期日期和時間

預先簽章 URL 僅在指定的期間內有效。也就是說，您必須在到期日期和時間之前開始 URL 所允許的操作。您可以多次使用預先簽章 URL，直到到期日期和時間為止。如果使用暫時字符建立了預先簽章的 URL，那麼 URL 會在字符過期時過期，即使您使用較晚的過期時間建立 URL 亦然。

虛擬私有雲端 (VPC) 中可存取預先簽章 URL 的使用者可以存取物件。例如，若儲存貯體中有一段影片且儲存貯體與物件皆為私有，即可透過產生預先簽章的 URL 來與其他人分享這段影片。由於預先簽章 URL 會將 S3 on Outposts 儲存貯體的存取權授予擁有 URL 的任何人，因此我們建議您妥善保護這些 URL。如需有關保護預先簽署 URL 的詳細資訊，請參閱[限制預先簽章的 URL 功能](S3OutpostsPresignedURL.md#S3OutpostsPresignedUrlUploadObjectLimitCapabilities)。

任何具備有效安全憑證的使用者，均可建立預先簽章的 URL。然而，只有具備許可執行作為預先簽章 URL 基礎操作的人員，才能建立預先簽章 URL。如需詳細資訊，請參閱[誰可以建立預先簽章的 URL](S3OutpostsPresignedURL.md#S3Outpostswho-presigned-url)。

您可以使用 AWS SDK 與 AWS CLI來產生預先簽章 URL，以在 S3 on Outposts 儲存貯體中共享物件。如需詳細資訊，請參閱下列範例。

## 使用 AWS SDKs
<a name="S3OutpostsShareObjectPreSignedURLSDK"></a>

您可以使用 AWS SDKs 來產生可提供給其他人的預先簽章 URL，以便他們可以擷取物件。

**注意**  
當您使用 AWS SDKs產生預先簽章的 URL 時，預先簽章 URL 的過期時間上限為從建立時間起算 7 天。

------
#### [ Java ]

**Example**  
以下範例會產生預先簽章的 URL，您可以將其提供給其他人，讓他們可以從 S3 on Outposts 儲存貯體擷取物件。如需詳細資訊，請參閱[使用適用於 S3 on OutOutposts 的預先簽章 URL](S3OutpostsPresignedURL.md)。若要使用此範例，請以您自己的資訊取代 *`user input placeholders`*。  

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.HttpMethod;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;

import java.io.IOException;
import java.net.URL;
import java.time.Instant;

public class GeneratePresignedURL {

    public static void main(String[] args) throws IOException {
        Regions clientRegion = Regions.DEFAULT_REGION;
        String accessPointArn = "*** access point ARN ***";
        String objectKey = "*** object key ***";

        try {
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .withRegion(clientRegion)
                    .withCredentials(new ProfileCredentialsProvider())
                    .build();

            // Set the presigned URL to expire after one hour.
            java.util.Date expiration = new java.util.Date();
            long expTimeMillis = Instant.now().toEpochMilli();
            expTimeMillis += 1000 * 60 * 60;
            expiration.setTime(expTimeMillis);

            // Generate the presigned URL.
            System.out.println("Generating pre-signed URL.");
            GeneratePresignedUrlRequest generatePresignedUrlRequest =
                    new GeneratePresignedUrlRequest(accessPointArn, objectKey)
                            .withMethod(HttpMethod.GET)
                            .withExpiration(expiration);
            URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);

            System.out.println("Pre-Signed URL: " + url.toString());
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process 
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        }
    }
}
```

------
#### [ .NET ]

**Example**  
以下範例會產生預先簽章的 URL，您可以將其提供給其他人，讓他們可以從 S3 on Outposts 儲存貯體擷取物件。如需詳細資訊，請參閱[使用適用於 S3 on OutOutposts 的預先簽章 URL](S3OutpostsPresignedURL.md)。若要使用此範例，請以您自己的資訊取代 *`user input placeholders`*。  

```
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;

namespace Amazon.DocSamples.S3
{
    class GenPresignedURLTest
    {
        private const string accessPointArn = "*** access point ARN ***"; 
        private const string objectKey = "*** object key ***";
        // Specify how long the presigned URL lasts, in hours.
        private const double timeoutDuration = 12;
        // Specify your bucket Region (an example Region is shown).
        private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
        private static IAmazonS3 s3Client;

        public static void Main()
        {
            s3Client = new AmazonS3Client(bucketRegion);
            string urlString = GeneratePreSignedURL(timeoutDuration);
        }
        static string GeneratePreSignedURL(double duration)
        {
            string urlString = "";
            try
            {
                GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
                {
                    BucketName = accessPointArn,
                    Key = objectKey,
                    Expires = DateTime.UtcNow.AddHours(duration)
                };
                urlString = s3Client.GetPreSignedURL(request1);
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            return urlString;
        }
    }
}
```

------
#### [ Python ]

下列範例使用了 SDK for Python (Boto3) 來產生預先簽章的 URL 以共用物件。例如，使用 Boto3 用戶端和 `generate_presigned_url` 函數來產生允許您 `GET` 物件的預先簽章的 URL。

```
import boto3
    url = boto3.client('s3').generate_presigned_url(
    ClientMethod='get_object', 
    Params={'Bucket': 'ACCESS_POINT_ARN', 'Key': 'OBJECT_KEY'},
    ExpiresIn=3600)
```

如需有關使用 SDK for Python (Boto3) 產生預先簽章的 URL 的詳細資訊，請參閱《*適用於 Python (Boto) 的 AWS SDK API 參考*》中的「[Python](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.generate_presigned_url)」。

------

## 使用 AWS CLI
<a name="S3OutpostsShareObjectPresignedCLI"></a>

下列範例 AWS CLI 命令會為 S3 on Outposts 儲存貯體產生預先簽章的 URL。若要使用此範例，請以您自己的資訊取代 *`user input placeholders`*。

**注意**  
當您使用 AWS CLI 產生預先簽章的 URL 時，預先簽章的 URL 最長過期時間為建立後 7 天。

```
aws s3 presign s3://arn:aws:s3-outposts:us-east-1:111122223333:outpost/op-01ac5d28a6a232904/accesspoint/example-outpost-access-point/mydoc.txt --expires-in 604800
```

如需詳細資訊，請參閱《*AWS CLI 命令參考*》中的 [presign](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/presign.html)。

# 產生預先簽章 URL 以將物件上傳至 S3 on Outposts 儲存貯體
<a name="S3OutpostsPresignedUrlUploadObject"></a>

若要授予對存放在本機 Outpost 上物件的有限時間存取權限，而不會更新儲存貯體政策，您可以使用預先簽章 URL。使用預先簽章 URL，身為儲存貯體擁有者的您可以與虛擬私有雲端 (VPC) 中的個人共享物件，或授予他們上傳或刪除物件的能力。

當您使用 AWS SDKs或 AWS Command Line Interface (AWS CLI) 建立預先簽章的 URL 時，您可以將 URL 與特定動作建立關聯。您也可以選擇自訂到期時間 (最低 1 秒，最高 7 天) 來授予預先簽章 URL 有限時間的存取權。當您共用預先簽章 URL 時，VPC 中的個人可以執行嵌入 URL 中的動作，如同原始簽章使用者一樣。當 URL 到達到期時間時，該 URL 就會過期且再也無法運作。

當您建立預先簽章 URL 時，必須提供安全憑證，然後指定下列項目：
+ 適用於 Amazon S3 on Outposts 儲存貯體的存取點 Amazon Resource Name (ARN)
+ 物件索引鍵
+ HTTP 方法 (`PUT` 用於上傳物件)
+ 過期日期和時間

預先簽章 URL 僅在指定的期間內有效。也就是說，您必須在到期日期和時間之前開始 URL 所允許的操作。您可以多次使用預先簽章 URL，直到到期日期和時間為止。如果使用暫時字符建立了預先簽章的 URL，那麼 URL 會在字符過期時過期，即使您使用較晚的過期時間建立 URL 亦然。

如果預先簽章的 URL 所允許的動作包含多個步驟 (例如分段上傳)，則您必須在到期之前開始所有步驟。如果 S3 on Outposts 嘗試以過期 URL 開始步驟時，您會收到錯誤。

虛擬私有雲端 (VPC) 中可存取預先簽章 URL 的使用者可以上傳物件。例如，VPC 中具有可存取預先簽章 URL 的使用者可以將物件上傳到您的儲存貯體。由於預先簽章 URL 會將 S3 on Outposts 儲存貯體的存取權授予 VPC 中擁有預先簽章 URL 存取權的任何使用者，因此我們建議您妥善保護這些 URL。如需有關保護預先簽署 URL 的詳細資訊，請參閱[限制預先簽章的 URL 功能](S3OutpostsPresignedURL.md#S3OutpostsPresignedUrlUploadObjectLimitCapabilities)。

任何具備有效安全憑證的使用者，均可建立預先簽章的 URL。然而，只有具備許可執行作為預先簽章 URL 基礎操作的人員，才能建立預先簽章 URL。如需詳細資訊，請參閱[誰可以建立預先簽章的 URL](S3OutpostsPresignedURL.md#S3Outpostswho-presigned-url)。

## 使用 AWS SDKs為 S3 on Outposts 物件操作產生預先簽章的 URL
<a name="s3-outposts-presigned-urls-upload-examples"></a>

------
#### [ Java ]

**適用於 Java 2.x 的 SDK**  
此範例顯示如何產生可以於限定時間內用來將物件上傳至 S3 on Outposts 儲存貯體的預先簽章 URL。如需詳細資訊，請參閱[使用適用於 S3 on OutOutposts 的預先簽章 URL](S3OutpostsPresignedURL.md)。  

```
    public static void signBucket(S3Presigner presigner, String outpostAccessPointArn, String keyName) {

        try {
            PutObjectRequest objectRequest = PutObjectRequest.builder()
                    .bucket(accessPointArn)
                    .key(keyName)
                    .contentType("text/plain")
                    .build();

            PutObjectPresignRequest presignRequest = PutObjectPresignRequest.builder()
                    .signatureDuration(Duration.ofMinutes(10))
                    .putObjectRequest(objectRequest)
                    .build();

            PresignedPutObjectRequest presignedRequest = presigner.presignPutObject(presignRequest);


            String myURL = presignedRequest.url().toString();
            System.out.println("Presigned URL to upload a file to: " +myURL);
            System.out.println("Which HTTP method must be used when uploading a file: " +
                    presignedRequest.httpRequest().method());

            // Upload content to the S3 on Outposts bucket by using this URL.
            URL url = presignedRequest.url();

            // Create the connection and use it to upload the new object by using the presigned URL.
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type","text/plain");
            connection.setRequestMethod("PUT");
            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
            out.write("This text was uploaded as an object by using a presigned URL.");
            out.close();

            connection.getResponseCode();
            System.out.println("HTTP response code is " + connection.getResponseCode());

        } catch (S3Exception e) {
            e.getStackTrace();
        } catch (IOException e) {
            e.getStackTrace();
        }
    }
```

------
#### [ Python ]

**適用於 Python 的 SDK (Boto3)**  
此範例顯示如何產生可於限定時間內執行 S3 on Outposts 動作的預先簽章 URL。如需詳細資訊，請參閱[使用適用於 S3 on OutOutposts 的預先簽章 URL](S3OutpostsPresignedURL.md)。若要使用 URL 提出請求，請使用 `Requests` 套件。  

```
import argparse
import logging
import boto3
from botocore.exceptions import ClientError
import requests

logger = logging.getLogger(__name__)


def generate_presigned_url(s3_client, client_method, method_parameters, expires_in):
    """
    Generate a presigned S3 on Outposts URL that can be used to perform an action.

    :param s3_client: A Boto3 Amazon S3 client.
    :param client_method: The name of the client method that the URL performs.
    :param method_parameters: The parameters of the specified client method.
    :param expires_in: The number of seconds that the presigned URL is valid for.
    :return: The presigned URL.
    """
    try:
        url = s3_client.generate_presigned_url(
            ClientMethod=client_method,
            Params=method_parameters,
            ExpiresIn=expires_in
        )
        logger.info("Got presigned URL: %s", url)
    except ClientError:
        logger.exception(
            "Couldn't get a presigned URL for client method '%s'.", client_method)
        raise
    return url


def usage_demo():
    logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

    print('-'*88)
    print("Welcome to the Amazon S3 on Outposts presigned URL demo.")
    print('-'*88)

    parser = argparse.ArgumentParser()
    parser.add_argument('accessPointArn', help="The name of the S3 on Outposts access point ARN.")
    parser.add_argument(
        'key', help="For a GET operation, the key of the object in S3 on Outposts. For a "
                    "PUT operation, the name of a file to upload.")
    parser.add_argument(
        'action', choices=('get', 'put'), help="The action to perform.")
    args = parser.parse_args()

    s3_client = boto3.client('s3')
    client_action = 'get_object' if args.action == 'get' else 'put_object'
    url = generate_presigned_url(
        s3_client, client_action, {'Bucket': args.accessPointArn, 'Key': args.key}, 1000)

    print("Using the Requests package to send a request to the URL.")
    response = None
    if args.action == 'get':
        response = requests.get(url)
    elif args.action == 'put':
        print("Putting data to the URL.")
        try:
            with open(args.key, 'r') as object_file:
                object_text = object_file.read()
            response = requests.put(url, data=object_text)
        except FileNotFoundError:
            print(f"Couldn't find {args.key}. For a PUT operation, the key must be the "
                  f"name of a file that exists on your computer.")

    if response is not None:
        print("Got response:")
        print(f"Status: {response.status_code}")
        print(response.text)

    print('-'*88)


if __name__ == '__main__':
    usage_demo()
```

------

# 搭配使用 Amazon S3 on Outposts 和本機 Amazon EMR on Outposts
<a name="s3-outposts-emr"></a>

Amazon EMR 是一種受管叢集平台，可簡化在 上執行大數據架構，例如 Apache Hadoop和 Apache Spark， AWS 以處理和分析大量資料。透過使用這些架構和相關的開放原始碼專案，您可以處理用於分析用途和商業智慧工作負載的資料。Amazon EMR 也可協助您轉換大量資料，並將其移入和移出其他 AWS 資料存放區和資料庫，並支援 Amazon S3 on Outposts。如需 Amazon EMR 的詳細資訊，請參閱《Amazon EMR 管理指南》**中的 [Amazon EMR on Outposts](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-outposts.html)。

對於 Amazon S3 on Outposts，Amazon EMR 7.0.0 版已支援的 Apache Hadoop S3A 連接器。Amazon EMR 的早期版本不支援本機 S3 on Outposts，且不支援 EMR 檔案系統 (EMRFS)。

**支援的應用程式**  
搭配 Amazon S3 on Outposts 的 Amazon EMR 支援下列應用程式：
+ Hadoop
+ Spark
+ Hue
+ Hive
+ Sqoop
+ Pig
+ Hudi
+ Flink

如需詳細資訊，請參閱《[Amazon EMR 版本指南](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-release-components.html)》。

## 建立和設定 Amazon S3 on Outposts 儲存貯體
<a name="create-outposts-bucket"></a>

Amazon EMR 使用 適用於 Java 的 AWS SDK 搭配 Amazon S3 on Outposts 來存放輸入資料和輸出資料。您的 Amazon EMR 日誌檔案會儲存在您選擇的區域 Amazon S3 位置，而不會以本機方式儲存在 Outpost 上。如需詳細資訊，請參閱《Amazon EMR 管理指南》**中的 [Amazon EMR 日誌](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-manage-view-web-log-files.html)。

為了符合 Amazon S3 和 DNS 需求，S3 on Outposts 儲存貯體具有特定的命名約束與限制。如需詳細資訊，請參閱[建立 S3 on Outposts 儲存貯體](S3OutpostsCreateBucket.md)。

使用 Amazon EMR 7.0.0 版及更新版本時，您可以將 Amazon EMR 與 S3 on Outposts 和 S3A 檔案系統搭配使用。

**先決條件**  
**S3 on Outposts 許可** – 當您建立 Amazon EMR 執行個體描述檔時，您的角色必須包含 S3 on Outposts 的 AWS Identity and Access Management (IAM) 命名空間。S3 on Outposts 具有自己的命名空間 `s3-outposts*`。如需有關使用此命名空間的政策範例，請參閱[使用 S3 on Outposts 設定 IAM](S3OutpostsIAM.md)。

**S3A 連接器** – 若要設定 EMR 叢集，以從 Amazon S3 on Outposts 儲存貯體存取資料，您必須使用 Apache Hadoop S3A 連接器。若要使用該連接器，請確保您的所有 S3 URI 均使用 `s3a` 結構描述。如果未使用，您可以設定用於 EMR 叢集的檔案系統實作，以便搭配使用您的 S3 URI 與 S3A 連接器。

若要將檔案系統實作設定為使用 S3A 連接器，您可以使用 EMR 叢集的 `fs.file_scheme.impl` 和 `fs.AbstractFileSystem.file_scheme.impl` 組態屬性，其中 `file_scheme` 對應於您擁有的 S3 URI 類型。若要使用下列範例，請以您自己的資訊取代 *`user input placeholders`*。例如，若要變更使用 `s3` 結構描述之 S3 URI 的檔案系統實作，請指定下列叢集組態屬性：

```
1. [
2.   {
3. "Classification": "core-site",
4.     "Properties": {
5.     "fs.s3.impl": "org.apache.hadoop.fs.s3a.S3AFileSystem",
6.     "fs.AbstractFileSystem.s3.impl": "org.apache.hadoop.fs.s3a.S3A"
7.     }
8.   }
9. ]
```

若要使用 S3A，請將 `fs.file_scheme.impl` 組態屬性設定為 `org.apache.hadoop.fs.s3a.S3AFileSystem`，並將 `fs.AbstractFileSystem.file_scheme.impl` 屬性設定為 `org.apache.hadoop.fs.s3a.S3A`。

例如，如果您存取路徑 `s3a://bucket/...`，請將 `fs.s3a.impl` 屬性設定為 `org.apache.hadoop.fs.s3a.S3AFileSystem`，並將 `fs.AbstractFileSystem.s3a.impl` 屬性設定為 `org.apache.hadoop.fs.s3a.S3A`。

## 搭配使用 Amazon S3 on Outposts 和 Amazon EMR 的入門指引
<a name="getting-started-outposts"></a>

下列主題說明如何開始使用 Amazon EMR 搭配 Amazon S3 on Outposts。

**Topics**
+ [建立許可政策](#create-permission-policy)
+ [建立和設定叢集](#configure-cluster)
+ [組態概觀](#configurations-overview)
+ [考量事項](#considerations)

### 建立許可政策
<a name="create-permission-policy"></a>

在建立使用 Amazon S3 on Outposts 的 EMR 叢集之前，您必須先建立 IAM 政策以連接至該叢集的 Amazon EC2 執行個體設定檔。政策必須具有存取 S3 on Outposts 存取點 Amazon Resource Name (ARN) 的許可。如需有關為 S3 on Outposts 建立 IAM 政策的詳細資訊，請參閱[使用 S3 on Outposts 設定 IAM](S3OutpostsIAM.md)。

下列政策範例會示範如何授予所需的許可。建立政策後，將政策連接至用於建立 EMR 叢集的執行個體設定檔角色，如 [建立和設定叢集](#configure-cluster) 一節中所述。若要使用此範例，請以您自己的資訊取代 *`user input placeholders`*。

```
 1. {
 2. "Version":"2012-10-17",		 	 	  
 3.   "Statement": [
 4.         {
 5.   "Effect": "Allow",
 6.             "Resource": "arn:aws:s3-outposts:us-west-2:111122223333:outpost/op-01ac5d28a6a232904/accesspoint/access-point-name,
 7.             "Action": [
 8.                 "s3-outposts:*"
 9.             ]
10.         }
11.     ]
12.     
13.  }
```

### 建立和設定叢集
<a name="configure-cluster"></a>

若要建立使用 S3 on Outposts 執行 Spark 的叢集，請在主控台中完成下列步驟。

**建立使用 S3 on Outposts 執行 Spark 的叢集**

1. 請在 [https://console.aws.amazon.com/elasticmapreduce/](https://console.aws.amazon.com/elasticmapreduce/) 開啟 Amazon EMR 主控台。

1. 在左側導覽窗格中選擇**叢集**。

1. 選擇 **建立叢集**。

   

1. 針對 **Amazon EMR 版本**，請選擇 **emr-7.0.0** 或更新版本。

1. 針對應用程式套件，請選擇 **Spark 互動式**。然後選取您要包含在叢集上的任何其他支援應用程式。

1. 若要啟用 Amazon S3 on Outposts，請輸入您的組態設定。

**範例組態設定**  
若要使用下列範例組態設定，請以您自己的資訊取代 `user input placeholders`。

   ```
    1. [
    2.  {
    3.    "Classification": "core-site",
    4.    "Properties": {
    5.      "fs.s3a.bucket.DOC-EXAMPLE-BUCKET.accesspoint.arn": "arn:aws:s3-outposts:us-west-2:111122223333:outpost/op-01ac5d28a6a232904/accesspoint/access-point-name"
    6.      "fs.s3a.committer.name": "magic", 
    7.      "fs.s3a.select.enabled": "false"
    8.     }
    9.   },
   10.   {
   11.     "Classification": "hadoop-env",
   12.     "Configurations": [
   13.       {
   14.         "Classification": "export",
   15.         "Properties": {
   16.           "JAVA_HOME": "/usr/lib/jvm/java-11-amazon-corretto.x86_64" 
   17.           }
   18.        }
   19.      ],
   20.      "Properties": {}
   21.    },
   22.    {
   23.      "Classification": "spark-env",
   24.      "Configurations": [
   25.        {
   26.          "Classification": "export",
   27.          "Properties": {
   28.            "JAVA_HOME": "/usr/lib/jvm/java-11-amazon-corretto.x86_64"
   29.          }
   30.        }
   31.       ],
   32.       "Properties": {}
   33.      },
   34.      {
   35.       "Classification": "spark-defaults",
   36.       "Properties": {
   37.         "spark.executorEnv.JAVA_HOME": "/usr/lib/jvm/java-11-amazon-corretto.x86_64",
   38.         "spark.sql.sources.fastS3PartitionDiscovery.enabled": "false"
   39.       }
   40.      }
   41.   ]
   ```

1. 在**聯網**區段中，選擇 AWS Outposts 機架上的虛擬私有雲端 (VPC) 和子網路。如需 Outposts 上的 Amazon EMR 的詳細資訊，請參閱《Amazon EMR 管理指南》**內之 [AWS Outposts上的 EMR 叢集](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-outposts.html)。

1. 在**適用於 Amazon EMR 的 EC2 執行個體設定檔**區段中，選擇連接[您先前建立之許可政策](#create-permission-policy)的 IAM 角色。

1. 設定剩餘的叢集設定，然後選擇**建立叢集**。

### 組態概觀
<a name="configurations-overview"></a>

下表會說明 S3A 組態，以及當您設定使用 S3 on Outposts 搭配 Amazon EMR 的叢集時，要為其參數指定的值。


| 參數 | 預設值 | S3 on Outposts 的必要值 | 說明 | 
| --- | --- | --- | --- | 
|  `fs.s3a.aws.credentials.provider`  |  如果未指定，S3A 會尋找區域儲存貯體 (具有 Outposts 儲存貯體名稱) 中的 S3。  |  S3 on Outposts 儲存貯體的存取點 ARN  |  Amazon S3 on Outposts 支援僅限 虛擬私有雲端 (VPC) 的存取點來作為存取 Outpost 儲存貯體的唯一方法。  | 
|  `fs.s3a.committer.name`  | file |  `magic`  |  Magic Committer 是 S3 on Outposts 唯一支援的遞交程式。  | 
|  `fs.s3a.select.enabled`  |  `TRUE`  |  `FALSE`  | Outposts 上不支援 S3 Select。 | 
|  `JAVA_HOME`  |  `/usr/lib/jvm/java-8`  |  `/usr/lib/jvm/java-11-amazon-corretto.x86_64`  |  S3A 上的 S3 on Outposts 需要 Java 11 版。  | 

下表說明當您設定搭配 Amazon EMR 使用 S3 on Outposts 的叢集時，要為其參數指定的 Spark 組態和值。


| 參數 | 預設值 | S3 on Outposts 的必要值 | 說明 | 
| --- | --- | --- | --- | 
|  `spark.sql.sources.fastS3PartitionDiscovery.enabled`  |  `TRUE`  |  `FALSE`  |  S3 on Outposts 不支援快速分割區。  | 
|  `spark.executorEnv.JAVA_HOME`  |  `/usr/lib/jvm/java-8`  |  `/usr/lib/jvm/java-11-amazon-corretto.x86_64`  |  S3A 上的 S3 on Outposts 需要 Java 11 版。  | 

### 考量事項
<a name="considerations"></a>

當您將 Amazon EMR 與 S3 on Outposts 儲存貯體整合時，請考慮下列事項：
+ Amazon EMR 7.0.0 版及更新版本支援 Amazon S3 on Outposts。
+ 您需要 S3A 連接器才能將 S3 on Outposts 與 Amazon EMR 搭配使用。只有 S3A 具有與 S3 on Outposts 儲存貯體互動所需的功能。如需 S3A 連接器設定資訊，請參閱[先決條件](#s3a-outposts-prerequisites)。
+ Amazon S3 on Outposts 僅支援使用 Amazon S3 受管金鑰 (SSE-S3) 搭配 Amazon EMR 的伺服器端加密。如需詳細資訊，請參閱[S3 on Outposts 中的資料加密](s3-outposts-data-encryption.md)。
+ Amazon S3 on Outposts 不支援使用 S3A FileOutputCommitter 進行寫入。使用 S3 on Outposts 儲存貯體上的 S3A FileOutputCommitter 寫入會導致下列錯誤：InvalidStorageClass: The storage class you specified is not valid。
+ Amazon EMR Serverless 或 Amazon EMR on EKS 不支援 Amazon S3 on Outposts。
+ Amazon EMR 日誌會儲存在您選擇的區域 Amazon S3 位置，而不會以本機方式儲存在 S3 on Outposts 儲存貯體中。

# 授權與身分驗證快取
<a name="s3-outposts-auth-cache"></a>

S3 on Outposts 會安全地快取 Outposts 機架上的本機身分驗證和授權資料。快取會移除 AWS 區域 每個請求的父系往返。這可消除網路往返時造成的變異。透過 S3 on Outposts 中的身分驗證和授權快取，您可以體驗一致延遲表現 (不同與 Outposts 和 AWS 區域之間的連線延遲)。

當您提出 S3 on Outposts API 請求時，系統會安全地快取身分驗證和授權資料。然後，系統會使用快取資料來驗證後續的 S3 物件 API 請求。S3 on Outposts 只會在使用簽章版本 4A (SigV4A) 簽署請求時，快取身分驗證和授權資料。快取會以本機方式儲存在 S3 on Outposts 服務內的 Outposts 上。當您提出 S3 API 請求時，系統會以非同步方式重新整理快取。系統會將快取加密，而且不會將純文字密碼編譯金鑰儲存在 Outposts 上。

當 Outpost 連線到 AWS 區域時，快取的有效期最長為 10 分鐘。當您提出 S3 on Outposts API 請求時，系統會以非同步方式重新整理快取，以確保使用最新的政策。如果 Outpost 與 中斷連線 AWS 區域，快取的有效期最長為 12 小時。

## 設定授權和身分驗證快取
<a name="config-auth-cache"></a>

S3 on Outposts 會自動快取使用 SigV4A 演算法簽署之請求的身分驗證和授權資料。如需詳細資訊，請參閱*AWS Identity and Access Management 《 使用者指南*》中的[簽署 AWS API 請求](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-signing.html)。SigV4A 演算法可在最新版本的 AWS SDKs中使用。您可以透過 [AWS Common Runtime (CRT) 程式庫](https://docs.aws.amazon.com/sdkref/latest/guide/common-runtime.html)的相依性來取得該項目。

您需要使用最新版本的 AWS SDK，並安裝最新版本的 CRT。例如，您可以執行 `pip install awscrt` 來取得最新版本的 CRT (具有 Boto3)。

S3 on Outposts 不會快取使用 SigV4 演算法簽署之請求的身分驗證和授權資料。

## 驗證 SigV4A 簽署
<a name="validate-SigV4A"></a>

您可以使用 AWS CloudTrail 驗證請求是否已使用 SigV4A 簽署。如需為 S3 on Outposts 設定 CloudTrail 的詳細資訊，請參閱[使用 AWS CloudTrail 日誌監控 S3 on Outposts](S3OutpostsCloudtrail.md)。

設定 CloudTrail 之後，您可以在 CloudTrail 日誌的 `SignatureVersion` 欄位中驗證請求的簽署方式。使用 SigV4A 簽署的請求會將 `SignatureVersion` 設為 `AWS 4-ECDSA-P256-SHA256`。使用 SigV4 簽署的請求會將 `SignatureVersion` 設為 `AWS 4-HMAC-SHA256`。