Bekerja dengan objek S3 pada perangkat Snowball Edge - AWS Snowball Edge Panduan Pengembang

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Bekerja dengan objek S3 pada perangkat Snowball Edge

Bagian ini menjelaskan berbagai operasi yang dapat Anda lakukan dengan objek di penyimpanan yang kompatibel dengan Amazon S3 di perangkat perangkat Snow Family.

Salin objek ke penyimpanan yang kompatibel dengan Amazon S3 di ember perangkat Snow Family

Contoh berikut mengunggah file bernama sample-object.xml ke penyimpanan yang kompatibel dengan Amazon S3 di ember perangkat Snow Family yang memiliki izin menulis untuk menggunakan. AWS CLI Untuk menggunakan perintah ini, ganti setiap placeholder input pengguna dengan informasi Anda sendiri.

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

Penyimpanan kompatibel Amazon S3 berikut pada perangkat Snow Family misalnya menyalin objek ke objek baru di bucket yang sama menggunakan SDK for Java. Untuk menggunakan perintah ini, ganti setiap placeholder input pengguna dengan informasi Anda sendiri.

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

Dapatkan objek dari ember

Contoh berikut mendapat sebuah objek bernama sample-object.xml dari penyimpanan yang kompatibel dengan Amazon S3 di ember perangkat Snow Family menggunakan. AWS CLI SDKPerintahnya adalahs3-snow:GetObject. Untuk menggunakan perintah ini, ganti setiap placeholder input pengguna dengan informasi Anda sendiri.

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

Untuk informasi selengkapnya tentang perintah ini, lihat get-object di AWS CLI Command Reference.

Berikut Amazon S3 penyimpanan kompatibel pada perangkat Snow Family contoh mendapatkan objek menggunakan SDK untuk Java. Untuk menggunakan perintah ini, ganti setiap placeholder input pengguna dengan informasi Anda sendiri. Untuk informasi selengkapnya, lihat GetObjectdi APIReferensi Layanan Penyimpanan Sederhana Amazon.

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

Daftar objek dalam ember

Contoh berikut mencantumkan objek dalam penyimpanan yang kompatibel dengan Amazon S3 di bucket perangkat Snow Family menggunakan. AWS CLI SDKPerintahnya adalahs3-snow:ListObjectsV2. Untuk menggunakan perintah ini, ganti setiap placeholder input pengguna dengan informasi Anda sendiri.

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

Untuk informasi selengkapnya tentang perintah ini, lihat list-objects-v2 di Referensi AWS CLI Perintah.

Penyimpanan yang kompatibel dengan Amazon S3 berikut pada perangkat Snow Family mencantumkan objek dalam bucket menggunakan SDK for Java. Untuk menggunakan perintah ini, ganti setiap placeholder input pengguna dengan informasi Anda sendiri.

Contoh ini menggunakan ListObjectsV2, yang merupakan revisi terbaru dari ListObjects API operasi. Kami menyarankan Anda menggunakan API operasi revisi ini untuk pengembangan aplikasi. Untuk kompatibilitas mundur, Amazon S3 terus mendukung versi sebelumnya dari API operasi ini.

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

Hapus objek dalam ember

Anda dapat menghapus satu atau beberapa objek dari penyimpanan yang kompatibel dengan Amazon S3 di ember perangkat Keluarga Salju. Contoh berikut menghapus objek bernama sample-object.xml menggunakan AWS CLI. Untuk menggunakan perintah ini, ganti setiap placeholder input pengguna dengan informasi Anda sendiri.

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

Untuk informasi selengkapnya tentang perintah ini, lihat delete-object di AWS CLI Command Reference.

Contoh penyimpanan Amazon S3 yang kompatibel di perangkat Snow Family berikut menghapus objek dalam bucket menggunakan for Java. SDK Untuk menggunakan contoh ini, tentukan nama kunci untuk objek yang ingin Anda hapus. Untuk informasi selengkapnya, lihat DeleteObjectdi API Referensi Layanan Penyimpanan Sederhana Amazon.

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