get `last export` from s3 inventory configuration in cli

0

In the AWS S3 UI there's a link to the Last export from the inventory configuration and I'm wondering if there's a way to access the last exported inventory configuration in cli?

Ultimately, I need a script that gets only the most recent inventory configuration csv file. Is there any way to do this without going through Athena or manually sorting by date?

1 Antwort
0

Hello there,

To get the latest inventory report from your bucket, you can run any of the below commands for the AWS CLI.

  1. aws s3api list-objects --bucket $BUCKET --query 'Contents[?LastModified>2023-02-09].{ Key: Key, LastModified: LastModified }' --output text | sort -k2 | tail -1
  2. aws s3api list-objects-v2 --bucket $BUCKET --query 'sort_by(Contents, &LastModified)[-1].Key' --output=text

The first command will display the path of the latest file and also the date and time it was created in the bucket.

Once the file has been located and listed, you can then download it to your local machine with the below command

aws s3 cp s3://bucket-name/filename.txt ./

Hope this helps.

AWS
MB
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen