【发布时间】:2022-09-22 23:22:47
【问题描述】:
如何:
- 将 lambda 函数 (presignedURL) 的输出链接到 API 网关?
- 将 presignedURL 转发到用户的浏览器,从而触发下载?
用户通过 API 将
csv文件上传到 s3。在 lambda 函数转换数据后,pdf文件被发送到用户的浏览器。因此,我想在下面的
app.js中包含一个下载功能,以方便 AWS API 网关的上传功能。欢迎任何帮助如何包含以下功能:- 将 lambda 函数的输出(presignedURL,当可用时最长 30 秒)发送到 API 网关;
- 将 presignedURL 发送到用户的浏览器,从而触发下载。
// Upload function const AWS = require(\'aws-sdk\') AWS.config.update({ region: process.env.AWS_REGION }) const s3 = new AWS.S3() const URL_EXPIRATION_SECONDS = 300 // Main Lambda entry point exports.handler = async (event) => { return await getUploadURL(event) } const getUploadURL = async function(event) { const Key = `test.csv` // Get signed URL from S3 const s3Params = { Bucket: process.env.UploadBucket, Key, Expires: URL_EXPIRATION_SECONDS, ContentType: \'text/csv\', // This ACL makes the uploaded object publicly readable. You must also uncomment // the extra permission for the Lambda function in the SAM template. // ACL: \'public-read\' } console.log(\'Params: \', s3Params) const uploadURL = await s3.getSignedUrlPromise(\'putObject\', s3Params) return JSON.stringify({ uploadURL: uploadURL, Key }) } // Download function (pdf) const Downloadfunc ... // Get presignedURL from lambda function output // Send presignedURL to the browser of the user that triggers a download... </div> <h2 v-if=\"uploadURL\">File uploaded to bucket.</h2> </div> <script> const API_ENDPOINT = \'https://*****.execute-api.us-east-1.amazonaws.com/uploads\' ...
标签: javascript amazon-web-services aws-lambda aws-api-gateway pre-signed-url