3

我正在使用 localstack 并试图让我的 lambda 的 s3 调用工作。我可以成功地从 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

我希望在 localstack 中看到与直接通过 cli 调用 lambda 时看到的相同的输出。相反,看起来 lambda 实际上并没有被调用。Localstack 只是说 mylambda 执行了异步,没有任何明显的事情发生。

有人可以指出我错过了什么吗?

谢谢!

4

0 回答 0