0

I am building a serverless application using AWS S3. In my web app, I have a table that lists the objects inside one of my S3 buckets. As my code is terribly spaghetti, I am trying to move the functions that build the table, get the S3 bucket object list, etc, into separate files and functions. This is the code that gets the S3 list:

function listS3Objects() {
    s3.listObjects(function(err, data) {
        if (err) {
            return alert(err.message);
        }
    });
}

My question is: how can I access "data" from outside the callback function, so I can pass it as argument to other functions (like the one actually building the table)?

1 Answer 1

1

You should use Promises. For the AWS SDK calls you can add .promise() after it to make it into a promise, which allows for async/await syntax.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.