How AWS-SDK V3 Works With Nodejs? | AWS-Sdk V3 Npm Installation – DS

Back to Blog
Feature image on AWS SDK Work with Nodejs

How AWS-SDK V3 Works With Nodejs? | AWS-Sdk V3 Npm Installation – DS

What Is NPM AWS SDK Version 3?

AWS announced the AWS SDK V3 general availability for javascript. You might see the warning by AWS SDK to migrate to version 3 on the console. AWS SDK V3 comes with modular packages, which means we can install only those modules which we needed in our project. It reduces the package size. It provides us the facility to map AWS service API.  Let’s see some key features of AWS SDK V3 npm.

What’re these new versions have?

  • It comes with a modular package. In the previous version, we needed to install ‘NPM AWS SDK’ for everything. But in V3 we need to install only those packages which we need in our project.
  • It provides a middleware stack
  • Now it supports first-class typescript.

It’s time to Run some command

  • Install s3 package ‘npm install @AWS SDK/client-s3’

What Is S3?

Amazon S3 is a secure service for storing, retrieving, and protecting the data in the buckets. It is a paid service of AMAZON WEB SERVICES which is more scalable, reliable, and flexible. Data is stored on S3 as flat objects. We can set the expiry time to the objects which will be expired and be deleted automatically.

Good to Read:- Easy Step to Create & Store Data In AWS S3 Bucket 

Steps to Connect Code to AWS S3 Bucket With NodeJs Project

In the below, we shared 04 steps to connect code to npm AWS sdk V3 with NodeJS.

  • Creating a new client object

const { S3Client } = require('@AWS SDK/client-s3');

const s3 = new S3Client({

  region:’replace-region’,

  credentials: {

    accessKeyId:’access-key’,

    secretAccessKey: ‘your-secret’

  }

});
  • Upload a file to S3

const { PutObjectCommand } = require('@AWS SDK/client-s3');

const putCommand = new PutObjectCommand({

  Bucket:’bucket-name’,

  Body:’file’,

  ContentType:’content-type’,

  Key: ‘file-key’

});

await s3.send(putCommand);
  • Delete file from S3

const { DeleteObjectCommand } = require('@AWS SDK/client-s3');

const deleteCommand = new DeleteObjectCommand({

  Bucket:’bucket-name’,

  Key: ‘file-key’

});

await s3.send(deleteCommand);

Good to Read:- Setting Up Jenkins on Amazon EC2 Ubuntu Instance

  • Creating pre-signed URL

For creating a pre-signed URL in version 3, we need to install a separate package ‘npm I @AWS SDK/s3-request-presigner’

const { GetObjectCommand } = require('@AWS SDK/client-s3');

const objCommand = new GetObjectCommand({

  Bucket: 'bucket-name',

  Key: 'file-key'

})

const signedUrl = await getSignedUrl(s3,objCommand, {expiresIn: ’expiry-time’});

Frequently Asked Questions

Answer:  This runtime framework allows you to develop scalable, outstanding-performance apps by bringing JavaScript into the server-side stage. One can build web pages using Node.js, manage networking demands and enjoy event-based and effective coding.

Answer:  Using the assistance of SDKs, programmers may choreograph how they communicate using a particular operating system or application by having access to a unified collection of instruments libraries, and documentation that contain challenging duties. In doing so, they enable programmers to unleash the entire potential of APIs as well as services, transforming programming into an arrangement of effectiveness.

Answer:  Do not be alarmed; setting up the AWS SDK is as easy as a musical scale. Whether it’s Python, JavaScript, or any other language that is supported, you must first decide on your favorite programming language. The AWS SDK can then be installed using the package manager for your language, just like a finely tuned instrument.

For instance, with Node.js, you may install the SDK package and its dependencies using npm or yarn, giving you access to the AWS orchestra.

Answer: You can establish a regular process for updating your AWS SDK. Depending on your preferred programming language, you can look for the most recent SDK version, review the documentation for any significant updates or new features, and then update the SDK package via your dependable package management to the most recent official release.

Just be sure to balance your dependencies and make sure your code moves to the beat of the new SDK.


Boost your web development projects with the expertise of our skilled & certified Node.js developers. Hire NodeJS developers from Devstringx Technologies today and take your web development to new heights!

Share this post

Back to Blog