简体   繁体   English

使用 javascript 从 S3 存储桶中读取 JSON

[英]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.我有一个每天输出到 S3 存储桶的 JSON。 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.我有一个内置 javascript 的网络应用程序,我希望能够简单地从 S3 存储桶中读取 JSON,而无需每天下载 JSON 并在 github 中重新提交等。

How does one read in a JSON that's hosted on an S3 bucket?如何读取托管在 S3 存储桶上的 JSON? 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.理想情况下,我希望它像实时连接一样工作(而不是下载),因为每天都会将 JSON 重新上传到 S3。

Is AWS SDK for javascript what I need?我需要 AWS SDK for javascript 吗? To clarify, this is an app built in vanilla javascript, not Node, so a simple-ish solution would be ideal... Thanks all.澄清一下,这是一个内置于 vanilla javascript 中的应用程序,而不是 Node,所以一个简单的解决方案将是理想的......谢谢大家。

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.到 S3 的“实时连接”的概念不切实际,但适当的替代方法是在 JSON 文件上传到 S3 存储桶时触发 JavaScript 代码运行。

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.为此,请编写并部署一个简单的 Node.js Lambda 函数,并配置 S3 以在上传 JSON 文件时触发 Lambda 函数。 Your Lambda function would use the JavaScript SDK to get the JSON file and do whatever processing is required.您的 Lambda 函数将使用JavaScript SDK来获取 JSON 文件并执行所需的任何处理。 Your Lambda function should be configured with an IAM role that permits it to get the uploaded object.您的 Lambda 函数应该配置有一个 IAM 角色,允许它获取上传的对象。

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.如果您更喜欢使用 JavaScript/TypeScript 以外的语言,请参阅AWS 工具以获取支持的语言开发工具包列表和Lambda 运行时列表以获取支持的 Lambda 运行时列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM