Documentation
¶
Index ¶
- func CreateInstance(client *ec2.EC2, ec2Params Params) (*ec2.Reservation, error)
- func DestroyInstance(client *ec2.EC2, instanceID string) error
- func GetInstanceID(instanceReservation *ec2.Instance) string
- func GetInstancePublicIP(client *ec2.EC2, instanceID string) (string, error)
- func GetInstanceState(client *ec2.EC2, instanceID string) (string, error)
- func GetInstances(client *ec2.EC2, filters []*ec2.Filter) ([]*ec2.Instance, error)
- func GetRegion(client *ec2.EC2) (string, error)
- func GetRunningInstances(client *ec2.EC2) (*ec2.DescribeInstancesOutput, error)
- func IsEC2Instance() bool
- func TagInstance(client *ec2.EC2, instanceID string, tagKey string, tagValue string) error
- func WaitForInstance(client *ec2.EC2, instanceID string) error
- type Connection
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateInstance ¶
CreateInstance returns an ec2 reservation for an instance that is created with the input ec2Params.
func DestroyInstance ¶
DestroyInstance terminates the ec2 instance associated with the input instanceID.
func GetInstanceID ¶
GetInstanceID returns the instance ID from an input instanceReservation.
func GetInstancePublicIP ¶
GetInstancePublicIP returns the public IP address of the input instanceID.
func GetInstanceState ¶
GetInstanceState returns the state of the ec2 instance associated with the input instanceID.
func GetInstances ¶
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 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 ¶
TagInstance tags the instance tied to the input ID with the specified tag.
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.