ec2metadata

package
Version: v1.38.60 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: Apache-2.0 Imports: 20 Imported by: 2,438

Documentation

Overview

Package ec2metadata provides the client for making API calls to the EC2 Metadata service.

This package's client can be disabled completely by setting the environment variable "AWS_EC2_METADATA_DISABLED=true". This environment variable set to true instructs the SDK to disable the EC2 Metadata client. The client cannot be used while the environment variable is set to true, (case insensitive).

The endpoint of the EC2 IMDS client can be configured via the environment variable, AWS_EC2_METADATA_SERVICE_ENDPOINT when creating the client with a Session. See aws/session#Options.EC2IMDSEndpoint for more details.

Index

Constants

View Source
const (
	// ServiceName is the name of the service.
	ServiceName = "ec2metadata"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EC2IAMInfo added in v1.1.15

type EC2IAMInfo struct {
	Code               string
	LastUpdated        time.Time
	InstanceProfileArn string
	InstanceProfileID  string
}

An EC2IAMInfo provides the shape for unmarshaling an IAM info from the metadata API

type EC2InstanceIdentityDocument added in v1.1.12

type EC2InstanceIdentityDocument struct {
	DevpayProductCodes      []string  `json:"devpayProductCodes"`
	MarketplaceProductCodes []string  `json:"marketplaceProductCodes"`
	AvailabilityZone        string    `json:"availabilityZone"`
	PrivateIP               string    `json:"privateIp"`
	Version                 string    `json:"version"`
	Region                  string    `json:"region"`
	InstanceID              string    `json:"instanceId"`
	BillingProducts         []string  `json:"billingProducts"`
	InstanceType            string    `json:"instanceType"`
	AccountID               string    `json:"accountId"`
	PendingTime             time.Time `json:"pendingTime"`
	ImageID                 string    `json:"imageId"`
	KernelID                string    `json:"kernelId"`
	RamdiskID               string    `json:"ramdiskId"`
	Architecture            string    `json:"architecture"`
}

An EC2InstanceIdentityDocument provides the shape for unmarshaling an instance identity document

type EC2Metadata added in v0.10.0

type EC2Metadata struct {
	*client.Client
}

A EC2Metadata is an EC2 Metadata service Client.

func New

func New(p client.ConfigProvider, cfgs ...*aws.Config) *EC2Metadata

New creates a new instance of the EC2Metadata client with a session. This client is safe to use across multiple goroutines.

Example:

// Create a EC2Metadata client from just a session.
svc := ec2metadata.New(mySession)

// Create a EC2Metadata client with additional configuration
svc := ec2metadata.New(mySession, aws.NewConfig().WithLogLevel(aws.LogDebugHTTPBody))

func NewClient added in v0.10.0

func NewClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion string, opts ...func(*client.Client)) *EC2Metadata

NewClient returns a new EC2Metadata client. Should be used to create a client when not using a session. Generally using just New with a session is preferred.

Will remove the URL path from the endpoint provided to ensure the EC2 IMDS client is able to communicate with the EC2 IMDS API.

If an unmodified HTTP client is provided from the stdlib default, or no client the EC2RoleProvider's EC2Metadata HTTP client's timeout will be shortened. To disable this set Config.EC2MetadataDisableTimeoutOverride to false. Enabled by default.

func (*EC2Metadata) Available added in v0.10.0

func (c *EC2Metadata) Available() bool

Available returns if the application has access to the EC2 Metadata service. Can be used to determine if application is running within an EC2 Instance and the metadata service is available.

func (*EC2Metadata) AvailableWithContext added in v1.30.3

func (c *EC2Metadata) AvailableWithContext(ctx aws.Context) bool

AvailableWithContext returns if the application has access to the EC2 Metadata service. Can be used to determine if application is running within an EC2 Instance and the metadata service is available.

func (*EC2Metadata) GetDynamicData added in v1.1.12

func (c *EC2Metadata) GetDynamicData(p string) (string, error)

GetDynamicData uses the path provided to request information from the EC2 instance metadata service for dynamic data. The content will be returned as a string, or error if the request failed.

func (*EC2Metadata) GetDynamicDataWithContext added in v1.30.3

func (c *EC2Metadata) GetDynamicDataWithContext(ctx aws.Context, p string) (string, error)

GetDynamicDataWithContext uses the path provided to request information from the EC2 instance metadata service for dynamic data. The content will be returned as a string, or error if the request failed.

func (*EC2Metadata) GetInstanceIdentityDocument added in v1.1.12

func (c *EC2Metadata) GetInstanceIdentityDocument() (EC2InstanceIdentityDocument, error)

GetInstanceIdentityDocument retrieves an identity document describing an instance. Error is returned if the request fails or is unable to parse the response.

func (*EC2Metadata) GetInstanceIdentityDocumentWithContext added in v1.30.3

func (c *EC2Metadata) GetInstanceIdentityDocumentWithContext(ctx aws.Context) (EC2InstanceIdentityDocument, error)

GetInstanceIdentityDocumentWithContext retrieves an identity document describing an instance. Error is returned if the request fails or is unable to parse the response.

func (*EC2Metadata) GetMetadata added in v0.10.0

func (c *EC2Metadata) GetMetadata(p string) (string, error)

GetMetadata uses the path provided to request information from the EC2 instance metadata service. The content will be returned as a string, or error if the request failed.

func (*EC2Metadata) GetMetadataWithContext added in v1.30.3

func (c *EC2Metadata) GetMetadataWithContext(ctx aws.Context, p string) (string, error)

GetMetadataWithContext uses the path provided to request information from the EC2 instance metadata service. The content will be returned as a string, or error if the request failed.

func (*EC2Metadata) GetUserData added in v1.4.15

func (c *EC2Metadata) GetUserData() (string, error)

GetUserData returns the userdata that was configured for the service. If there is no user-data setup for the EC2 instance a "NotFoundError" error code will be returned.

func (*EC2Metadata) GetUserDataWithContext added in v1.30.3

func (c *EC2Metadata) GetUserDataWithContext(ctx aws.Context) (string, error)

GetUserDataWithContext returns the userdata that was configured for the service. If there is no user-data setup for the EC2 instance a "NotFoundError" error code will be returned.

func (*EC2Metadata) IAMInfo added in v1.1.15

func (c *EC2Metadata) IAMInfo() (EC2IAMInfo, error)

IAMInfo retrieves IAM info from the metadata API

func (*EC2Metadata) IAMInfoWithContext added in v1.30.3

func (c *EC2Metadata) IAMInfoWithContext(ctx aws.Context) (EC2IAMInfo, error)

IAMInfoWithContext retrieves IAM info from the metadata API

func (*EC2Metadata) Region added in v0.10.0

func (c *EC2Metadata) Region() (string, error)

Region returns the region the instance is running in.

func (*EC2Metadata) RegionWithContext added in v1.30.3

func (c *EC2Metadata) RegionWithContext(ctx aws.Context) (string, error)

RegionWithContext returns the region the instance is running in.

Jump to

Keyboard shortcuts

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