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回答
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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ