Been debugging an entire day and still can't figure out why my s3.upload() method is not being called inside my lambda function. Someone please help
const AWS = require('aws-sdk');
let s3= new AWS.S3();
exports.handler = (event, context, callback) => {
var message_body = JSON.parse(event.body);
let encodedImage = message_body.base64;
let decodedImage = Buffer.from(encodedImage, 'base64');
var params = {
"Body": decodedImage,
"Bucket": "testbucket1-bucket",
"Key": "testkey1.jpg"
};
console.log("function triggered. ");
s3.upload(params).promise()
.then(data => {
console.log('complete:PUT Object',data);
callback(null, data);
})
.catch(err => {
console.log('failure:PUT Object', err);
callback(err);
});
};
In Cloudwatch, there are no errors in the entire function. I've made sure the function has access to s3, the bucket is public, and the bucket name is correct numerous times. It just times out after 30 seconds. Neither of the s3.upload() callback methods are being fired and I can't for the life of me figure out why.
Issue Identified
....I just figured out the problem after wasting so much time. My Lambda function had a VPC that didn't grant access to S3.... Now the function is not timing out, and the upload finally is working.
userData['event_photo'] = 'FUNCTION TRIGGERED';And you are also saying that S3.upload() doesn't saysUpload FailednorUpload worked?