Documentation
¶
Overview ¶
Package awsinstancetag helps retrieving data from AWS instance metadata.
This is oriented toward software configuration (not infrastructure checking or monitoring). Secrets must NOT be stored in metadata (not safe). Some methods require tags to be explicitly allowed in the instance options.
See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html and https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html
This is opinionated for a specific use:
- Using https://ec2.amazonaws.com/?Action=DescribeInstances (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html)
- Using "http://169.254.169.254/latest/dynamic/instance-identity/document"
- NOT using "http://169.254.169.254/latest/user-data"
- NOT using "http://169.254.169.254/latest/meta-data"
It returns a custom error for common catch errors (Like "not on AWS" or "instance metadata not configured")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
func Load( ctx context.Context, ims AWSInstanceMetadataService, ec2s func(region string) (AWSEC2Service, error), ) ( *imds.GetInstanceIdentityDocumentOutput, *ec2.DescribeInstancesOutput, error, )
Load gets instances metadata.
First, it gets the InstanceIdentityDocument for the InstanceID + region. Then it creates a new session with the region and finally it calls DescribeInstances.
It uses CreateEC2sDefault() if ec2s is null.
Types ¶
type AWSEC2Service ¶
type AWSEC2Service interface {
DescribeInstances(input *ec2.DescribeInstancesInput) (*ec2.DescribeInstancesOutput, error)
}
func CreateEC2sDefault ¶
func CreateEC2sDefault(region string) (AWSEC2Service, error)
type AWSInstanceMetadataService ¶
type AWSInstanceMetadataService interface {
GetInstanceIdentityDocument(ctx context.Context, params *imds.GetInstanceIdentityDocumentInput, optFns ...func(*imds.Options)) (*imds.GetInstanceIdentityDocumentOutput, error)
}
type ForbiddenInstanceTagReadingError ¶
type ForbiddenInstanceTagReadingError struct {
Err error
}
see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html
func (ForbiddenInstanceTagReadingError) Error ¶
func (e ForbiddenInstanceTagReadingError) Error() string
func (ForbiddenInstanceTagReadingError) Unwrap ¶
func (e ForbiddenInstanceTagReadingError) Unwrap() error
type UnreachableInstanceIdentityDocumentError ¶
type UnreachableInstanceIdentityDocumentError struct {
Err error
}
func (UnreachableInstanceIdentityDocumentError) Error ¶
func (e UnreachableInstanceIdentityDocumentError) Error() string
func (UnreachableInstanceIdentityDocumentError) Unwrap ¶
func (e UnreachableInstanceIdentityDocumentError) Unwrap() error