aws

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package aws provides AWS client helpers for ssmx.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListManagedInstances

func ListManagedInstances(ctx context.Context, cfg aws.Config) (map[string]SSMInfo, error)

ListManagedInstances returns SSM's view of all managed instances.

func MergeSSMInfo

func MergeSSMInfo(instances []Instance, ssmInfo map[string]SSMInfo)

MergeSSMInfo enriches a slice of Instance values with SSM ping status and agent version from the SSM info map.

func NewConfig

func NewConfig(ctx context.Context, profile, region string) (aws.Config, error)

NewConfig builds an aws.Config honouring explicit profile and region overrides. Either argument may be empty to fall back to SDK defaults (AWS_PROFILE env var, ~/.aws/config, etc.).

func SendDocCommand added in v0.2.0

func SendDocCommand(ctx context.Context, cfg aws.Config, instanceID, docName string, params map[string]string, timeoutSecs int32) (string, error)

SendDocCommand sends an arbitrary SSM document command to a single instance. params values are automatically wrapped in string arrays as required by the SSM API. timeoutSecs of 0 uses SSM's default (3600s). Returns the CommandId. Use WaitForShellCommand to poll for completion.

func SendSSHPublicKey

func SendSSHPublicKey(ctx context.Context, cfg aws.Config, instanceID, az, osUser, pubKey string) error

SendSSHPublicKey pushes pubKey to instanceID for osUser via EC2 Instance Connect. The key is valid for 60 seconds — long enough for the SSH handshake. az is the instance's availability zone (e.g. "us-east-1a").

func SendShellCommand added in v0.2.0

func SendShellCommand(ctx context.Context, cfg aws.Config, instanceID string, commands []string, env map[string]string, timeoutSecs int32) (string, error)

SendShellCommand sends AWS-RunShellScript to instanceID and returns the SSM commandID. env entries are injected as shell exports prepended to commands. timeoutSecs of 0 uses SSM's default (3600s).

func StartInteractiveCommand

func StartInteractiveCommand(ctx context.Context, cfg aws.Config, instanceID, command string) (*ssm.StartSessionOutput, error)

StartInteractiveCommand starts an SSM session using AWS-StartInteractiveCommand, which runs command on the target instance and streams output back through the plugin.

func StartPortForwardingSession

func StartPortForwardingSession(ctx context.Context, cfg aws.Config, instanceID, localPort, remotePort string) (*ssm.StartSessionOutput, error)

StartPortForwardingSession opens a native SSM port forward from localPort on the client to remotePort on the instance (localhost).

func StartPortForwardingSessionToRemoteHost

func StartPortForwardingSessionToRemoteHost(ctx context.Context, cfg aws.Config, instanceID, localPort, remoteHost, remotePort string) (*ssm.StartSessionOutput, error)

StartPortForwardingSessionToRemoteHost opens a native SSM port forward from localPort on the client to remotePort on remoteHost (reachable from the instance).

func StartSSHSession

func StartSSHSession(ctx context.Context, cfg aws.Config, instanceID string) (*ssm.StartSessionOutput, error)

StartSSHSession opens an SSM session using AWS-StartSSHSession, which bridges the SSM data channel to the instance's SSH port.

func StartSession

func StartSession(ctx context.Context, cfg aws.Config, instanceID string) (*ssm.StartSessionOutput, error)

StartSession starts an SSM session on the target instance and returns the raw response needed by session-manager-plugin.

func WaitForShellCommand added in v0.2.0

func WaitForShellCommand(ctx context.Context, cfg aws.Config, instanceID, commandID string, progress io.Writer) (stdout, stderr string, exitCode int, err error)

WaitForShellCommand polls GetCommandInvocation until the command reaches a terminal state. Returns stdout, stderr, and exit code. On SSM-level errors (TimedOut, Cancelled) it returns a non-nil error. A non-zero exit code from the script itself is not an error — the caller decides whether to treat it as failure. If progress is non-nil, new stdout chunks are written to it incrementally as they arrive during polling.

Types

type ConfigError added in v0.2.0

type ConfigError struct {
	Kind    ConfigErrorKind
	Profile string // the --profile value that was passed, if any
	Err     error  // underlying SDK error
}

ConfigError is returned by NewConfig when credentials or configuration are unavailable. Kind allows callers to show targeted remediation messages.

func (*ConfigError) Error added in v0.2.0

func (e *ConfigError) Error() string

func (*ConfigError) Unwrap added in v0.2.0

func (e *ConfigError) Unwrap() error

type ConfigErrorKind added in v0.2.0

type ConfigErrorKind int

ConfigErrorKind classifies why AWS credential/config loading failed.

const (
	ConfigErrNoCredentials   ConfigErrorKind = iota // no credentials configured at all
	ConfigErrProfileNotFound                        // --profile name not in ~/.aws/config
	ConfigErrSSOExpired                             // SSO profile exists but session is expired
	ConfigErrGeneric                                // any other AWS config/auth error
)

ConfigErrorKind values classify why AWS credential/config loading failed.

type Instance

type Instance struct {
	InstanceID       string
	Name             string
	State            string
	PrivateIP        string
	PublicIP         string
	Platform         string
	SubnetID         string
	VPCID            string
	IAMProfileARN    string
	SSMStatus        string
	AgentVersion     string
	LastPingAt       string
	PlatformName     string // e.g. "Amazon Linux", "Ubuntu" — from SSM DescribeInstanceInformation
	AvailabilityZone string // e.g. "us-east-1a" — from EC2 Placement.AvailabilityZone
}

Instance is a normalised view of an EC2 instance used throughout ssmx.

func ListInstances

func ListInstances(ctx context.Context, cfg aws.Config, tagFilters []string) ([]Instance, error)

ListInstances returns all EC2 instances visible to the caller, optionally filtered by tag key=value pairs (e.g. ["env=prod", "role=web"]).

func ListInstancesByIDs added in v0.2.0

func ListInstancesByIDs(ctx context.Context, cfg aws.Config, ids []string) ([]Instance, error)

ListInstancesByIDs returns EC2 instances for the given instance IDs. Returns the same Instance shape as ListInstances; SSMStatus defaults to "unknown". Returns nil, nil when ids is empty.

type SSMInfo

type SSMInfo struct {
	InstanceID   string
	PingStatus   string
	AgentVersion string
	LastPingAt   string
	PlatformName string
}

SSMInfo holds the Systems Manager view of a managed instance.

Jump to

Keyboard shortcuts

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