Rajiv Seelam • December 12, 2019

AWS Basics - Setup

aws

You need an AWS Account

Setup your command line

Before we delve into the world of AWS. Let's make sure our system is fit and ready for development.

Do you have these installed?

Is AWS Configured?

We have copied Access Key and Secret Key in above steps, we need to use them after all.

We can configure multiple AWS Accounts (If you want)

Where are AWS credentials stored in my system?

For AWS NodeJS SDK to work properly, it's important for above to be setup properly.

Setup NodeJS SDK

Let's install aws-sdk and see if it works now.

Let's write our first piece of code, we will try to see which profile is being used, paste the following contents into index.js file:

//index.js
const AWS = require("aws-sdk");

AWS.config.getCredentials((err) => {
  if (err) console.log(err.stack);
  else console.log("Access Key:", AWS.config.credentials);
});

Run: node index.js

You would see response something similar to:

// response in command line
Access Key: SharedIniFileCredentials {
  expired: false,
  expireTime: null,
  refreshCallbacks: [],
  accessKeyId: 'XXXXXXXXXXXX',
  sessionToken: undefined,
  filename: undefined,
  profile: 'xxxxxxxxx',
  disableAssumeRole: true,
  preferStaticCredentials: false,
  tokenCodeFn: null,
  httpOptions: null
}

Let's try to get list of users, replace index.js with following code:

//index.js
const AWS = require("aws-sdk");

var iam = new AWS.IAM();

iam.listUsers({}, (err, data) => {
  if (err) {
    console.log(err, err.stack);
  } else {
    console.log(data);
  }
});

And you should see some response like following:

{
  ResponseMetadata: { RequestId: 'ddddddxxx-81d6-445b-a953-6111ac85454f' },
  Users: [
    {
      Path: '/',
      UserName: 'access-xxx',
      UserId: 'AIDAXTRL34HMEET6MW74W',
      Arn: 'arn:aws:iam::45656546:user/access-xxx',
      CreateDate: 2019-11-26T10:37:22.000Z,
      Tags: []
    }
  ]
}

If you got above responses, you are done with setup.