暖池活动类型和模式 - Amazon EC2 Auto Scaling
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

暖池活动类型和模式

注意

Amazon EC2 Auto Scaling 支持 Amazon EventBridge 中的多种预定义模式。这简化了事件模式的创建方式。您可以选择表单上的字段值,然后 EventBridge 将为您生成模式。目前,对于具有暖池的自动扩缩组发出的任何事件,Amazon EC2 Auto Scaling 不支持预定义模式。您必须以 JSON 对象的形式输入模式。这一部分和 为暖池事件创建 EventBridge 规则 主题演示例了如何使用事件模式来选择事件并将其发送到目标。

将生命周期挂钩添加到自动扩缩组时,事件会在实例变为等待状态时发送到 EventBridge。

生命周期挂钩有两种主要事件类型:

  • EC2 Instance-launch Lifecycle Action

  • EC2 Instance-terminate Lifecycle Action

要创建 EventBridge 规则来筛选由具有温池的自动扩缩组发出的特定事件,请包含事件的 detail 部分的 OriginDestination 字段。包含 OriginDestination 字段的事件仅可由具有暖池的自动扩缩组发出。

它可以是以下 OriginDestination 值之一:

EC2 | AutoScalingGroup | WarmPool

示例 事件

这一部分列出了实例变为等待状态时将发送到 EventBridge 的事件。尽最大努力发出事件。

示例 1:Amazon EC2 Auto Scaling 将一个新实例添加到暖池

在此示例事件中,新实例的状态在其被添加到暖池时更改为 Warmed:Pending:Wait。其原因在于横向扩展事件的生命周期挂钩。

{ "version": "0", "id": "12345678-1234-1234-1234-123456789012", "detail-type": "EC2 Instance-launch Lifecycle Action", "source": "aws.autoscaling", "account": "123456789012", "time": "2021-01-13T00:12:37.214Z", "region": "us-west-2", "resources": [ "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:042cba90-ad2f-431c-9b4d-6d9055bcc9fb:autoScalingGroupName/my-asg" ], "detail": { "LifecycleActionToken": "71514b9d-6a40-4b26-8523-05e7eEXAMPLE", "AutoScalingGroupName": "my-asg", "LifecycleHookName": "my-launch-lifecycle-hook", "EC2InstanceId": "i-1234567890abcdef0", "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING", "NotificationMetadata": "additional-info", "Origin": "EC2", "Destination": "WarmPool" } }

示例 2:Amazon EC2 Auto Scaling 将一个实例添加到自动扩缩组

在此示例事件中,暖池中实例的状态在其被添加到自动扩缩组时更改为 Pending:Wait。其原因在于横向扩展事件的生命周期挂钩。

{ "version": "0", "id": "12345678-1234-1234-1234-123456789012", "detail-type": "EC2 Instance-launch Lifecycle Action", "source": "aws.autoscaling", "account": "123456789012", "time": "2021-01-19T00:35:52.359Z", "region": "us-west-2", "resources": [ "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:042cba90-ad2f-431c-9b4d-6d9055bcc9fb:autoScalingGroupName/my-asg" ], "detail": { "LifecycleActionToken": "19cc4d4a-e450-4d1c-b448-0de67EXAMPLE", "AutoScalingGroupName": "my-asg", "LifecycleHookName": "my-launch-lifecycle-hook", "EC2InstanceId": "i-1234567890abcdef0", "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING", "NotificationMetadata": "additional-info", "Origin": "WarmPool", "Destination": "AutoScalingGroup" } }

示例 3:Amazon EC2 Auto Scaling 将一个新实例添加到自动扩缩组

在此示例事件中,新实例(而非暖池中的实例)的状态在其被添加到自动扩缩组时更改为 Pending:Wait。其原因在于横向扩展事件的生命周期挂钩。

{ "version": "0", "id": "12345678-1234-1234-1234-123456789012", "detail-type": "EC2 Instance-launch Lifecycle Action", "source": "aws.autoscaling", "account": "123456789012", "time": "2021-02-01T17:18:06.082Z", "region": "us-west-2", "resources": [ "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:042cba90-ad2f-431c-9b4d-6d9055bcc9fb:autoScalingGroupName/my-asg" ], "detail": { "LifecycleActionToken": "87654321-4321-4321-4321-21098EXAMPLE", "AutoScalingGroupName": "my-asg", "LifecycleHookName": "my-launch-lifecycle-hook", "EC2InstanceId": "i-1234567890abcdef0", "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING", "NotificationMetadata": "additional-info", "Origin": "EC2", "Destination": "AutoScalingGroup" } }

示例 4:Amazon EC2 Auto Scaling 将一个实例退回暖池

在此示例事件中,实例的状态在其被退回到暖池时更改为 Warmed:Pending:Wait。其原因在于横向缩减事件的生命周期挂钩。

{ "version": "0", "id": "12345678-1234-1234-1234-123456789012", "detail-type": "EC2 Instance-terminate Lifecycle Action", "source": "aws.autoscaling", "account": "123456789012", "time": "2022-03-28T00:12:37.214Z", "region": "us-west-2", "resources": [ "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:042cba90-ad2f-431c-9b4d-6d9055bcc9fb:autoScalingGroupName/my-asg" ], "detail": { "LifecycleActionToken": "42694b3d-4b70-6a62-8523-09a1eEXAMPLE", "AutoScalingGroupName": "my-asg", "LifecycleHookName": "my-termination-lifecycle-hook", "EC2InstanceId": "i-1234567890abcdef0", "LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING", "NotificationMetadata": "additional-info", "Origin": "AutoScalingGroup", "Destination": "WarmPool" } }

示例事件模式

前一节提供 Amazon EC2 Auto Scaling 发出的示例事件。

EventBridge 事件模式与它们匹配的事件具有相同的结构。模式引用了您要匹配的字段,并提供您所查找的值。

事件中的下列字段构成规则中定义的事件模式以调用操作:

"source": "aws.autoscaling"

识别来自 Amazon EC2 Auto Scaling 的事件。

"detail-type": "EC2 Instance-launch Lifecycle Action"

识别事件类型。

"Origin": "EC2"

标识实例的来源。

"Destination": "WarmPool"

标识实例的目标位置。

使用以下示例事件模式捕获与进入暖池的实例相关联的所有事件。

{ "source": [ "aws.autoscaling" ], "detail-type": [ "EC2 Instance-launch Lifecycle Action" ], "detail": { "Origin": [ "EC2" ], "Destination": [ "WarmPool" ] } }

使用以下示例事件模式捕获与因横向扩展事件而离开暖池的实例有关的所有事件。

{ "source": [ "aws.autoscaling" ], "detail-type": [ "EC2 Instance-launch Lifecycle Action" ], "detail": { "Origin": [ "WarmPool" ], "Destination": [ "AutoScalingGroup" ] } }

使用以下示例事件模式捕获与直接启动到 Auto Scaling 组的实例相关联的所有事件。

{ "source": [ "aws.autoscaling" ], "detail-type": [ "EC2 Instance-launch Lifecycle Action" ], "detail": { "Origin": [ "EC2" ], "Destination": [ "AutoScalingGroup" ] } }

使用以下示例事件模式捕获与在横向缩减时退回暖池的实例有关的所有事件。

{ "source": [ "aws.autoscaling" ], "detail-type": [ "EC2 Instance-terminate Lifecycle Action" ], "detail": { "Origin": [ "AutoScalingGroup" ], "Destination": [ "WarmPool" ] } }

使用以下示例事件模式捕获与 EC2 Instance-launch Lifecycle Action 关联的所有相关事件,无论起点或目的地如何。

{ "source": [ "aws.autoscaling" ], "detail-type": [ "EC2 Instance-launch Lifecycle Action" ] }