ec2

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 5 Imported by: 0

README

Running the Tests

You'll need a bunch of environment variables to run these tests. The easiest way to do this is to copy and fill in the provided template:

cp test_env_template test_env

Fill in all of the export commands in test_env with the appropriate values, then source the file to add the environment variables to your shell:

source test_env

Note: test_env is captured in the repo's .gitignore, so you don't need to worry about accidentally committing secrets.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateInstance

func CreateInstance(client *ec2.EC2, ec2Params Params) (*ec2.Reservation, error)

CreateInstance returns an ec2 reservation for an instance that is created with the input ec2Params.

func DestroyInstance

func DestroyInstance(client *ec2.EC2, instanceID string) error

DestroyInstance terminates the ec2 instance associated with the input instanceID.

func GetInstanceID

func GetInstanceID(instanceReservation *ec2.Instance) string

GetInstanceID returns the instance ID from an input instanceReservation.

func GetInstancePublicIP

func GetInstancePublicIP(client *ec2.EC2, instanceID string) (string, error)

GetInstancePublicIP returns the public IP address of the input instanceID.

func GetInstanceState

func GetInstanceState(client *ec2.EC2, instanceID string) (string, error)

GetInstanceState returns the state of the ec2 instance associated with the input instanceID.

func GetInstances

func GetInstances(client *ec2.EC2, filters []*ec2.Filter) (
	[]*ec2.Instance, error)

GetInstances returns ec2 instances that the input client has access to. If no filters are provided, all ec2 instances will be returned by default.

func GetRegion

func GetRegion(client *ec2.EC2) (string, error)

GetRegion returns the region associated with the input ec2 client.

func GetRunningInstances

func GetRunningInstances(client *ec2.EC2) (*ec2.DescribeInstancesOutput, error)

GetRunningInstances returns all ec2 instances with a state of running.

func IsEC2Instance

func IsEC2Instance() bool

IsEC2Instance checks whether the code is running on an AWS EC2 instance by checking the existence of the file /sys/devices/virtual/dmi/id/product_uuid. If the file exists, the code is running on an EC2 instance, and the function returns true. If the file does not exist, the function returns false, indicating that the code is not running on an EC2 instance.

Example usage:

isEC2 := IsEC2Instance()
if isEC2 {
	fmt.Println("Running on an EC2 instance")
} else {
	fmt.Println("Not running on an EC2 instance")
}

Returns:

bool: A boolean value that indicates whether the code is running on an EC2 instance.

func TagInstance

func TagInstance(client *ec2.EC2, instanceID string, tagKey string, tagValue string) error

TagInstance tags the instance tied to the input ID with the specified tag.

func WaitForInstance

func WaitForInstance(client *ec2.EC2, instanceID string) error

WaitForInstance waits for the input instanceID to get to a running state.

Types

type Connection

type Connection struct {
	Client      *ec2.EC2
	Reservation *ec2.Reservation
	Params      Params
}

Connection contains all of the relevant information to maintain an EC2 connection.

func CreateConnection

func CreateConnection() Connection

CreateConnection creates a connection with EC2 and returns a Connection.

type Params

type Params struct {
	AssociatePublicIPAddress bool
	ImageID                  string
	InstanceProfile          string
	InstanceType             string
	MinCount                 int
	MaxCount                 int
	SecurityGroupIDs         []string
	KeyName                  string
	SubnetID                 string
	VolumeSize               int64
	InstanceID               string
	InstanceName             string
	PublicIP                 string
}

Params provides parameter options for an EC2 instance.

Jump to

Keyboard shortcuts

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