Documentation
¶
Index ¶
- func CheckInstanceExists(client *ec2.EC2, instanceID string) error
- 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 GetInstancesRunningForMoreThan24Hours(client *ec2.EC2) ([]*ec2.Instance, error)
- func GetLatestAMI(info AMIInfo) (string, 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 AMIInfo
- type Connection
- type Params
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckInstanceExists ¶ added in v1.1.1
CheckInstanceExists checks if an EC2 instance with the given instance ID exists.
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 GetInstancesRunningForMoreThan24Hours ¶ added in v1.1.1
GetInstancesRunningForMoreThan24Hours returns a list of all EC2 instances running for more than 24 hours.
func GetLatestAMI ¶ added in v1.1.1
GetLatestAMI retrieves the latest Amazon Machine Image (AMI) for a specified distribution, version and architecture. It utilizes AWS SDK to query AWS EC2 for the AMIs matching the provided pattern and returns the latest one based on the creation date.
**Parameters:**
info: An AMIInfo struct containing necessary details like Distro, Version, Architecture, and Region for which the AMI needs to be retrieved.
**Returns:**
string: The ID of the latest AMI found based on the provided information.
error: An error if any issue occurs while trying to get the latest AMI.
Example ¶
info := AMIInfo{
Distro: "ubuntu",
Version: "20.04",
Architecture: "amd64",
Region: "us-west-2",
}
amiID, err := GetLatestAMI(info)
if err != nil {
log.Fatalf("failed to get latest AMI: %v", err)
}
log.Println("Latest AMI ID:", amiID)
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.
**Returns:**
bool: A boolean value that indicates whether the code is running on an EC2 instance.
Example ¶
isEC2 := IsEC2Instance()
if isEC2 {
log.Println("Running on an EC2 instance")
} else {
log.Println("Not running on an EC2 instance")
}
func TagInstance ¶
TagInstance tags the instance tied to the input ID with the specified tag.
Types ¶
type AMIInfo ¶ added in v1.1.1
AMIInfo provides information about an AMI.
**Attributes:**
Distro: the distro to use Version: the version to use Architecture: the architecture to use Region: the region to use
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.
**Attributes:**
Client: an EC2 session Reservation: an EC2 reservation Params: parameters for an EC2 instance
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.
**Attributes:**
AssociatePublicIPAddress: whether or not to associate a public IP address ImageID: the AMI ID to use InstanceProfile: the IAM instance profile to use InstanceType: the instance type to use MinCount: the minimum number of instances to launch MaxCount: the maximum number of instances to launch SecurityGroupIDs: the security group IDs to use KeyName: the key name to use SubnetID: the subnet ID to use VolumeSize: the volume size to use InstanceID: the instance ID to use InstanceName: the instance name to use PublicIP: the public IP to use