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
已提问 1 年前411 查看次数
1 回答
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
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则