Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

amazon web services - Getting 'invalid reference format' error on localstack when use 'aws lambda invoke'

I'm using localstack/terraform/aws (latest versions) to play with lambda on aws locally. The configuration can be found here https://github.com/wentao-daommo/aws-local

While I can successfully setup/deploy everything and list my lambda function via 'aws lambda list-functions'. I was unable to invoke the function with command

aws --endpoint-url=http://localhost:4566 lambda invoke --function-name=handler --payload='' test.json

From the command line, I got error

{
    "StatusCode": 200,
    "FunctionError": "Unhandled",
    "LogResult": "",
    "ExecutedVersion": "$LATEST"
}
question from:https://stackoverflow.com/questions/65895930/getting-invalid-reference-format-error-on-localstack-when-use-aws-lambda-invo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your handler is incorrect and you are missing runtime. I would also recommend using standard main.js in the form of:

exports.handler = async (event) => {
    return {
        statusCode: 200,
        body: JSON.stringify("Hi from lambda on localstack")
    }
};

Then, your aws_lambda_function with correct handler and runtime should be:

resource "aws_lambda_function" "lambda" {
  filename      = "lambda_file.zip"
  function_name = "handler"
  runtime       = "nodejs12.x"
  role          = aws_iam_role.iam_for_lambda.arn
  handler       = "main.handler"
  source_code_hash = filebase64sha256(data.archive_file.lambda_file.output_path)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...