Tuesday, 19 November 2019

How to access Amazon Web Services via AWS Go SDK

The centre point of the AWS client application is AWS Session. To create it, we need to do the following:

(1) import github.com/aws/aws-sdk-go/aws/session package
(2) call NewSession() on it

sess, err := session.NewSession()

By default, session uses environment variables for its configuration. Some of them are:

AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION

For the full list see AWS CLI - Environment Variables.

So, if we call our AWS client app (let's name it aws-client) from command line, we can first set these environment variables:

export AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID_VALUE
export AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY_VALUE
export AWS_REGION=AWS_REGION_VALUE
aws-client

If aws-client is entrypoint for Docker container, we can pass these environment variables via command line:

docker run \
-e AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID_VALUE \
-e AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY_VALUE \
-e AWS_REGION=AWS_REGION_VALUE \
--rm \
aws-client-image

We can create session configuration explicitly and pass options which are programmatically set. For this, we need to:

(1) import github.com/aws/aws-sdk-go/aws package
(2) create Config structure and pass it to session constructor

sess, err := session.NewSession(&aws.Config{})

In the example above, environment variables will still be used. If we want to pass particular options, we can set matching properties of the Config structure:

// S3Region is the name of the geo region e.g. "eu-west-2"
const S3Region = "us-east-1"
...
sess, err := session.NewSession(
   &aws.Config{
      Region: aws.String(S3Region)
   }
)

For complete list of regions see Regions and Availability Zones - Amazon Relational Database Service.



TO BE CONTINUED...

1 comment:

micheal pan said...

BE SMART AND BECOME RICH IN LESS THAN 3DAYS....It all depends on how fast 
you can be to get the new PROGRAMMED blank ATM card that is capable of
hacking into any ATM machine,anywhere in the world. I got to know about 
this BLANK ATM CARD when I was searching for job online about a month 
ago..It has really changed my life for good and now I can say I'm rich and 
I can never be poor again. The least money I get in a day with it is about 
$50,000.(fifty thousand USD) Every now and then I keeping pumping money 
into my account. Though is illegal,there is no risk of being caught 
,because it has been programmed in such a way that it is not traceable,it 
also has a technique that makes it impossible for the CCTVs to detect 
you..For details on how to get yours today, email the hackers on : (
atmmachinehackers1@gmail.com ). Tell your 
loved once too, and start to live large. That's the simple testimony of how 
my life changed for good...Love you all ...the email address again is ;
atmmachinehackers1@gmail.com