Documentation
¶
Overview ¶
Package aws provides AWS client helpers for ssmx.
Index ¶
- func ListManagedInstances(ctx context.Context, cfg aws.Config) (map[string]SSMInfo, error)
- func MergeSSMInfo(instances []Instance, ssmInfo map[string]SSMInfo)
- func NewConfig(ctx context.Context, profile, region string) (aws.Config, error)
- func SendDocCommand(ctx context.Context, cfg aws.Config, instanceID, docName string, ...) (string, error)
- func SendSSHPublicKey(ctx context.Context, cfg aws.Config, instanceID, az, osUser, pubKey string) error
- func SendShellCommand(ctx context.Context, cfg aws.Config, instanceID string, commands []string, ...) (string, error)
- func StartInteractiveCommand(ctx context.Context, cfg aws.Config, instanceID, command string) (*ssm.StartSessionOutput, error)
- func StartPortForwardingSession(ctx context.Context, cfg aws.Config, instanceID, localPort, remotePort string) (*ssm.StartSessionOutput, error)
- func StartPortForwardingSessionToRemoteHost(ctx context.Context, cfg aws.Config, ...) (*ssm.StartSessionOutput, error)
- func StartSSHSession(ctx context.Context, cfg aws.Config, instanceID string) (*ssm.StartSessionOutput, error)
- func StartSession(ctx context.Context, cfg aws.Config, instanceID string) (*ssm.StartSessionOutput, error)
- func WaitForShellCommand(ctx context.Context, cfg aws.Config, instanceID, commandID string, ...) (stdout, stderr string, exitCode int, err error)
- type ConfigError
- type ConfigErrorKind
- type Instance
- type SSMInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListManagedInstances ¶
ListManagedInstances returns SSM's view of all managed instances.
func MergeSSMInfo ¶
MergeSSMInfo enriches a slice of Instance values with SSM ping status and agent version from the SSM info map.
func NewConfig ¶
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 ¶
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
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.