dongxi1320 2018-08-20 22:33
浏览 57

如何使用无服务器框架处理手动调用的AWS Lambda

I am manually invoking my lambda function since the 30s HTTP gateway timeout is too short for my purpose. The function was working when using HTTP, but when I manually invoke the function, the request.Body is empty.

Here is the handler on my lambda code:

func handler(request events.APIGatewayProxyRequest) 
    (events.APIGatewayProxyResponse, error) {
    // Left out implementation details.
    // request.Body == "" here
}

Here is how I invoke it:

func InvokeHooknode(req *HooknodeReq) error {
    // Serialize params
    payload, err := json.Marshal(*req)
    if err != nil {
        return err
    }

    // Invoke lambda.
    client := lambda.New(sess)
    res, err := client.Invoke(&lambda.InvokeInput{
        FunctionName: aws.String(hooknodeFnName),
        Payload:      payload,
    })
    if err != nil {
        return err
    }

    return nil
}

I've printed out payload, and it looks correct. I'm just not sure how to access the payload in my lambda handler.

  • 写回答

1条回答 默认 最新

  • dongqiya9552 2018-08-21 00:11
    关注

    Check the region that this function is in, and then check the region from which you are calling the function.

    Instead of supplying the function name, insert the functions ARN as the function name.

    Payload: JSON.stringify(payload) 
    

    instead of just

    Payload: payload
    
    评论

报告相同问题?