Skip to content

Issue: Parsing (Unmarshal) ALBTargetGroupRequest request body triggered by ALB with gRPC #389

Open
@elad-da

Description

@elad-da

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) {
	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 12 70 10 195 24 123 32 ....]

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions