How to call s3 manually inside query

Is any way to call a read file object directly from query because I want to get the body of the document, the getAllInvoices is not brining me body of the documents so I need to take them by Key

Hello @dinkok,

Thank you for your question! Here is a suggestion:

To retrieve the body of a document by its key from an S3 file object, we can use the getObject method provided by the AWS SDK. Below are the steps you need to follow:

  1. Set up an S3 resource in your AWS platform and ensure you have the appropriate access keys, secret keys, and permissions.
  2. Here's a sample code where you use the getObject method:
var AWS = require('aws-sdk');
var s3 = new AWS.S3();

var params = {
  Bucket: 'your-bucket-name',
  Key: 'the-key-of-the-object',

s3.getObject(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else console.log(data.Body.toString('utf-8')); // successful response

In this code, replace 'your-bucket-name' and 'the-key-of-the-object' with your actual bucket name and the key of the object.

  1. Now you can create a new query to retrieve the file. Select the S3 resource you configured, and create a query using 'Bucket' and 'Key' parameters. If your S3 bucket is connected to Retool, create a new query of type 'S3 getObject'.

Make sure that the getAllInvoices method returns the entire contents of the file. If not, you may have to modify it or use the getObject command. When handling large file contents, consider implementing pagination or loading a preview to avoid performance issues.

The key of an S3 object resembles the path of the file in the bucket, with the file name. If for instance, there's a 'document.txt' file at the root of your S3 bucket, then the key would be 'document.txt'.

If the context involves collecting .har and .json files, ensure to avoid personal and sensitive data while refreshing the page to gather their .har files.

Hopefully this information gets you closer to a solution to this challenge.


I fixed with additionalScope thank you :slight_smile:

If I try to load libraries with require or import statements retool gives me an error. How did you manage to use aws-sdk in a jsquery in retool?