ec2

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ec2 implements the instance.InstanceProvisioner interface using the AWS EC2 API (SDK v2). Provider-specific launch configuration is passed via EC2LaunchConfig at construction time, keeping the shared InstanceConfig provider-neutral.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EC2API

type EC2API interface {
	RunInstances(ctx context.Context, params *ec2.RunInstancesInput, optFns ...func(*ec2.Options)) (*ec2.RunInstancesOutput, error)
	TerminateInstances(ctx context.Context, params *ec2.TerminateInstancesInput, optFns ...func(*ec2.Options)) (*ec2.TerminateInstancesOutput, error)
	StopInstances(ctx context.Context, params *ec2.StopInstancesInput, optFns ...func(*ec2.Options)) (*ec2.StopInstancesOutput, error)
	StartInstances(ctx context.Context, params *ec2.StartInstancesInput, optFns ...func(*ec2.Options)) (*ec2.StartInstancesOutput, error)
	DescribeInstances(ctx context.Context, params *ec2.DescribeInstancesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error)
}

EC2API wraps the subset of the AWS EC2 SDK methods needed by the provisioner. This enables unit testing with a mock implementation.

type EC2InstanceProvisioner

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

EC2InstanceProvisioner implements instance.InstanceProvisioner using the AWS EC2 API.

func NewEC2InstanceProvisioner

func NewEC2InstanceProvisioner(client EC2API, launchCfg EC2LaunchConfig) *EC2InstanceProvisioner

NewEC2InstanceProvisioner creates an EC2InstanceProvisioner with the given EC2 API client and launch configuration.

func NewEC2InstanceProvisionerWithLogger

func NewEC2InstanceProvisionerWithLogger(client EC2API, launchCfg EC2LaunchConfig, logger *slog.Logger) *EC2InstanceProvisioner

NewEC2InstanceProvisionerWithLogger creates an EC2InstanceProvisioner with a custom logger.

func (*EC2InstanceProvisioner) DescribeInstance

func (p *EC2InstanceProvisioner) DescribeInstance(ctx context.Context, instanceID string) (*instance.InstanceStatus, error)

DescribeInstance returns the current status of an EC2 instance.

func (*EC2InstanceProvisioner) LaunchInstance

LaunchInstance provisions a new EC2 instance. It calls RunInstances and returns immediately with the instance ID and initial info. The instance may still be booting (State == CloudInstancePending).

func (*EC2InstanceProvisioner) ListInstances

ListInstances returns all instances matching the given filter. Uses EC2 tag filters and instance-state-name filters to narrow results. This is the crash recovery path for rediscovering managed instances.

func (*EC2InstanceProvisioner) StartInstance

func (p *EC2InstanceProvisioner) StartInstance(ctx context.Context, instanceID string) (*instance.InstanceInfo, error)

StartInstance restarts a previously stopped EC2 instance. Returns updated InstanceInfo with potentially new IP addresses.

func (*EC2InstanceProvisioner) StopInstance

func (p *EC2InstanceProvisioner) StopInstance(ctx context.Context, instanceID string) error

StopInstance stops an EC2 instance without terminating it.

func (*EC2InstanceProvisioner) TerminateInstance

func (p *EC2InstanceProvisioner) TerminateInstance(ctx context.Context, instanceID string) error

TerminateInstance permanently destroys an EC2 instance. Terminating an already-terminated instance is idempotent (no error).

type EC2LaunchConfig

type EC2LaunchConfig struct {
	// SecurityGroupIDs are VPC security groups to attach to launched instances.
	SecurityGroupIDs []string

	// SubnetID is the VPC subnet to launch into.
	SubnetID string

	// KeyName is the SSH key pair name (optional, for debugging).
	KeyName string

	// InstanceProfileName is the IAM instance profile NAME (not ARN, not role name).
	// This is the instance profile that gets associated with the EC2 instance via
	// the IamInstanceProfile.Name parameter in RunInstances. The instance profile
	// must already exist and have the desired IAM role attached to it.
	InstanceProfileName string
}

EC2LaunchConfig holds AWS-specific instance launch parameters. These are provider-specific and are NOT part of the shared InstanceConfig.

Jump to

Keyboard shortcuts

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