如何使用 AWS CLI 获取包含给定字符串的 S3 存储桶的全名?

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

Terraform 使用名称前缀部署 S3 存储桶。

如何通过为 AWS CLI 命令提供名称前缀来获取 S3 存储桶的全名?

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

使用上面的 AWS CLI 命令并向 grep 命令提供名称 prefix/string/identifier 我们可以获得所需的输出。

输出:

admin-passwords202104262231251212001

您可以使用 AWS 命令​​的组合来列出所有存储桶并从该命令的输出中 grep string/identifier。由于所有存储桶名称都是唯一的,因此它应该很容易工作。例如-

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