I am creating a lambda function which I've tied to API gateway and my code doesn't seem to fire the s3.putObject event.
I can console.log the AWS, s3, params variables with no problems but when trying to use the putObject function, nothing fires...the rest of my code simply seems to run.
Does anyone know what I might need to do?
I've set a region on my s3 instance, an API version Logged out my variables Checked cloudwatch logs for changes
exports.handler = async (event) => {
const AWS = require('aws-sdk');
const s3 = new AWS.S3({region: "us-east-1", apiVersion: '2006-03-01'});
const params = {
Bucket: bucketName,
Key: 'file.txt',
ContentType: 'text/plain',
Body: JSON.stringify(event)};
// The below doesn't seem to run or log out
s3.putObject(params).promise().then(data => {
console.log('complete:PUT Object',data);
})
.catch(err => {
console.log('failure:PUT Object', err);
});
return JSON.stringify(event);
};
I expect to be able to go into my s3 bucket and see a file uploaded. Instead its empty
return JSON.stringify(event);
? If you're going to use an async handler function, don't you need to return a promise? Your Lambda invocation is finishing before theputObject
really gets started.