lifecycle

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2019 License: MIT Imports: 8 Imported by: 0

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

View Source
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

func (e *Event) GlobalTimeout() time.Time

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.

func (*Event) Timeout

func (e *Event) Timeout() time.Time

Timeout returns the time that the lifecycle event will expire.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL