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?

eden3
preguntada hace un año412 visualizaciones
1 Respuesta
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
respondido hace un año

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas