Amazon web services 如何在所有地区获取最新的Amazon Linux映像?

Amazon web services 如何在所有地区获取最新的Amazon Linux映像?,amazon-web-services,amazon-ec2,aws-cli,Amazon Web Services,Amazon Ec2,Aws Cli,我编写了一个脚本,使用AWS CLI获取最新的Amazon Linux映像。当我运行这个脚本时,我会在默认区域eu-west-1中获得最新的Amazon Linux映像。如何修改代码以获取所有区域中的最新图像。将--region添加到CLI命令中 像这样的 #!/bin/bash aws ec2 describe-images \ --owners self amazon \ --filters "Name=root-device-type,Values=ebs" \ --query 'Imag

我编写了一个脚本,使用AWS CLI获取最新的Amazon Linux映像。当我运行这个脚本时,我会在默认区域eu-west-1中获得最新的Amazon Linux映像。如何修改代码以获取所有区域中的最新图像。

--region
添加到CLI命令中

像这样的

#!/bin/bash
aws ec2 describe-images \
--owners self amazon \
--filters "Name=root-device-type,Values=ebs" \
--query 'Images[*].[ImageId,CreationDate]' \
| sort -k2 -r \
| head -n1
您可以使用
aws ec2 descripe regions
命令获取区域列表并对每个区域运行查询,而不是硬编码区域名称

执行aws ec2 descripe regions--query“regions[].{Name:RegionName}”--输出文本,输出为

aws ec2 describe-images --region eu-west-2 \
--owners self amazon \
--filters "Name=root-device-type,Values=ebs" \
--query 'Images[*].[ImageId,CreationDate]' \
| sort -k2 -r \
| head -n1

现在循环遍历每个区域并执行
descripe images
CLI命令。

谢谢,但我在给出多个区域时遇到了一个错误,例如:--region eu-west-1,us-east-1“Invalid endpoint”您不能给出多个区域。您必须在每个区域执行该命令。谢谢!我试试看
ap-south-1
eu-west-3
eu-west-2
eu-west-1
ap-northeast-3
ap-northeast-2
ap-northeast-1
sa-east-1
ca-central-1
ap-southeast-1
ap-southeast-2
eu-central-1
us-east-1
us-east-2
us-west-1
us-west-2