Using the AWS SDK for Node.js developments
- 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.
aws-nodejs-sample - Sample project to demonstrate usage of the AWS SDK for Node.jsgithub.com
If you clone the project, then You can see these followings line in the
// 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 installcommand 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/credentialson Mac/Linux or
In Linux, You want to go to your Home directory and press
Ctrl+Hto get the view of hidden folders. Then after create a directory as
.awsand then create a
credentialsfile inside the folder.
Create credentials file using this following lines,
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
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 :-)