Utilizzo di oggetti S3 su un dispositivo Snowball Edge - AWS Snowball Edge Guida per gli sviluppatori

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à.

Utilizzo di oggetti S3 su un dispositivo Snowball Edge

Questa sezione descrive varie operazioni che puoi eseguire con oggetti sullo storage compatibile con Amazon S3 sui dispositivi della famiglia Snow.

Copia un oggetto in un bucket di storage compatibile con Amazon S3 sui dispositivi Snow Family

L'esempio seguente carica un file denominato sample-object.xml in un bucket di storage compatibile con Amazon S3 su dispositivi Snow Family per il quale disponi delle autorizzazioni di scrittura per l'utilizzo di. AWS CLI Per utilizzare questo comando, sostituisci ogni segnaposto di input dell'utente con le tue informazioni.

aws s3api put-object --bucket sample-bucket --key sample-object.xml --body sample-object.xml --profile your-profile --endpoint-url s3api-endpoint-ip

Il seguente esempio di storage compatibile con Amazon S3 su dispositivi Snow Family copia un oggetto in un nuovo oggetto nello stesso bucket utilizzando l'SDK for Java. Per utilizzare questo comando, sostituisci ogni segnaposto di input dell'utente con le tue informazioni.

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; add : import java.io.IOException; public class CopyObject { public static void main(String[] args) { String bucketName = "*** Bucket name ***"; 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(sourceKey, destinationKey); s3Client.copyObject(copyObjectRequest); CopyObjectRequest copyObjectRequest = CopyObjectRequest.builder() .sourceKey(sourceKey) .destinationKey(destKey) .build(); } 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(); } } }

Recupera un oggetto da un secchio

L'esempio seguente ottiene un oggetto denominato sample-object.xml da uno storage compatibile con Amazon S3 su dispositivi Snow Family utilizzando il. AWS CLI Il comando SDK è. s3-snow:GetObject Per utilizzare questo comando, sostituisci ogni segnaposto di input dell'utente con le tue informazioni.

aws s3api get-object --bucket sample-bucket --key sample-object.xml --profile your-profile --endpoint-url s3api-endpoint-ip

Per ulteriori informazioni su questo comando, vedere get-object nel Command Reference.AWS CLI

Il seguente esempio di storage compatibile con Amazon S3 su dispositivi Snow Family ottiene un oggetto utilizzando l'SDK for Java. Per utilizzare questo comando, sostituisci ogni segnaposto di input dell'utente con le tue informazioni. Per ulteriori informazioni, consulta il riferimento GetObjectall'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 bucketName = "*** Bucket name ***"; 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(); GetObjectRequest getObjectRequest = GetObjectRequest.builder() .bucket(bucketName) .key(key) .build()); s3Client.getObject(getObjectRequest); } 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(); } }

Elenca gli oggetti in un bucket

L'esempio seguente elenca gli oggetti in un bucket di storage compatibile con Amazon S3 su dispositivi Snow Family utilizzando il. AWS CLI Il comando SDK è. s3-snow:ListObjectsV2 Per utilizzare questo comando, sostituisci ogni segnaposto di input dell'utente con le tue informazioni.

aws s3api list-objects-v2 --bucket sample-bucket --profile your-profile --endpoint-url s3api-endpoint-ip

Per ulteriori informazioni su questo comando, vedere list-objects-v2 nella Guida ai AWS CLI comandi.

Il seguente esempio di storage compatibile con Amazon S3 sui dispositivi Snow Family elenca gli oggetti in un bucket utilizzando l'SDK for Java. Per utilizzare questo comando, sostituisci ogni segnaposto di input dell'utente con le tue informazioni.

Questo esempio utilizza ListObjectsV2, che è l'ultima revisione del funzionamento dell'API. ListObjects Si consiglia di utilizzare questa operazione API rivista per lo sviluppo di applicazioni. Per la compatibilità con le versioni precedenti, Amazon S3 continua a supportare la versione precedente di questa operazione 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 bucketName = "*** Bucket 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(); System.out.println("Listing objects"); // maxKeys is set to 2 to demonstrate the use of // ListObjectsV2Result.getNextContinuationToken() ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(bucketName).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(); } } }

Eliminare oggetti in un bucket

Puoi eliminare uno o più oggetti da un bucket di storage compatibile con Amazon S3 sui dispositivi Snow Family. L'esempio seguente elimina un oggetto denominato sample-object.xml utilizzando il. AWS CLI Per utilizzare questo comando, sostituite ogni segnaposto di input dell'utente con le vostre informazioni.

aws s3api delete-object --bucket sample-bucket --key key --profile your-profile --endpoint-url s3api-endpoint-ip

Per ulteriori informazioni su questo comando, vedete delete-object nel Command Reference.AWS CLI

Il seguente esempio di storage compatibile con Amazon S3 sui dispositivi Snow Family elimina un oggetto in un bucket utilizzando l'SDK for Java. Per utilizzare questo esempio, specifica il nome della chiave per l'oggetto che desideri eliminare. Per ulteriori informazioni, consulta il riferimento DeleteObjectall'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.DeleteObjectRequest; public class DeleteObject { public static void main(String[] args) { String bucketName = "*** Bucket name ***"; 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(); DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder() .bucket(bucketName) .key(keyName) .build())); s3Client.deleteObject(deleteObjectRequest); } 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(); } } }