aws

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package aws provides utilities for interacting with AWS services, particularly EC2 for managing Elastic Network Interfaces (ENIs).

This package uses AWS SDK v2 for all AWS interactions, providing improved performance, better error handling, and more modern API design compared to v1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EC2Client

type EC2Client struct {
	// EC2 is the underlying AWS SDK v2 EC2 client
	EC2 *ec2.Client
	// Logger is used for structured logging
	Logger logr.Logger
}

EC2Client wraps the AWS EC2 client with additional functionality using SDK v2. It provides methods for creating, attaching, detaching, and deleting ENIs, as well as looking up subnet and security group IDs by name.

func NewEC2Client

func NewEC2Client(ctx context.Context, region string, logger logr.Logger) (*EC2Client, error)

NewEC2Client creates a new EC2 client using AWS SDK v2

func (*EC2Client) AttachENI

func (c *EC2Client) AttachENI(ctx context.Context, eniID, instanceID string, deviceIndex int, deleteOnTermination bool) (string, error)

AttachENI attaches an ENI to an EC2 instance

func (*EC2Client) CreateENI

func (c *EC2Client) CreateENI(ctx context.Context, subnetID string, securityGroupIDs []string, description string, tags map[string]string) (string, error)

CreateENI creates a new ENI in AWS

func (*EC2Client) DeleteENI

func (c *EC2Client) DeleteENI(ctx context.Context, eniID string) error

DeleteENI deletes an ENI

func (*EC2Client) DescribeENI

func (c *EC2Client) DescribeENI(ctx context.Context, eniID string) (*EC2v2NetworkInterface, error)

DescribeENI describes an ENI

func (*EC2Client) DetachENI

func (c *EC2Client) DetachENI(ctx context.Context, attachmentID string, force bool) error

DetachENI detaches an ENI from an EC2 instance

func (*EC2Client) GetSecurityGroupIDByName

func (c *EC2Client) GetSecurityGroupIDByName(ctx context.Context, securityGroupName string) (string, error)

GetSecurityGroupIDByName looks up a security group ID by its Name or GroupName

func (*EC2Client) GetSubnetCIDRByID added in v1.2.2

func (c *EC2Client) GetSubnetCIDRByID(ctx context.Context, subnetID string) (string, error)

GetSubnetCIDRByID looks up a subnet CIDR by its ID

func (*EC2Client) GetSubnetIDByName

func (c *EC2Client) GetSubnetIDByName(ctx context.Context, subnetName string) (string, error)

GetSubnetIDByName looks up a subnet ID by its Name tag

func (*EC2Client) WaitForENIDetachment

func (c *EC2Client) WaitForENIDetachment(ctx context.Context, eniID string, timeout time.Duration) error

WaitForENIDetachment waits for an ENI to be detached

type EC2Interface

type EC2Interface interface {
	// CreateENI creates a new ENI in AWS
	CreateENI(ctx context.Context, subnetID string, securityGroupIDs []string, description string, tags map[string]string) (string, error)

	// AttachENI attaches an ENI to an EC2 instance
	AttachENI(ctx context.Context, eniID, instanceID string, deviceIndex int, deleteOnTermination bool) (string, error)

	// DetachENI detaches an ENI from an EC2 instance
	DetachENI(ctx context.Context, attachmentID string, force bool) error

	// DeleteENI deletes an ENI
	DeleteENI(ctx context.Context, eniID string) error

	// DescribeENI describes an ENI
	// Returns nil, nil if the ENI doesn't exist
	DescribeENI(ctx context.Context, eniID string) (*EC2v2NetworkInterface, error)

	// GetSubnetIDByName looks up a subnet ID by its Name tag
	GetSubnetIDByName(ctx context.Context, subnetName string) (string, error)

	// GetSubnetCIDRByID looks up a subnet CIDR by its ID
	GetSubnetCIDRByID(ctx context.Context, subnetID string) (string, error)

	// GetSecurityGroupIDByName looks up a security group ID by its Name or GroupName
	GetSecurityGroupIDByName(ctx context.Context, securityGroupName string) (string, error)

	// WaitForENIDetachment waits for an ENI to be detached
	WaitForENIDetachment(ctx context.Context, eniID string, timeout time.Duration) error
}

EC2Interface defines the interface for EC2 operations using AWS SDK v2

func CreateEC2Client

func CreateEC2Client(ctx context.Context, region string, logger logr.Logger) (EC2Interface, error)

CreateEC2Client creates a new EC2 client

type EC2v2NetworkInterface

type EC2v2NetworkInterface struct {
	NetworkInterfaceID string
	Status             EC2v2NetworkInterfaceStatus
	Attachment         *EC2v2NetworkInterfaceAttachment
}

EC2v2NetworkInterface represents a network interface in AWS SDK v2

type EC2v2NetworkInterfaceAttachment

type EC2v2NetworkInterfaceAttachment struct {
	AttachmentID        string
	DeleteOnTermination bool
	DeviceIndex         int32
	InstanceID          string
	Status              string
}

EC2v2NetworkInterfaceAttachment represents a network interface attachment in AWS SDK v2

type EC2v2NetworkInterfaceStatus

type EC2v2NetworkInterfaceStatus string

EC2v2NetworkInterfaceStatus represents the status of a network interface in AWS SDK v2

const (
	// EC2v2NetworkInterfaceStatusAvailable represents the "available" status
	EC2v2NetworkInterfaceStatusAvailable EC2v2NetworkInterfaceStatus = "available"
	// EC2v2NetworkInterfaceStatusInUse represents the "in-use" status
	EC2v2NetworkInterfaceStatusInUse EC2v2NetworkInterfaceStatus = "in-use"
)

Jump to

Keyboard shortcuts

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