awsutils

package module
v0.0.0-...-c196fe8 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

README

AWS Utils Library

Go Report Card Build Status

This is a simple Go library that wraps the "AWS GO SDK" library to provide some useful functions that create or modify AWS resources.

Example Usage

awsutils.CreateEC2KeyPair("aws_region", "key_name")

The above code creates a new KeyPair and saves the secret key to ~/.ssh/ directory on UNIX systems. It returns an error if something went wrong.

awsutils.ListAllEC2KeyPairs("aws_region")

The above code returns a array of pointers to ec2.KeyPairInfo or an error if something goes wrong while querying the region for all security keys available.

awsutils.DeleteEC2KeyPair("aws_region", "keypair_name")

The above code deletes a key in the specifid region if it exists, otherwise gives an error.

awsutils.CreateSecurityGroupForSSH("aws_region", "group_name", "group_description")

The above code creates a security group with name and description unless the name already exists. It returns a string which contains the sgID of the newly create security group or an error if something went wrong.

awsutils.ListAllSecurityGroups("aws_region", "sgID")

The above function lists all security groups in a region if the "sgID" string was empty, otherwise lists all info about the security group with the given ID.

awsutils.OpenSession("public_ec2_IP", "name_of_secret_key.pem")

The above code can be used to initiate a session in the terminal and switch to it interactively.

The library assumes that the secret key used for login is available in the "~/.ssh" directory.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllRegions = []string{
	"us-east-2",
	"us-east-1",
	"us-west-1",
	"us-west-2",
	"ap-south-1",
	"ap-northeast-3",
	"ap-northeast-2",
	"ap-southeast-1",
	"ap-southeast-2",
	"ap-northeast-1",
	"ca-central-1",
	"cn-north-1",
	"cn-northwest-1",
	"eu-central-1",
	"eu-west-1",
	"eu-west-2",
	"eu-west-3",
	"sa-east-1",
	"us-gov-east-1",
	"us-gov-west-1",
}

AllRegions is a vsriable that stores all possible AWS regions

Functions

func Connect

func Connect(host string, username string, methods ...ssh.AuthMethod) (*ssh.Client, error)

Connect is a function to configure the connection with username, authentication methods

func CreateEC2KeyPair

func CreateEC2KeyPair(region string, keyname string) error

CreateEC2KeyPair creates a new AWS SSH Secret key and puts the secret content in a file in ~/.ssh/ dir

func CreateInstance

func CreateInstance(region string, keypair string, sgparam string, amid string) (string, error)

CreateInstance is for creating EC2 instances for given region, keypair, SG and AMI-ID

func CreateSecurityGroupForSSH

func CreateSecurityGroupForSSH(region string, name string, description string) (string, error)

CreateSecurityGroupForSSH is a function to create security group that allows SSN through on TCP/22 returns (string, error) that point to SG-ID and error if any during execution

func DeleteEC2KeyPair

func DeleteEC2KeyPair(region string, keyname string) error

DeleteEC2KeyPair is a function to delete specified key in specified region

func GetAmazonImageID

func GetAmazonImageID(region string) string

GetAmazonImageID is a function storing ami IDs anre returning then based on region

func GetEC2ServiceClient

func GetEC2ServiceClient(region string) (*ec2.EC2, error)

GetEC2ServiceClient it is helper function to validate region and open SVC session to EC2

func GetKeyPairs

func GetKeyPairs(region string) ([]string, error)

GetKeyPairs returns EC2 key pairs from given account for given region

func GetSecurityGroupID

func GetSecurityGroupID(region string) string

GetSecurityGroupID is a func that returns SG ID basedo n region

func KeyPair

func KeyPair(keyFile string) (ssh.AuthMethod, error)

KeyPair is a function to help retrieve the key from the filesystem, assumes it to be under ~/.ssh/ folder

func ListAllEC2KeyPairs

func ListAllEC2KeyPairs(region string) ([]*ec2.KeyPairInfo, error)

ListAllEC2KeyPairs is a function to list all AWS KeyPairs in region specified

func ListAllSecurityGroups

func ListAllSecurityGroups(region string, sgID string) ([]*ec2.SecurityGroup, error)

ListAllSecurityGroups is a function to list all security groups, if sgID is "" then it lists all in the region

func OpenSession

func OpenSession(username string, ipaddress string, keyname string)

OpenSession helps to open the session in an interactive way in current terminal session

func PlotGraph

func PlotGraph(region string, instanceID string, data []Metric)

PlotGraph is for plotting graphs

func RenderGraphs

func RenderGraphs(metricArray []Metric)

RenderGraphs is helper func to render graphs

func SSHAgent

func SSHAgent() (ssh.AuthMethod, error)

SSHAgent creates an SSH agent

func StartInstance

func StartInstance(region string, instanceID string) error

StartInstance is helper func to start instance in region with given InstanceID

func StopInstance

func StopInstance(region string, instanceID string) error

StopInstance is helper func to stop instance with given ID in given region

func TagInstance

func TagInstance(region string, instanceid string, nametag string) error

TagInstance is a helper function to tag a newly created instance

func TerminateInstanceByID

func TerminateInstanceByID(region string, instanceID string) error

TerminateInstanceByID is helper func to terminate instance by ID

Types

type Metric

type Metric struct {
	Region     string
	InstanceID string
	MetricName string
	Values     []int
}

Metric struct to hold CW metrics data

func GetCloudWatchMetrics

func GetCloudWatchMetrics(region string, instanceID string) []Metric

GetCloudWatchMetrics to help get metrics for given Instance ID

Jump to

Keyboard shortcuts

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