question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

S3.getObject "Converting circular structure to JSON" error in node 8.10

See original GitHub issue
const AWS = require('aws-sdk');
const s3 = new AWS.S3();

exports.handler = async (event) => {
    // TODO implement
    
    var params = {
        Bucket: 'bucketName',
        Key: `Key`
    };

    return s3.getObject(params, function(err, data) {
        if (err) { // an error occurred
        console.log(err)
            return 'Hello from Lambda!, error';
        } else { // successful response
            console.log(data);
            return 'Hello from Lambda! data';
        }
    });
    
};
{
  "errorMessage": "Converting circular structure to JSON",
  "errorType": "TypeError",
  "stackTrace": []
}
START RequestId: f66642cd-6561-11e8-9101-45144114db6b Version: $LATEST
Unable to stringify response body as json: Converting circular structure to JSON: TypeError
    at JSON.stringify (<anonymous>)
2018-06-01T06:06:46.750Z	f66642cd-6561-11e8-9101-45144114db6b	{ AcceptRanges: 'bytes',
  LastModified: 2018-05-13T08:32:08.000Z,
  ContentLength: 198,
  ETag: '"6c437a16c722e7f90b76dc3198355248"',
  ContentType: 'application/json',
  Metadata: {},
  Body: <Buffer 7b 0a 20 20 20 20 22 6d 61 6b 65 22 3a 20 22 46 69 61 74 22 2c 0a 20 20 20 20 22 6d 6f 64 65 6c 22 3a 20 22 35 30 30 22 2c 0a 20 20 20 20 22 72 72 70 ... > }
END RequestId: f66642cd-6561-11e8-9101-45144114db6b
REPORT RequestId: f66642cd-6561-11e8-9101-45144114db6b	Duration: 936.36 ms	Billed Duration: 1000 ms 	Memory Size: 128 MB	Max Memory Used: 32 MB	

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
SamWSoftwarecommented, Jun 4, 2018

I had to promisify the .getObject to make it work with async

1reaction
srchasecommented, Oct 8, 2018

@taylor-zr

The ‘response’ you’re attempting to return is the actual request, which has a circular reference to itself, resulting in the error you’re seeing.

Could you try this instead?

exports.handler = async (event) => {
    return await s3.getObject(params).promise()
    .then((res) => {
        return res.Body.toString('utf-8');
    })
    .catch((err) => {
        return err;
    });
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

"Converting circular structure to JSON" while reading data ...
I getting data from RDS correctly but facing problems while inserting it into DynamoDB. I am sharing my code and error message please...
Read more >
Converting circular structure to JSON in nodejs-node.js
TypeError : Converting circular structure to JSON in nodejs: This error can be seen on Arangodb when using it with Node.js, because storage...
Read more >
@aws-cdk/aws-s3 | Yarn - Package Manager
Define an unencrypted S3 bucket. const bucket = new s3.Bucket(this, 'MyFirstBucket');. Bucket constructs expose the following deploy-time attributes:.
Read more >
AWS S3 GetObject API Walkthrough with NodeJS - YouTube
Learn all about the S3 GetObject API and how to use it with NodeJS.Become a Better Developer Using the Courses I Recommend Below:-...
Read more >
Red Hat Integration 2020-Q2 Data Virtualization Reference
official Joyent Node.js open source or commercial project. ... and JSON responses are converted to tabular results.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found