Need help with the following functionalities:
- Connecting the output of a lambda function (presignedURL) to an API gateway;
- Sending the presignedURL to the user's browser for triggering a download.
Imagine a scenario where a user uploads a csv
file through an API to s3. A lambda function then processes the data and sends a pdf
file back to the user's browser.
I am looking for assistance with implementing a download function in the provided app.js
that integrates with the uploading feature of the AWS API Gateway. Any suggestions on how to include the aforementioned functionalities would be greatly appreciated!
- Transferring the output of the lambda function (presignedURL, within 30 seconds) to the API gateway;
- Sending the presignedURL to the user's browser to trigger a download.
// Code snippet for uploading 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`
// Obtain signed URL from S3
const s3Params = {
Bucket: process.env.UploadBucket,
Key,
Expires: URL_EXPIRATION_SECONDS,
ContentType: 'text/csv',
// Setting ACL to make the uploaded object publicly readable is necessary. Don't forget to uncomment
// the additional permission for the Lambda function in the SAM template.
// ACL: 'public-read'
}
console.log('Parameters: ', s3Params)
const uploadURL = await s3.getSignedUrlPromise('putObject', s3Params)
return JSON.stringify({
uploadURL: uploadURL,
Key
})
}
// Download function (pdf)
const Downloadfunc ...
// Retrieve presignedURL from lambda function output
// Transmit presignedURL to the user's browser to initiate 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'
...