Documentation ¶
Overview ¶
Package lifecycle impelmments unmarshaling of AWS Autoscaling Group Lifecycle Hook event messages, and provides a function KeepAlive() that will keep an event in the Transition:Wait state until a function returns true.
See: https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTestEvent is returned for new Events if it is a test event. ErrTestEvent = errors.New("test event") // ErrUnknownTransition is returned for Transitions other than launching or terminating. ErrUnknownTransition = errors.New("unknown Transition type") // ErrUnmarshal is returned when a unmarshalled JSON string doesn't appear to be a lifecycle event. ErrUnmarshal = errors.New("data is not a lifecycle event message") // ErrExpired is returned when a lifecycle event should be expried according to its timeout and start timestamp. ErrExpired = errors.New("lifecycle event has expired") )
Functions ¶
func KeepAlive ¶
func KeepAlive(ctx context.Context, client autoscalingiface.AutoScalingAPI, e *Event, c func(context.Context, *Event) (bool, error)) error
KeepAlive keeps a lifecycle event in the Transition:Wait state as long as condition c returns false.
The condition is is only checked just before the lifecycle event is due to expire.
Types ¶
type Event ¶
type Event struct { // The AWS account ID. AccountID string `json:"AccountId"` // The name of the autoscaling group. AutoScalingGroupName string `json:"AutoScalingGroupName"` Event string `json:"Event"` // The ID of the EC2 instance. InstanceID string `json:"EC2InstanceId"` // A unique token for this event. Used to record lifecycle heartbeat. LifecycleActionToken string `json:"LifecycleActionToken"` // The global heartbeat timeout duration. // The maximum is 172800 seconds (48 hours) or 100 times the HeartbeatTimeout, whichever is smaller. GlobalHeartbeatTimeout time.Duration // The initial heartbeat timeout duration. HeartbeatTimeout time.Duration // The name of the lifecycle hook. LifecycleHookName string `json:"LifecycleHookName"` // Launching or terminating. LifecycleTransition Transition `json:"LifecycleTransition"` // The time the event started. Start time.Time `json:"Time"` // Number of times a heartbeat has been recorded for this event. HeartbeatCount int `json:"HeartbeatCount,omitempty"` }
Event represents an AWS Lifecycle Hook event.
func NewEventFromMsg ¶
func NewEventFromMsg(ctx context.Context, client autoscalingiface.AutoScalingAPI, data []byte) (*Event, error)
NewEventFromMsg creates a new event from a lifecycle message.
func (*Event) GlobalTimeout ¶
GlobalTimeout returns the time past which the lifecycle transition cannot be delayed. The maximum is 172800 seconds (48 hours) or 100 times the heartbeat timeout, whichever is smaller.
type Transition ¶
type Transition string
Transition is an enum representing the possible AWS Autoscaling Group transitions that can have a lifecycle hook.
const ( // TransitionLaunching represents an instance that is launching. TransitionLaunching Transition = "autoscaling:EC2_INSTANCE_LAUNCHING" // TransitionTerminating represents an instance that is terminating. TransitionTerminating Transition = "autoscaling:EC2_INSTANCE_TERMINATING" // TestEvent is sent by AWS on initial lifecycle hook creation. TestEvent = "autoscaling:TEST_NOTIFICATION" )
func (Transition) String ¶
func (lt Transition) String() string