[Node.js] Read an S3 object with AWS SDK for JavaScript v2

Created on November 30, 2026

You can call getObject() on an AWS.S3 client to fetch an object. The following example reads a text file and prints its contents. Set the region, bucket, and key for your object, and use AWS credentials with read access.

const AWS = require("aws-sdk");

async function main() {
  const s3 = new AWS.S3({
    region: "ap-northeast-1",
  });

  const result = await s3
    .getObject({
      Bucket: "dummy.s3.example.com",
      Key: "dummy_files/file1.txt",
    })
    .promise();

  console.log(result.Body.toString());
}

main();

An object containing hello produces the following output.

hello

This example uses AWS SDK for JavaScript v2. AWS ended support for v2 on September 8, 2025.

Reference

Node.js AWS