本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
在 Snowball Edge 上删除 Amazon S3 兼容存储空间中的存储桶中的对象
您可以从 Snowball Edge 存储段上与 Amazon S3 兼容的存储空间中删除一个或多个对象。以下示例sample-object.xml
使用删除名为的对象 Amazon CLI。要使用此命令,请将每个用户输入占位符替换为您自己的信息。
aws s3api delete-object --bucket
sample-bucket
--keykey
--endpoint-urls3api-endpoint-ip
--profileyour-profile
有关此命令的更多信息,请参阅《Amazon CLI 命令参考》中的 delete-object
以下 Snowball Edge 上与 Amazon S3 兼容的存储示例使用适用于 Java 的 SDK 删除存储桶中的对象。要使用此示例,请指定您想要删除的对象的密钥名称。有关更多信息,请参阅DeleteObject《亚马逊简单存储服务 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.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(); } } }