I am trying to get a pre-signed URL to upload files to the S3 bucket. Here is my workflow:
1. Invoke Lambda -> 2. Get pre-signed URL -> 3. Hit the URL (PUT) with file
1. Invoke Lambda
I made sure the AWS keys have the correct permission. In fact, it has full access. Here is the Source code:
AWS.config.update({
accessKeyId: '*****************',
secretAccessKey: '*****************',
region: 'us-east-1',
signatureVersion: 'v4'
});
let requestObject = JSON.parse(event["body"]);
let fileName = requestObject.fileName;
let fileType = requestObject.fileType;
const myBucket = 'jobobo-resumes';
s3.getSignedUrl('putObject', {
"Bucket": myBucket,
"Key": fileName,
"ContentType": fileType
}, function (err, url) {
if (err) {
mainCallback(null, err);
} else {
mainCallback(null, url);
}
}
So, I am getting the filename, file type(MIME) from the request and use that to create the signature.
2. Get pre-signed URL When I hit the Lambda I get the pre-signed URL. Now, I will use this URL to upload the file to S3.
3. Hit the URL (PUT) with file
Now, I hit the URL with HTTP method and I add the file (binary), see my Postman request:
You can see that I hit the request with the PUT HTTP Method. I get the 403 error. Here are the headers in the request and you can see that the content-type is image/jpeg
:
When I try the POST method, I get that the signature is invalid. I guess that is because of the signature is signed for the PUT method.
Here is the S3 bucket's settings:
Since I get access denied, I completely opened the bucket, I mean Block Public access: off
.
What is wrong with the settings? Maybe S3?