Snowball Edge 디바이스에서 S3 객체로 작업하기 - AWS Snowball Edge 개발자 가이드

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Snowball Edge 디바이스에서 S3 객체로 작업하기

이 섹션에서는 Amazon S3 compatible storage on Snow Family devices 디바이스에 있는 객체를 사용하여 수행할 수 있는 다양한 작업을 설명합니다.

Amazon S3 compatible storage on Snow Family devices 버킷에 객체 복사

다음 예시에서는 AWS CLI를 사용하기 위한 쓰기 권한이 있는 Amazon S3 compatible storage on Snow Family devices 버킷에 sample-object.xml 파일을 업로드합니다. 이 명령을 사용하려면 각각의 사용자 입력 자리 표시자를 사용자의 정보로 바꿉니다.

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

다음 Amazon S3 compatible storage on Snow Family devices 예시에서는 SDK for Java를 사용하여 한 객체를 동일한 버킷의 새 객체로 복사합니다. 이 명령을 사용하려면 각각의 사용자 입력 자리 표시자를 사용자의 정보로 바꿉니다.

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

버킷에서 객체 가져오기

다음 예시에서는 AWS CLI를 사용하여 Amazon S3 compatible storage on Snow Family devices 버킷에서 sample-object.xml 이름의 객체를 가져옵니다. SDK 명령은 s3-snow:GetObject입니다. 이 명령을 사용하려면 각각의 사용자 입력 자리 표시자를 사용자의 정보로 바꿉니다.

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

이 명령에 대한 자세한 내용은 AWS CLI Command Referenceget-object 섹션을 참조하세요.

다음 Amazon S3 compatible storage on Snow Family devices 예시에서는 SDK for Java를 사용하여 객체를 가져옵니다. 이 명령을 사용하려면 각각의 사용자 입력 자리 표시자를 사용자의 정보로 바꿉니다. 자세한 내용은 Amazon 심플 스토리지 서비스 API 참조를 참조하십시오 GetObject.

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

버킷의 객체 나열

다음 예시에서는 AWS CLI를 사용하여 Amazon S3 compatible storage on Snow Family devices 버킷을 나열합니다. SDK 명령은 s3-snow:ListObjectsV2입니다. 이 명령을 사용하려면 각각의 사용자 입력 자리 표시자를 사용자의 정보로 바꿉니다.

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

이 명령에 대한 자세한 내용은 AWS CLI 명령 참조의 list-objects-v 2를 참조하십시오.

다음 Amazon S3 compatible storage on Snow Family devices 예시에서는 SDK for Java를 사용하여 버킷 내 객체를 나열합니다. 이 명령을 사용하려면 각각의 사용자 입력 자리 표시자를 사용자의 정보로 바꿉니다.

이 예제에서는 ListObjects API 작업의 최신 버전인 ListObjectsV2를 사용합니다. 애플리케이션 개발 시 이 개정된 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 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(); } } }

버킷 내 객체 삭제

Amazon S3 compatible storage on Snow Family devices 버킷에서 객체를 하나 이상 삭제할 수 있습니다. 다음 예시에서는 AWS CLI를 사용하여 sample-object.xml 이름의 객체를 삭제합니다. 이 명령을 사용하려면 각각의 사용자 입력 자리 표시자를 사용자의 정보로 바꿉니다.

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

이 명령에 대한 자세한 내용은 AWS CLI Command Referencedelete-object 섹션을 참조하세요.

다음 Amazon S3 compatible storage on Snow Family devices 예시에서는 SDK for Java를 사용하여 버킷 내 객체를 삭제합니다. 이 예시를 사용하려면 삭제할 객체의 키 이름을 지정합니다. 자세한 내용은 Amazon 심플 스토리지 서비스 API 참조를 참조하십시오 DeleteObject.

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