从 EC2 服务中的 Auto Scale 获取实例 ID 列表
Getting the list of Instance IDs from Auto Scale in EC2 service
有没有办法在 SQS 消息中发送配置为由 EC2 的 Auto Scale 服务启动的 Spawned "scaled" 实例列表?
如果您想在扩展事件期间了解 ec2 实例的实例 ID,您可以使用 SQS 设置生命周期挂钩。
Receive Notification Using Amazon SQS
You can use Amazon SQS to set up a notification target to receive notifications when a lifecycle action occurs.
To set up notifications using Amazon SQS
Create the target using Amazon SQS. For more information, see Getting Started with Amazon SQS in the Amazon Simple Queue Service Developer Guide. Note the ARN of the target.
Create an IAM role to grant Auto Scaling permission to access your notification target, using the steps in Creating a Role to Delegate Permissions to an AWS Service in the IAM User Guide. When prompted to select a role type, select AWS Service Roles, AutoScaling Notification Access. Note the ARN of the role. For example, arn:aws:iam::123456789012:role/my-notification-role.
When Auto Scaling responds to a scale out or scale in event, it puts the instance in a wait state. While the instance is in a wait state, Auto Scaling publishes a message to the notification target.
示例消息:
Service: AWS Auto Scaling
Time: 2016-09-30T20:42:11.305Z
RequestId: 18b2ec17-3e9b-4c15-8024-ff2e8ce8786a
LifecycleActionToken: 71514b9d-6a40-4b26-8523-05e7ee35fa40
AccountId: 123456789012
AutoScalingGroupName: my-asg
LifecycleHookName: my-hook
EC2InstanceId: i-0598c7d356eba48d7
LifecycleTransition: autoscaling:EC2_INSTANCE_LAUNCHING
NotificationMetadata: null
然后添加生命周期钩子
您可以使用 put-lifecycle-hook 命令创建生命周期挂钩。
要对扩展执行操作,请使用以下命令:
aws autoscaling put-lifecycle-hook --lifecycle-hook-name my-hook --auto-scaling-group-name my-asg --lifecycle-transition autoscaling:EC2_INSTANCE_LAUNCHING --notification-target-arn arn:aws:sns:us-west-2:123456789012:my-sqs --role-arn arn:aws:iam::123456789012:role/my-notification-role
http://docs.aws.amazon.com/autoscaling/latest/userguide/lifecycle-hooks.html#adding-lifecycle-hooks
http://docs.aws.amazon.com/cli/latest/reference/autoscaling/put-lifecycle-hook.html
有没有办法在 SQS 消息中发送配置为由 EC2 的 Auto Scale 服务启动的 Spawned "scaled" 实例列表?
如果您想在扩展事件期间了解 ec2 实例的实例 ID,您可以使用 SQS 设置生命周期挂钩。
Receive Notification Using Amazon SQS
You can use Amazon SQS to set up a notification target to receive notifications when a lifecycle action occurs.
To set up notifications using Amazon SQS
Create the target using Amazon SQS. For more information, see Getting Started with Amazon SQS in the Amazon Simple Queue Service Developer Guide. Note the ARN of the target.
Create an IAM role to grant Auto Scaling permission to access your notification target, using the steps in Creating a Role to Delegate Permissions to an AWS Service in the IAM User Guide. When prompted to select a role type, select AWS Service Roles, AutoScaling Notification Access. Note the ARN of the role. For example, arn:aws:iam::123456789012:role/my-notification-role.
When Auto Scaling responds to a scale out or scale in event, it puts the instance in a wait state. While the instance is in a wait state, Auto Scaling publishes a message to the notification target.
示例消息:
Service: AWS Auto Scaling
Time: 2016-09-30T20:42:11.305Z
RequestId: 18b2ec17-3e9b-4c15-8024-ff2e8ce8786a
LifecycleActionToken: 71514b9d-6a40-4b26-8523-05e7ee35fa40
AccountId: 123456789012
AutoScalingGroupName: my-asg
LifecycleHookName: my-hook
EC2InstanceId: i-0598c7d356eba48d7
LifecycleTransition: autoscaling:EC2_INSTANCE_LAUNCHING
NotificationMetadata: null
然后添加生命周期钩子
您可以使用 put-lifecycle-hook 命令创建生命周期挂钩。
要对扩展执行操作,请使用以下命令:
aws autoscaling put-lifecycle-hook --lifecycle-hook-name my-hook --auto-scaling-group-name my-asg --lifecycle-transition autoscaling:EC2_INSTANCE_LAUNCHING --notification-target-arn arn:aws:sns:us-west-2:123456789012:my-sqs --role-arn arn:aws:iam::123456789012:role/my-notification-role
http://docs.aws.amazon.com/autoscaling/latest/userguide/lifecycle-hooks.html#adding-lifecycle-hooks
http://docs.aws.amazon.com/cli/latest/reference/autoscaling/put-lifecycle-hook.html