Recupero di un oggetto da un bucket Amazon S3 su Outposts - Amazon Simple Storage Service

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.

Nell'esempio seguente viene illustrato il formato ARN per i punti di accesso S3 su Outposts, che include il codice Regione AWS per la Regione in cui si trova l'Outpost, l'ID Account AWS, l'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 sugli ARN S3 su Outposts, consulta Risorsa ARNs per S3 su Outposts.

Con Amazon S3 su Outposts, i dati degli oggetti vengono sempre archiviati nell'Outpost. Quando AWS installa un rack Outpost, i tuoi dati rimangono locali nel tuo 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. Dal momento che la AWS Management Console è ospitata nella regione, non puoi utilizzare la console per caricare o gestire oggetti nel tuo Outpost. Tuttavia, puoi utilizzare l'API REST, AWS Command Line Interface (AWS CLI) e gli SDK AWS per caricare e gestire gli oggetti tramite i punti di accesso.

Gli esempi seguenti illustrano come scaricare un oggetto utilizzando AWS Command Line Interface (AWS CLI) eAWS SDK for 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 nella Documentazione di riferimento delle 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(); } }