简体   繁体   中英

How do I get the full name of an S3 bucket which contains a given string using AWS CLI?

Terraform deploys an S3 bucket using a name prefix.

How do I get the full name of an S3 bucket by providing name prefix to the AWS CLI command?

aws s3api list-buckets --query 'Buckets[*].[Name]' --output text | grep "admin-passwords"

Using the above AWS CLI command and providing the name prefix/string/identifier to the grep command we can achieve the desired output.

Output:

admin-passwords202104262231251212001

You can use a combination of AWS command to list all the buckets and grep your string/identifier from the output of that command. Since all the buckets names are unique, it should work easily. For example -

aws s3 ls | grep "my-bucket-identifier"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM