1

I'm struggling to get any sort of response from ListFunctions that isn't null. I have 3 functions in a single region and have played around with the params and AWS.config.region a fair bit. I'm consistently getting null as a return and in my console logs, I don't get anything back. Any help would be greatly appreciated!

let AWS = require('aws-sdk');
//AWS.config.region = 'ca-central-1';
let lambda = new AWS.Lambda({ "apiVersion": "2015-03-31" });

module.exports.handler = async (event, context) => {
  let params = {
    //MasterRegion: 'ALL',
    //FunctionVersion: 'ALL',
    MaxItems: 10
  };

  lambda.listFunctions(params, function(err,data) {
    if(err){
      console.log(err);
    }
    else {
      console.log(data);
    }
    context.done(null, "function finished");
  }
}

serverless.yml changes

provider:
  name: aws
  runtime: nodejs8.10
  profile: [PROFILE_NAME]
  region: [ca-central-1]
  iamRoleStatements:
  - Effect: "Allow"
    Action:
      - "lambda:*"
    Resource:
      - "*"
2
  • Try making your function not async. When it's marked as async and the function returns it returns that values. You don't have an explicit return but nodejs returns undefined if a function ends without an explicit return value. Commented Nov 21, 2018 at 20:42
  • And there it is..... thank you kind sir. Commented Nov 21, 2018 at 20:49

1 Answer 1

3

Make your function not be async. When it's marked as async and the handler function returns, lambda returns that value. You don't have an explicit return but nodejs returns undefined if a function ends without an explicit return value.

You can also switch from using callbacks

module.exports.handler = async (event, context) => {
  let params = {
    //MasterRegion: 'ALL',
    //FunctionVersion: 'ALL',
    MaxItems: 10
  };

  try {
    let result = await lambda.listFunctions(params).promise() {
    console.log(result);
  } catch (err) {
    console.log(err);
    throw err; // this try catch isn't really necessary 
  }
  return "function finished";
}
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.