ssmclient

package
v0.0.0-...-f8a80ba Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResizeSleepInterval = time.Millisecond * 500
)

Variables

View Source
var (
	// ErrInvalidTargetFormat is the error returned if the target format doesn't match the expected format
	// required by the resolver.
	ErrInvalidTargetFormat = errors.New("invalid target format")
	// ErrNoInstanceFound is the error returned if a resolver was unable to find an instance.
	ErrNoInstanceFound = errors.New("no instances returned from lookup")
)

Functions

func PortForwardingSession

func PortForwardingSession(cfg aws.Config, opts *PortForwardingInput) error

PortForwardingSession starts a port forwarding session using the PortForwardingInput parameters to configure the session. The client.ConfigProvider parameter will be used to call the AWS SSM StartSession API, which is used as part of establishing the websocket communication channel.

func ResolveTarget

func ResolveTarget(target string, cfg aws.Config) (string, error)

ResolveTarget attempts to find the instance ID of the target using a pre-defined resolution order. The first check will see if the target is already in the format of an EC2 instance ID. Next, if the cfg parameter is not nil, checking by EC2 instance tags or private IPv4 IP address is performed. Finally, resolving by DNS TXT record will be attempted.

func ResolveTargetChain

func ResolveTargetChain(target string, resolvers ...TargetResolver) (inst string, err error)

ResolveTargetChain attempts to find the instance ID of the target using the provided list of TargetResolvers. The first check will always be to see if the target is already in the format of an EC2 instance ID before moving on to the resolution logic of the provided TargetResolvers. If a resolver returns an error, the next resolver in the chain is checked. If all resolvers fail to find an instance ID an error is returned.

func SSHSession

func SSHSession(cfg aws.Config, opts *PortForwardingInput) error

SSHSession starts a specialized port forwarding session to allow SSH connectivity to the target instance over the SSM session. It listens for data from Stdin and sends output to Stdout. Like a port forwarding session, use a PortForwardingInput type to configure the session properties. Any LocalPort information is ignored, and if no RemotePort is specified, the default SSH port (22) will be used. The client.ConfigProvider parameter is used to call the AWS SSM StartSession API, which is used as part of establishing the websocket communication channel.

func ShellSession

func ShellSession(cfg aws.Config, target string, initCmd ...io.Reader) error

ShellSession starts a shell session with the instance specified in the target parameter. The client.ConfigProvider parameter will be used to call the AWS SSM StartSession API, which is used as part of establishing the websocket communication channel. A vararg slice of io.Readers can be provided to send data to the instance before handing control of the terminal to the user.

func ShellSessionV2

func ShellSessionV2(cfg aws.Config, target string, r io.Reader, w io.Writer, initCmd ...io.Reader) error

Types

type DNSResolver

type DNSResolver bool

* DNS Resolver attempts to find an instance using a DNS TXT record lookup. The DNS record is expected * to resolve to the EC2 instance ID associated with the DNS name. If the DNS record is not found, or if * there is nothing which looks like an EC2 instance ID in the record data, and error is returned.

func NewDNSResolver

func NewDNSResolver() *DNSResolver

NewDNSResolver is a TargetResolver which knows how to find an EC2 instance using DNS TXT record lookups.

func (*DNSResolver) Resolve

func (r *DNSResolver) Resolve(target string) (string, error)

type EC2Resolver

type EC2Resolver struct {
	// contains filtered or unexported fields
}

* EC2 Resolver calls the EC2 DescribeInstances API with a provided filter, which will return at most 1 * instance ID. If more than 1 instance matches the filter, the 1st instance ID in the list is returned.

func (*EC2Resolver) Resolve

func (r *EC2Resolver) Resolve(filter ...types.Filter) (string, error)

type IPResolver

type IPResolver struct {
	*EC2Resolver
}

* IP Resolver attempts to find an instance by its private or public IPv4 address using the EC2 API. * If the target doesn't look like an IPv4 address, a DNS lookup is tried. If neither of those produce * an IPv4 address, or the EC2 instance lookup fails to find an instance, an error is returned. At most, * 1 instance ID is returned; if more than 1 match is found, only the 1st element of the instances list * is returned. The nature of the AWS EC2 API will not guarantee ordering of the instances list.

func NewIPResolver

func NewIPResolver(cfg aws.Config) *IPResolver

NewIPResolver is a TargetResolver which knows how to find an EC2 instance using the private IPv4 address.

func (*IPResolver) Resolve

func (r *IPResolver) Resolve(target string) (string, error)

type PortForwardingInput

type PortForwardingInput struct {
	Target     string
	RemotePort int
	LocalPort  int
}

PortForwardingInput configures the port forwarding session parameters. Target is the EC2 instance ID to establish the session with. RemotePort is the port on the EC2 instance to connect to. LocalPort is the port on the local host to listen to. If not provided, a random port will be used.

type TagResolver

type TagResolver struct {
	*EC2Resolver
}

* Tag Resolver attempts to find an instance using instance tags. The expected format is tag_key:tag_value * (ex. hostname:web0). If the target to resolve doesn't look like a a colon-separated tag key:value pair, * or no instance is found, an error is returned. At most, 1 instance ID is returned; if more than 1 match * is found, only the 1st element of the instances list is returned. The nature of the AWS EC2 API will not * guarantee ordering of the instances list.

func NewTagResolver

func NewTagResolver(cfg aws.Config) *TagResolver

NewTagResolver is a TargetResolver which knows how to find an EC2 instance using tags.

func (*TagResolver) Resolve

func (r *TagResolver) Resolve(target string) (string, error)

type TargetResolver

type TargetResolver interface {
	Resolve(string) (string, error)
}

TargetResolver is the interface specification for something which knows how to resolve and EC2 instance identifier.

Jump to

Keyboard shortcuts

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