无法通过AWS CLI从LocalStack调用Lambda函数

时间:2018-08-11 21:26:36

标签: amazon-web-services aws-lambda atlassian-localstack aws-lambda-go

根据下面的命令/输出,我在本地堆栈中看到了lambda函数推送

 aws lambda get-function --function-name books1 --endpoint-url=http://localhost:4574
{
    "Code": {
        "Location": "http://localhost:4574/2015-03-31/functions/books1/code"
    }, 
    "Configuration": {
        "Version": "$LATEST", 
        "FunctionName": "books1", 
        "CodeSize": 50, 
        "FunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:books1", 
        "Environment": {}, 
        "Handler": "main", 
        "Runtime": "go1.x"
    }
}

当我尝试执行它时,如下所示,我得到一个错误,并且我的本地堆栈正在docker容器中运行

aws --endpoint-url = http://localhost:4574 lambda调用--function-name books1 /tmp/output.json

An error occurred (InternalFailure) when calling the Invoke operation (reached max retries: 4): Error executing Lambda function: Unable to find executor for Lambda function "books1". Note that Node.js and .NET Core Lambdas currently require LAMBDA_EXECUTOR=docker Traceback (most recent call last):
  File "/opt/code/localstack/localstack/services/awslambda/lambda_api.py", line 269, in run_lambda
    event, context=context, version=version, asynchronous=asynchronous)
  File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 466, in execute
    process.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 462, in do_execute
    result = lambda_function(event, context)
  File "/opt/code/localstack/localstack/services/awslambda/lambda_api.py", line 390, in generic_handler
    'Note that Node.js and .NET Core Lambdas currently require LAMBDA_EXECUTOR=docker') % lambda_name)
Exception: Unable to find executor for Lambda function "books1". Note that Node.js and .NET Core Lambdas currently require LAMBDA_EXECUTOR=docker

此lambda是用Go编写的,当我在真正的AWS上手动执行时,它就可以正常工作。

1 个答案:

答案 0 :(得分:0)

您应在传递的LAMBDA_EXECUTOR=docker环境和/var/run/docker.sock:/var/run/docker.sock卷的情况下运行localstack容器

docker run \
  -itd \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e LAMBDA_EXECUTOR=docker \
  -p 4567-4583:4567-4583 -p 8080:8080 \
  --name localstack \
  localstack/localstack