ec2

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

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

Go to latest
Published: Nov 16, 2020 License: MIT Imports: 16 Imported by: 0

README

go-aws-ec2

Golang aws ec2 api wrapper

Example of use

package main

import (
    "fmt"
    ec2 "github.com/alonsopf/go-aws-ec2"
)

func main() {
	ec2.Init("us-west-1","AwsAccessKeyID", "AwsSecretAccessKey")
	//only if needed create a key pair
	keyPairName := "my-new-secret-key"
	fmt.Println("Creating key pair...")
	keyFingerprint, keyMaterial, keyPairId, err := ec2.CreateAWSKeyPair(keyPairName, 1) // 1 is create pem file
	fmt.Println(keyFingerprint, keyMaterial, keyPairId)

	fmt.Println("Creating server instance...")
	mySecurityGroup := "sg-00000000"
	instanceID, publicDNS, err := aws.CreateInstanceAndUploadDockerImage("ami-0e4035ae3f70c400f", "t2.micro", mySecurityGroup, "/dev/sdh", keyPairName, "dockerUser", "dockerPass", "nameImgDocker", int64(8))
	fmt.Println(instanceID, ip, err)
	fmt.Println("Associating server instance to IAM Profile...")
        // AmazonSSMRoleForInstancesQuickSetup is the automatic role that was created in the IAM quick setup
	AssociationId, err := ec2.AssociateIAMRole(instanceID, "AmazonSSMRoleForInstancesQuickSetup") 
	fmt.Println(AssociationId, err)
	
	/*
	//create ecr repository
	res, err := aws.CreateRepository("alonsopf/test")
	fmt.Println(res, err)

	//create kubernetes cluster
	subnetIds := "subnet-b061adea|subnet-d7dd6eb1"
	roleArn, err := aws.GetIAMRoleARN("testIAM")
	fmt.Println(roleArn, err)
	status, err := aws.CreateKubernetesCluster("1.17", mySecurityGroup, "tekton", roleArn, uid, subnetIds) 
	fmt.Println(status, err)
	*/
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssociateIAMRole

func AssociateIAMRole(instanceID, iamRole string) (string, error)

AssociateIAMRole allows you connect your IAM role to your instance

func CreateAWSKeyPair

func CreateAWSKeyPair(keyName string, option int) (string, string, string, error)

CreateAWSKeyPair allows you create your key pair if needed set option to 1 if you want to save the pem file to disk

func CreateInstanceAndUploadDockerImage

func CreateInstanceAndUploadDockerImage(ami, instanceType, securityGroupID, deviceName, keyPairName, dockerUser, passDocker, dockerImgName string, gbSize int64) (string, string, error)

CreateInstanceAndUploadDockerImage create a server instance, and return the instanceID, public dns, or error if fails. You must provide the ami id, for example: "ami-0e4035ae3f70c400f", the instanceType too, such as "t2.micro" and your securityGroupID: "sg-00000000", also the gbSize is the disk space in gigabytes

func CreateKubernetesCluster

func CreateKubernetesCluster(version, securityGroupID, name, roleArn, uuid, subnetIds string) (string, error)

CreateKubernetesCluster allows you create a new Kubernetes cluster

func CreateRepository

func CreateRepository(name string) (string, error)

CreateRepository allows you create a new repository in aws ErrCodeResourceInUseException

func GetIAMRoleARN

func GetIAMRoleARN(name string) (string, error)

GetIAMRoleARN allows you create a new Kubernetes cluster

func Init

func Init(region, accessKey, secretKey string)

Init is for setting the aws secret keys

func InstallGo

func InstallGo(fileNamePem, user, publicDNS string) error

InstallGo install golang in your server (under development)

Types

This section is empty.

Jump to

Keyboard shortcuts

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