DeleteObjectNonVersionedBucketTest1.cs - AWS Code Sample

DeleteObjectNonVersionedBucketTest1.cs

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 using Amazon; using Amazon.S3; using Amazon.S3.Model; using System; using System.Threading.Tasks; namespace Amazon.DocSamples.S3 { class DeleteObjectNonVersionedBucketTest { private const string bucketName = "*** bucket name ***"; private const string keyName = "*** object key ***"; // Specify your bucket region (an example region is shown). private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2; private static IAmazonS3 client; public static void Main() { client = new AmazonS3Client(bucketRegion); DeleteObjectNonVersionedBucketAsync().Wait(); } private static async Task DeleteObjectNonVersionedBucketAsync() { try { var deleteObjectRequest = new DeleteObjectRequest { BucketName = bucketName, Key = keyName }; Console.WriteLine("Deleting an object"); await client.DeleteObjectAsync(deleteObjectRequest); } catch (AmazonS3Exception e) { Console.WriteLine("Error encountered on server. Message:'{0}' when deleting an object", e.Message); } catch (Exception e) { Console.WriteLine("Unknown encountered on server. Message:'{0}' when deleting an object", e.Message); } } } }