Documentation
¶
Overview ¶
Package aws provides a standard way to create a virtual machine on AWS.
Index ¶
- Constants
- Variables
- func DeleteKeyPair(name string, region string) error
- func UploadKeyPair(publicKey []byte, name string, region string) error
- func ValidCredentials(region string) error
- type EbsBlockVolume
- type Image
- type InstanceStatus
- type IpPermission
- type ReadyError
- type Region
- type S3
- type SecurityGroup
- type Subnet
- type VM
- func (vm *VM) AttachVolume() error
- func (vm *VM) AuthorizeSecurityGroup() error
- func (vm *VM) CreateVolume() error
- func (vm *VM) DeleteVolume() error
- func (vm *VM) Destroy() error
- func (vm *VM) DetachVolume() error
- func (vm *VM) GetAvailabilityZoneList() ([]Zone, error)
- func (vm *VM) GetIPs() ([]net.IP, error)
- func (vm *VM) GetImageList() ([]Image, error)
- func (vm *VM) GetName() string
- func (vm *VM) GetRegionList() ([]Region, error)
- func (vm *VM) GetSSH(options ssh.Options) (ssh.Client, error)
- func (vm *VM) GetSecurityGroupList() ([]SecurityGroup, error)
- func (vm *VM) GetState() (string, error)
- func (vm *VM) GetSubnetList() ([]Subnet, error)
- func (vm *VM) GetVPCList() ([]VPC, error)
- func (vm *VM) Halt() error
- func (vm *VM) Provision() error
- func (vm *VM) ResetKeyPair()
- func (vm *VM) Resume() error
- func (vm *VM) RevokeSecurityGroup() error
- func (vm *VM) SetKeyPair(privateKey string, name string)
- func (vm *VM) SetTag(key, value string) error
- func (vm *VM) SetTags(tags map[string]string) error
- func (vm *VM) Start() error
- func (vm *VM) Suspend() error
- func (vm *VM) ValidateAuth() error
- type VPC
- type Zone
Constants ¶
const ( // PublicIP is the index of the public IP address that GetIPs returns. PublicIP = 0 // PrivateIP is the index of the private IP address that GetIPs returns. PrivateIP = 1 // StateStarted is the state AWS reports when the VM is started. StateStarted = "running" // StateHalted is the state AWS reports when the VM is halted. StateHalted = "stopped" // StateDestroyed is the state AWS reports when the VM is destroyed. StateDestroyed = "terminated" // StatePending is the state AWS reports when the VM is pending. StatePending = "pending" )
const ( // Timeout for VM operations viz. Halt, Start & Terminate in seconds VmOpsTimeout = 900 // 15 mins // Retry interval for VM operations in seconds VmOpsInterval = 15 // Timeout for Volume operations viz. Create, Detach in seconds VolTimeout = 600 // 10 mins // Retry interval for Volume operations in seconds VolInterval = 5 )
const (
HttpClientTimeout = 30
)
const (
// RegionEnv is the env var for the AWS region.
RegionEnv = "AWS_DEFAULT_REGION"
)
Variables ¶
var ( // ErrNoCreds is returned when no credentials are found in environment or // home directory. ErrNoCreds = errors.New("Missing AWS credentials") // ErrNoRegion is returned when a request was sent without a region. ErrNoRegion = errors.New("Missing AWS region") // ErrNoInstance is returned querying an instance, but none is found. ErrNoInstance = errors.New("Missing VM instance") // ErrNoInstanceID is returned when attempting to perform an operation on // an instance, but the ID is missing. ErrNoInstanceID = errors.New("Missing instance ID") // ErrProvisionTimeout is returned when the EC2 instance takes too long to // enter "running" state. ErrProvisionTimeout = errors.New("AWS provision timeout") // ErrNoIPs is returned when no IP addresses are found for an instance. ErrNoIPs = errors.New("Missing IPs for instance") // ErrNoSupportSuspend is returned when vm.Suspend() is called. ErrNoSupportSuspend = errors.New("Suspend action not supported by AWS") // ErrNoSupportResume is returned when vm.Resume() is called. ErrNoSupportResume = errors.New("Resume action not supported by AWS") )
var SSHTimeout = 5 * time.Minute
SSHTimeout is the maximum time to wait before failing to GetSSH. This is not thread-safe.
Functions ¶
func DeleteKeyPair ¶
DeleteKeyPair deletes the given key pair from the given region.
func UploadKeyPair ¶
UploadKeyPair uploads the public key to AWS with a given name. If the public key already exists, then no error is returned.
func ValidCredentials ¶
ValidCredentials sends a dummy request to AWS to check if credentials are valid. An error is returned if credentials are missing or region is missing.
Types ¶
type EbsBlockVolume ¶
type EbsBlockVolume struct { DeviceName string `json:"device_name,omitempty"` VolumeSize *int64 `json:"volume_size,omitempty"` VolumeType string `json:"volume_type,omitempty"` AvailabilityZone string `json:"availability_zone,omitempty"` VolumeId string `json:"volume_id,omitempty"` SnapshotId string `json:"snapshot_id,omitempty"` }
EbsBlockVolume represents a AWS EbsBlockDevice
type Image ¶
type Image struct { Id *string `json:"id,omitempty"` Name *string `json:"name,omitempty"` Description *string `json:"description,omitempty"` State *string `json:"state,omitempty"` OwnerId *string `json:"owner_id,omitempty"` OwnerAlias *string `json:"owner_alias,omitempty"` CreationDate *string `json:"creation_date,omitempty"` Architecture *string `json:"architecture,omitempty"` Platform *string `json:"platform,omitempty"` Hypervisor *string `json:"hypervisor,omitempty"` VirtualizationType *string `json:"virtualization_type,omitempty"` ImageType *string `json:"image_type,omitempty"` KernelId *string `json:"kernel_id,omitemtpy"` RootDeviceName *string `json:"root_device_name,omitempty"` RootDeviceType *string `json:"root_device_type,omitempty"` Public *bool `json:"public,omitempty"` EbsVolumes []*EbsBlockVolume `json:"ebs_volumes,omitempty"` }
Image represents a AWS Image
type InstanceStatus ¶
type InstanceStatus struct { AvailabilityZone string `json:"availability_zone,omitempty"` InstanceId string `json:"instance_id,omitempty"` State string `json:"state,omitempty"` }
InstanceStatus represents AWS InstanceStatus
func GetInstanceStatus ¶
func GetInstanceStatus(svc *ec2.EC2, instID string) (*InstanceStatus, error)
GetInstanceStatus: returns status of given instances Status includes availabilityZone & state
type IpPermission ¶
type IpPermission struct { FromPort *int64 `json:"from_port,omitempty"` ToPort *int64 `json:"to_port,omitempty"` IpProtocol string `json:"ip_protocol,omitempty"` Ipv4Ranges []string `json:"ipv4_ranges,omitempty"` Ipv6Ranges []string `json:"ipv6_ranges,omitempty"` }
IpPermission in AWS is used to represent inbound or outbound rules associated with SecurityGroup
type ReadyError ¶
type ReadyError struct { Err error ImageID string InstanceID string InstanceType string LaunchTime time.Time PublicIPAddress string State string StateReason string StateTransitionReason string SubnetID string VPCID string }
ReadyError is an information error that tells you why an instance wasn't ready.
func (ReadyError) Error ¶
func (e ReadyError) Error() string
Error returns a summarized string version of ReadyError. More details about the failed instance can be accessed through the struct.
type Region ¶
type Region struct { Name string `json:"name,omitempty"` RegionEndpoint string `json:"region_endpoint,omitempty"` }
Region represents a AWS Region
type S3 ¶
type S3 struct { Name string // required Region string // required Prefix string // for creating a bucket /obj1/obj2/obj3 }
func (*S3) BucketExist ¶
func (*S3) CreateBucket ¶
func (*S3) DeleteBucket ¶
func (*S3) GetS3BucketsList ¶
type SecurityGroup ¶
type SecurityGroup struct { Id string `json:"id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` OwnerId string `json:"owner_id,omitempty"` VpcId string `json:"vpc_id,omitempty"` IpPermissionsEgress []IpPermission `json:"ip_permissions_egress,omitempty"` IpPermissions []IpPermission `json:"ip_permissions,omitempty"` }
SecurityGroup represents a AWS SecurityGroup
type Subnet ¶
type Subnet struct { Id string `json:"id,omitempty"` State string `json:"state,omitempty"` VpcId string `json:"vpc_id,omitempty"` IPv4Block string `json:"ipv4block,omitempty"` IPv6Blocks []string `json:"ipv6blocks,omitempty"` AvailableAddressCount *int64 `json:"available_address_count,omitempty"` // Availability Zone of the subnet AvailabilityZone string `json:"availability_zone,omitempty"` // Indicates if this is default for Availability Zone DefaultForAz bool `json:"default_for_az,omitempty"` MapPublicIpOnLaunch bool `json:"map_public_ip_on_launch,omitempty"` }
Subnet represents a AWS Subnet
type VM ¶
type VM struct { Name string Region string // required AMI string InstanceType string InstanceID string // required when adding volume KeyPair string // required IamInstanceProfileName string PrivateIPAddress string // required when addding or deleting volume Volumes []EbsBlockVolume KeepRootVolumeOnDestroy bool DeleteNonRootVolumeOnDestroy bool VPC string Subnet string // required when modifying security group rules // all other parameters except this one and Region // is ingnored while security group modification SecurityGroups []SecurityGroup SSHCreds ssh.Credentials // required DeleteKeysOnDestroy bool // only relevant in GetSubnetList, GetSecurityGroupList & GetImageList // filters result with given key-values Filters map[string][]*string }
VM represents an AWS EC2 virtual machine.
func (*VM) AttachVolume ¶
AttachVolume: Attaches given volume to given instance
func (*VM) AuthorizeSecurityGroup ¶
AuthorizeSecurityGroup: Adds one or more rules to a security group
func (*VM) CreateVolume ¶
CreateVolume: Creates a volume with given parameter
func (*VM) DeleteVolume ¶
DeleteVolume: Deletes volume with given Id Disk must not be in-use by any instance
func (*VM) Destroy ¶
Destroy terminates the VM on AWS. It returns an error if AWS credentials are missing or if there is no instance ID.
func (*VM) DetachVolume ¶
DetachVolume: Detaches volume with given Id from instance
func (*VM) GetAvailabilityZoneList ¶
GetAvailabilityZoneList: returns list of availability zones for a region
func (*VM) GetIPs ¶
GetIPs returns a slice of IP addresses assigned to the VM. The PublicIP or PrivateIP consts can be used to retrieve respective IP address type. It returns nil if there was an error obtaining the IPs.
func (*VM) GetImageList ¶
GetImageList: returns list of images available for given account Includes public,owned private images & private images with explicit permission
func (*VM) GetRegionList ¶
GetRegionList: returns list of regions
func (*VM) GetSSH ¶
GetSSH returns an SSH client that can be used to connect to a VM. An error is returned if the VM has no IPs.
func (*VM) GetSecurityGroupList ¶
func (vm *VM) GetSecurityGroupList() ([]SecurityGroup, error)
GetSecurityGroupList : returns list of all securityGroup for given region most relevant filter(s) (map-keys): "vpc-id", "group-id" See all available filters at below link http://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#DescribeSecurityGroupsInput
func (*VM) GetState ¶
GetState returns the state of the VM, such as "running". An error is returned if the instance ID is missing, if there was a problem querying AWS, or if there are no instances.
func (*VM) GetSubnetList ¶
GetSubnetList: returns list of all subnet for given region most relevant filter(s) (map-keys): "vpc-id", "subnet-id", "availabilityZone" See all available filters at below link http://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#DescribeSubnetsInput
func (*VM) GetVPCList ¶
GetVPCList: returns list of VPCs for given region
func (*VM) Provision ¶
Provision creates a virtual machine on AWS. It returns an error if there was a problem during creation, if there was a problem adding a tag, or if the VM takes too long to enter "running" state.
func (*VM) ResetKeyPair ¶
func (vm *VM) ResetKeyPair()
ResetKeyPair resets the key pair for this VM.
func (*VM) RevokeSecurityGroup ¶
RevokeSecurityGroup: Removes one or more rules from a security group
func (*VM) SetKeyPair ¶
SetKeyPair sets the given private key and AWS key name for this vm
func (*VM) SetTags ¶
SetTags takes in a map of tags to set to the provisioned instance. This is essentially a shorter way than calling SetTag many times.
func (*VM) ValidateAuth ¶
ValidateAuth: returns error if credentials are incorrect
type VPC ¶
type VPC struct { Id string `json:"id,omitempty"` State string `json:"state,omitempty"` IsDefault *bool `json:"is_default,omitempty"` IPv4Blocks []string `json:"ipv4_blocks,omitempty"` IPv6Blocks []string `json:"ipv6_blocks,omitempty"` // ID of DHCP options associated with VPC DhcpOptionsId string `json:"dhcp_options_id,omitempty"` // Allowed tenancy of instances launched into the VPC InstanceTenancy string `json:"instance_tenancy,omitempty"` }
VPC represents a AWS VPC