2

I am trying to run a lambda function attached to an API gateway GET request and below is the code

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

const bucketName = "dhaval-upload";

let params = {
        Bucket: bucketName, 
        Key: event.fileName
};

exports.handler = async (event, context, callback) => {
    return await s3.getObject(params).promise()
    .then((res) => {
        return "abcd";
        // return res.Body.toString('utf-8');
    })
    .catch((err) => {
        return err;
    });
};

but I am getting the below error

errorMessage: "event is not defined"
errorType: "ReferenceError"

But I don't understand the reason for this as I have another POST request running perfectly..

Any help will be highly appreciated

1
  • 1
    Look at the definition of params, event is not defined up there. Commented Dec 13, 2018 at 17:53

1 Answer 1

2

You need to place params inside your handler, like this:

exports.handler = async (event, context, callback) => {

    let params = {
        Bucket: bucketName, 
        Key: event.fileName
    };

    return await s3.getObject(params).promise()
    .then((res) => {
        return "abcd";
        // return res.Body.toString('utf-8');
    })
    .catch((err) => {
        return err;
    });
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.