Deleting logs file in Amazon s3 bucket according to created date

0 votes

0

How to delete the log files in Amazon s3 according to date.? I have log files in a logs folder folder inside my bucket.

  string sdate = datetime.ToString("yyyy-MM-dd");
  string key = "logs/" + sdate + "*" ;
  AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client();

   DeleteObjectRequest delRequest = new DeleteObjectRequest()
  .WithBucketName(S3_Bucket_Name)
  .WithKey(key);

   DeleteObjectResponse res = s3Client.DeleteObject(delRequest);

I tried this but doesn't seem to work. I can delete individual files if I put the whole name in the key. But I want to delete all the log files created for a particular date

Feb 17, 2022 in AWS by Rahul
• 2,120 points
1,746 views

1 answer to this question.

0 votes
You can use S3's Object Lifecycle feature especially Object Expiration to delete all objects under a given prefix and over a given age. It's not instantaneous but it beats having to make pyramid individual requests. To delete everything just make the age small.
answered Feb 17, 2022 by anonymous

Related Questions In AWS

0 votes
0 answers
0 votes
1 answer

How to copy .csv file from Amazon S3 bucket?

Boto3 is the library to use for ...READ MORE

answered Jul 6, 2018 in AWS by Priyaj
• 58,020 points
2,119 views
0 votes
1 answer

How to download the latest file in a S3 bucket using AWS CLI?

You can use the below command $ aws ...READ MORE

answered Sep 6, 2018 in AWS by Archana
• 4,170 points
19,883 views
+1 vote
2 answers

How to read a csv file stored in Amazon S3 using csv.DictReader

The code would be something like this: import ...READ MORE

answered Oct 25, 2018 in AWS by Archana
• 5,640 points
54,452 views
0 votes
0 answers

I want to get file name from key in S3 bucket wanted to read single file from list of file present in bucket

1 <class 'boto.s3.key.Key'> <Key: numbers-email, staging/Procured_Numbers_Status/procured_numbers_status_2019-05-15:06:09:04.csv> I ...READ MORE

May 15, 2019 in AWS by anonymous
6,970 views
0 votes
1 answer

How much will it cost to read from an S3 bucket in the same region but on different account

There will be no data transfer cost ...READ MORE

answered Feb 17, 2022 in AWS by anonymous
3,168 views
0 votes
1 answer

How to use AWS S3 REST API ListObjects(v2) with multiple parent/child bucket directories?

Here you have to use the ListObjectsV2 ...READ MORE

answered Feb 15, 2022 in AWS by anonymous
1,323 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP