Created
August 20, 2019 08:19
-
-
Save keroloswilliam/5a64debaa73ecd7ee58cbd9dd7dbac52 to your computer and use it in GitHub Desktop.
Go function that opens session to aws and returns it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/logrusorgru/aurora" | |
) | |
// this is used for colorizing the output | |
var au aurora.Aurora | |
func init(){ | |
au = aurora.NewAurora(true) | |
} | |
// The AWS ENV VARS should be set before CALLING this function | |
// Also REGION is Hard coded | |
// DESC. Opens session for AWS s3 buckets | |
// ARGS none | |
// RETURNS The opened session | |
func openConnectionToAws() *session.Session{ | |
fmt.Println(au.Bold(au.Cyan("INFO:")), "Setting up the session") | |
sess, err := session.NewSession(&aws.Config{ | |
Region: aws.String("us-west-1")}, | |
) | |
if err != nil { | |
log.Fatalln(au.Bold(au.Red("ERROR:\n")), "couldn't open connection", err) | |
} | |
fmt.Println(au.Bold(au.Green("DONE:")), "Setting up the session") | |
return sess | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment