Recupero di un oggetto da un bucket Amazon S3 su Outposts - Amazon S3 su Outposts

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Recupero di un oggetto da un bucket Amazon S3 su Outposts

Gli oggetti sono le entità fondamentali archiviate in Amazon S3 su Outposts. Ogni oggetto è contenuto in un bucket. È necessario utilizzare i punti di accesso per accedere a qualsiasi oggetto in un bucket Outpost. Quando specifichi il bucket per le operazioni di oggetto, utilizza il nome della risorsa Amazon (ARN) o l'alias del punto di accesso. Per ulteriori informazioni sugli alias del punto di accesso, consulta Utilizzo di un alias in stile bucket per il punto di accesso del bucket S3 su Outposts.

L'esempio seguente mostra il formato ARN per S3 sui punti di accesso Outposts, che include il Regione AWS codice per la regione in cui risiede l'Outpost, l'ID, l' Account AWS ID Outpost e il nome del punto di accesso:

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

Per ulteriori informazioni su S3 on ARNs Outposts, consulta. Risorsa ARNs per S3 su Outposts

Con Amazon S3 su Outposts, i dati degli oggetti vengono sempre archiviati nell'Outpost. Quando si AWS installa un rack Outpost, i dati rimangono locali rispetto a Outpost per soddisfare i requisiti di residenza dei dati. I tuoi oggetti non lasciano mai il tuo Outpost e non sono in una Regione AWS. Poiché AWS Management Console è ospitato in una regione, non puoi utilizzare la console per caricare o gestire oggetti in Outpost. Tuttavia, puoi utilizzare l'API REST, AWS Command Line Interface (AWS CLI) e caricare e AWS SDKs gestire gli oggetti tramite i tuoi punti di accesso.

Gli esempi seguenti illustrano come scaricare un oggetto utilizzando AWS Command Line Interface (AWS CLI) e AWS SDK per Java.

Nell'esempio seguente viene inserito un oggetto denominato sample-object.xml da un bucket S3 su Outposts (s3-outposts:GetObject) utilizzando AWS CLI. Per usare questo comando, sostituire ogni user input placeholder con le proprie informazioni. Per ulteriori informazioni su questo comando, consulta get-object nella Guida di riferimento a AWS CLI .

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

Nell'esempio S3 su Outposts seguente viene ottenuto un oggetto utilizzando SDK per Java. Per utilizzare questo comando, sostituisci user input placeholder con le tue informazioni. Per ulteriori informazioni, consulta GetObject in Amazon Simple Storage Service API Reference (Guida di riferimento per l'API di Amazon Simple Storage Service).

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(); } }