DiamondJoe12
DiamondJoe12

Reputation: 1809

Reading in a JSON from S3 bucket using JavaScript

I've tried to read about this but have not come up with anything yet. I have a JSON that gets output to an S3 bucket daily. I have a web app built in JavaScript that I'd like to be able to simply read in the JSON from the S3 bucket without downloading the JSON every day and re-committing in GitHub, etc etc.

How does one read in a JSON that's hosted on an S3 bucket? Ideally, I'd like this to work like a live connection (rather than downloaded), since the JSON will be re-uploaded to S3 every day.

Is AWS SDK for JavaScript what I need? To clarify, this is an app built in vanilla JavaScript, not Node, so a fairly simple solution would be ideal.

Upvotes: 0

Views: 1118

Answers (1)

jarmod
jarmod

Reputation: 78713

The notion of a 'live connection' to S3 isn't practical, but an appropriate alternative would be to trigger your JavaScript code to run whenever a JSON file is uploaded to your S3 bucket.

To do that, write and deploy a simple Node.js Lambda function and configure S3 to trigger the Lambda function when a JSON file is uploaded. Your Lambda function would use the JavaScript SDK to get the JSON file and do whatever processing is required. Your Lambda function should be configured with an IAM role that permits it to get the uploaded object.

If you prefer to use a language other than JavaScript/TypeScript, see AWS Tools for the list of supported language SDKs and Lambda runtimes for the list of supported Lambda runtimes.

Upvotes: 1

Related Questions