Getting Started with AWS JavaScript SDK
Build JavaScript App with Amazon Web Services
I just joined with WSO2 as an Intern for Cloud Team. After the first chat with my mentor, I was assigned to the Project about Amazon Cloud Watch Logs. Before working on that project, I prepared with AWS Javascript SDK. I have shared some useful information or the beginners here!
AWS provides JavaScript SDK for Node.js or Browsers which can allow to interact with Amazon Web services through Java Script developments. The JavaScript APIs which are available in the SDK allows developers to build libraries or applications that make use of AWS services.
Using the AWS SDK for Node.js developments
Node.js is the one of the major cross-platform run-time for running server-side JavaScript applications. So here you need to configure your environment for Node.js before working with AWS SDK. You can follow this tutorial to install Node.js for your environment.
Now we are moving to create first JavaScript App which can interact with AWS!
First Development
- There is a sample project in the GitHub, So you can simply clone to your system. You must have Git installed to get this project from GitHub.
If you clone the project, then You can see these followings line in the sample.js
file.
// Load the SDK and UUID
var AWS = require(‘aws-sdk’);
var uuid = require(‘node-uuid’);
- It means, the JS files requires those dependencies for the development. So you need to run
npm install
command to install those required dependencies including AWS SDK. - Now you want to configure your environment with AWS. To configure the AWS credentials, Create a credentials file at
~/.aws/credentials
on Mac/Linux orC:\Users\USERNAME\.aws\credentials
on Windows
In Linux, You want to go to your Home directory and press
Ctrl+H
to get the view of hidden folders. Then after create a directory as.aws
and then create acredentials
file inside the folder.
Create credentials file using this following lines,
[default]
aws_access_key_id = your_access_key
aws_secret_access_key = your_secret_key
How to get AWS Access Key and Secret Key?
If you haven’t Amazon Access Key and Secret Key already, then follow these ways to get it,
- Go to your AWA Console and then Search Identity and Access Management under Services and Click to enter IAM. In the IAM Dashboard, you can see this following menus,
- Click on the first menu(Delete your root access keys) and then click Manage Security Credentials to get your keys.
- Then after you will be redirected to Security Credentials management dashboard. At there, Click access Keys(Access Key ID and Secret Access Key menu). Now you can see Create New Access Key button.
- Click Create New Access Key button to get your Access Keys. If you click Show Access key there, then you will get your Access Key and Secret Access Keys.
Run your First Application
Now you are almost ready to run your first JavaScript application with AWS. So just type node sample.js
command to execute the code file. If you configured and manged all the dependencies correctly, then most properly you will get a success message like this,
Finally, If you check your Amazon S3 account, then you can see there was a new bucket created and the hello_world.txt file was uploaded inside that bucket.
What happened? You just uploaded hello_world.txt file from your client machine to Amazon S3 cloud :-)
Help from