我正在使用localstack并尝试使s3调用我的lambda工作。我可以从cli成功调用lambda,而s3似乎正在尝试,但是什么也没发生。
我使用以下命令创建了lambda:
$ awslocal lambda create-function --function-name mylambda-local --zip-file fileb://mylambda.zip --handler mylambda --runtime go1.x --role somerole
{
"FunctionName": "mylambda-local",
"FunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:mylambda-local",
"Runtime": "go1.x",
"Role": "somerole",
"Handler": "mylambda",
"CodeSize": 7968172,
"Description": "",
"Timeout": 3,
"LastModified": "2019-08-22T15:16:32.638+0000",
"CodeSha256": "jyMyhp6H2FryoUGqH1Pyj911KIZO66KLnJs6cWGVb84=",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "028c8385-ec67-4fe4-b77a-5db05282005a"
}
然后我从cli调用我的lambda,如下所示:
$ awslocal lambda invoke --function-name mylambda-local --payload='{}' out --log-type Tail
{
"StatusCode": 200
}
在localstack中,我看到此输出。我的日志消息是“ Lambda开始”和“接收到S3事件”,所以我知道到目前为止它可以正常工作。
localstack_1 | 2019-08-22T15:54:56:DEBUG:localstack.services.awslambda.lambda_executors: Lambda arn:aws:lambda:us-east-1:000000000000:mylambda-local result / log output:
localstack_1 | null
localstack_1 | >{"level":"info","msg":"Lambda starting","time":"2019-08-22T15:54:56Z"}
localstack_1 | > START RequestId: 6d2cc238-bc8f-1d42-17d7-10a95d4d2109 Version: $LATEST
localstack_1 | > {"level":"info","msg":"S3 event received","time":"2019-08-22T15:54:56Z"}
localstack_1 | > END RequestId: 6d2cc238-bc8f-1d42-17d7-10a95d4d2109
localstack_1 | > REPORT RequestId: 6d2cc238-bc8f-1d42-17d7-10a95d4d2109 Duration: 1.05 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 10 MB
接下来,我创建我的存储桶,设置事件通知并推送文件。
$ awslocal s3 mb s3://test-bucket
$ awslocal s3api put-bucket-notification-configuration --bucket test-bucket --notification-configuration file://notification.json
$ awslocal s3api get-bucket-notification-configuration --bucket test-bucket
{
"LambdaFunctionConfigurations": [
{
"Id": "bfc3da24-6b82-4f03-b5dc-03e49f4059b6",
"LambdaFunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:mylambda-local",
"Events": [
"s3:ObjectCreated:*"
],
"Filter": {}
}
]
}
$ awslocal s3 cp test.txt s3://test-bucket
这时,我在localstack中看到了以下内容。它看起来像是在试图调用我的lambda。所有的lambda执行跟踪看起来都与我直接运行它时发生的事情相同,但似乎什么也没有发生。
localstack_1 | 2019-08-22 15:17:33,314:API: 127.0.0.1 - - [22/Aug/2019 15:17:33] "PUT /test-bucket/test.txt HTTP/1.1" 200 -
localstack_1 | 2019-08-22 15:17:33,341:API: 172.18.0.2 - - [22/Aug/2019 15:17:33] "GET / HTTP/1.1" 404 -
localstack_1 | 2019-08-22 15:17:33,348:API: 172.18.0.2 - - [22/Aug/2019 15:17:33] "POST / HTTP/1.1" 200 -
localstack_1 | 2019-08-22 15:17:33,354:API: 172.18.0.2 - - [22/Aug/2019 15:17:33] "POST / HTTP/1.1" 200 -
localstack_1 | 2019-08-22 15:17:33,361:API: 172.18.0.2 - - [22/Aug/2019 15:17:33] "POST / HTTP/1.1" 200 -
localstack_1 | 2019-08-22 15:17:33,368:API: 172.18.0.2 - - [22/Aug/2019 15:17:33] "POST / HTTP/1.1" 200 -
localstack_1 | 2019-08-22T15:17:33:DEBUG:localstack.services.awslambda.lambda_executors: Running lambda cmd: CONTAINER_ID="$(docker create -e AWS_LAMBDA_EVENT_BODY="$AWS_LAMBDA_EVENT_BODY" -e HOSTNAME="$HOSTNAME" -e LOCALSTACK_HOSTNAME="$LOCALSTACK_HOSTNAME" -e AWS_LAMBDA_FUNCTION_NAME="$AWS_LAMBDA_FUNCTION_NAME" -e AWS_LAMBDA_FUNCTION_VERSION="$AWS_LAMBDA_FUNCTION_VERSION" -e AWS_LAMBDA_FUNCTION_INVOKED_ARN="$AWS_LAMBDA_FUNCTION_INVOKED_ARN" "lambci/lambda:go1.x" "mylambda")";docker cp "/tmp/localstack/zipfile.45928c79/." "$CONTAINER_ID:/var/task"; docker start -a "$CONTAINER_ID";
localstack_1 | 2019-08-22T15:17:33:DEBUG:localstack.services.awslambda.lambda_executors: Lambda arn:aws:lambda:us-east-1:000000000000:function:mylambda-local result / log output:
localstack_1 | {"asynchronous": "True"}
localstack_1 | >Lambda executed asynchronously
我期望在本地堆栈中看到与直接通过cli调用lambda时看到的相同输出。相反,看起来lambda实际上没有被调用。 Localstack刚刚说mylambda执行了异步操作,但显然没有发生任何事情。
有人可以指出我错过的内容吗?
谢谢!