3

I'm trying to parse the request body from the events.ALBTargetGroupRequest in my lambda function.

I couldn't find any example or explanation on how should I parse this binary data. My thought was that I would get a proto and just Unmarshal it, but that's not the case. The flow is gRPC-->ALB-->Lambda.

Lambda Code Example:

func HandleRequest(ctx context.Context, request events.ALBTargetGroupRequest) (events.ALBTargetGroupResponse, error) {
    // Assume body is base64 encoded
    bt, err := base64.StdEncoding.DecodeString(request.Body)
    if err != nil {
        log.Printf("Failed to decode body: %s\n", err.Error())
        return events.ALBTargetGroupResponse{}, err
    }

    msg := pb.Msg{}
    err = proto.Unmarshal(bt, &msg)
    if err != nil {
        log.Printf("Failed to unmarshal body: %s\n", err.Error())
        return events.ALBTargetGroupResponse{}, err
    }

    return events.ALBTargetGroupResponse{Body: "", StatusCode: 200, StatusDescription: "200 OK", IsBase64Encoded: false, Headers: map[string]string{}}, nil
}

func main() {
    lambda.Start(HandleRequest)
}

Headers:

{
    "accept-encoding": "identity,gzip",
    "content-type": "application/grpc",
    "grpc-accept-encoding": "identity,deflate,gzip",
    "grpc-timeout": "353S",
    "te": "trailers",
    "user-agent": "grpc-c++/1.16.0 grpc-c/6.0.0 (linux; chttp2; gao)",
    "x-amzn-trace-id": "Root=1-6124edf6-4fa33c5674127c7266ba0430"
}

Error:

Failed to Unmarshal body:  proto: cannot parse invalid wire-format data
proto: cannot parse invalid wire-format data: prefixError

Byte array: (if it helps)

[0 0 0 0 85 10 83 10 43 105 112 45 49 48 45 49 54 53 45 50 50 53 45 55 53 46 101 117 45 119 101 115 116 45 50 46 99 111 109 112 117 116 101 46 105 110 116 101 114 110 97 108 18 36 102 56 56 56 101 100 53 99 45 54 102 99 51 45 52 99 54 99 45 56 49 99 55 45 55 53 101 100 48 99 57 50 54 102 50 53]

I would appreciate if someone can shed some light on this subject.

Elad
  • 664
  • 1
  • 5
  • 14

0 Answers0