我有一个 cloudformation 堆栈创建多个 EC2。是否有 CLI 命令可以描述特定 cloudformation 堆栈的实例?
您可以使用以下命令获取作为 CloudFormation 部署的一部分部署的实例 ID:
$ STACK_NAME=myteststack
$ aws cloudformation describe-stack-resources --stack-name "$STACK_NAME" --query 'StackResources[?ResourceType==`AWS::EC2::Instance`].PhysicalResourceId' --output text
i-0033781a7765d0b05 i-0963426e25b95e1e3
然后您可以将其提供给
describe-instances
:
$ aws cloudformation describe-stack-resources --stack-name "$STACK_NAME" --query 'StackResources[?ResourceType==`AWS::EC2::Instance`].PhysicalResourceId' --output text | tr '\t' '\n' | xargs -I {} aws ec2 describe-instances --instance-id {}
...