0

I am trying to read a JSON file stored in an S3 bucket. I am trying to get the JSON file contents using getObject command of Javascript SDK. I am getting output as [object Object] when I convert the aws response to utf8 string. This is my nodeJS code:

const s3Client = require("./aws_s3_connect");
const { GetObjectCommand } = require("@aws-sdk/client-s3");
//const storage_file_path = "";

const run = async (input_data) => {

    const bucket_name = "bucket_name";
    const file_path = "";
    const file_name = "sample.json";

    const bucketParams = {
        Bucket: bucket_name,
        Key: file_path + file_name,
        ResponseContentType: 'application/json'
    };

    try {
        // Send get object command
        let aws_response = await s3Client.send(new GetObjectCommand(bucketParams));
        console.log(aws_response);
        //var blob = new Blob(aws_response.Body);
        let data = aws_response.Body.toString('utf8');
        console.log(data);

        return data;
    } catch (err) {
        console.log("Error", err);
    }
};

module.exports = { run };

Please help me to identify the issue. Thanks for your help.

0 Answers0