简体   繁体   English

使用API​​网关,AWS LAMBDA和S3从浏览器检索文件

[英]Retrieve a file from browser using API gateway, AWS LAMBDA and S3

The setup is using S3 as a storage, API gateway for the rest endpoint and Lambda (Python) for get/fetch of file in S3. 该设置使用S3作为存储,其余端点使用API​​网关,S3中使用Lambda(Python)获取/获取文件。

I'm using Boto3 for the Lambda function (Python) to check if the file exists in S3, and I was able to download it but being stored in Lambda machine ("/tmp"). 我正在对Lambda函数(Python)使用Boto3来检查文件是否存在于S3中,并且我能够下载它但将其存储在Lambda机器(“ / tmp”)中。 The API Gateway can trigger the lambda function already. API网关已经可以触发lambda函数。 Is there a way that once the lambda function is triggered then the download will happen in the browser? 有没有一种方法可以触发lambda函数,然后在浏览器中进行下载?

Thanks! 谢谢!

Here is how we did it: 这是我们的操作方式:

Check and Redirect: 检查并重定向:

API Gateway --> Lambda (return 302) API网关-> Lambda(返回302)

Deliver Content: 交付内容:

CloudFront --> S3 CloudFront-> S3

Check for S3 existence with Lambda returning a 302 to cloudfront. 使用Lambda将302返回Cloudfront检查S3是否存在。 You can also return Signed URL from Lambda with a valid time to access the URL from CloudFront. 您还可以在有效时间内从Lambda返回Signed URL,以从CloudFront访问URL。

Hope it helps. 希望能帮助到你。

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

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