I wanted to create a lambda function in AWS to create a presigned url for my project, I am not sure if this is the expected result.
This is the lambda function in AWS console.
const AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: 'xxx',
secretAccessKey: 'xxx'
});
const bucket = new AWS.S3();
exports.handler = async (event) => {
// TODO implement
// let requestObject = event["body"];
const fileName = event["fileName"];
// generate a 10 (60 sec. * 10) minutes URL
const params = {
Bucket: "xxx",
Expires: 60 * 60, // in seconds,
Fields: {
key: fileName,
},
Conditions: [
['content-length-range', 0,1073741824]
]
};
const { url, fields } = await bucket.createPresignedPost(params);
const response = {
statusCode: 200,
url: url,
fields: fields
};
return response;
};
this is the result of the test request to lambda function
{
"statusCode": 200,
"url": "https://s3.eu-west-2.amazonaws.com/xxx",
"fields": {
"key": "upload/yasin-test-aaa.mp4",
"bucket": "xxx",
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Credential": "AKIA4VX7VVP3LMLE3CHF/20240520/eu-west-2/s3/aws4_request",
"X-Amz-Date": "20240520T173547Z",
"Policy": "eyJleHBpcmF0aW9uIjoiMjAyNC0wNS0yMFQxODozNTo0N1oiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMCwxMDczNzQxODI0XSx7ImtleSI6InVwbG9hZC95b3J1bS1yZXNpbWxlcmkveWFzaW4tdGVzdC1hYWEubXA0In0seyJidWNrZXQiOiJjZG4udG9uem8uY29tLnRyIn0seyJYLUFtei1BbGdvcml0aG0iOiJBV1M0LUhNQUMtU0hBMjU2In0seyJYLUFtei1DcmVkZW50aWFsIjoiQUtJQTRWWDdWVlAzTE1MRTNDSEYvMjAyNDA1MjAvZXUtd2VzdC0yL3MzL2F3czRfcmVxdWVzdCJ9LHsiWC1BbXotRGF0ZSI6IjIwMjQwNTIwVDE3MzU0N1oifV19",
"X-Amz-Signature": "3a8372b714f7327de2aef6076210660f51180b077fc960ae7a7179449529d52e"
}
}
But where is the url to post the file ? I could not locate that from the result? I hope someone can help me on this.
New contributor
ahmet simsek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.