aws / aws/aws-lambda-go

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

Open
#389 0 comments 0 reactions 0 assignees View on GitHub
troubleshooting
Dominant language
Go
Stars
3.8k
Forks
578
Avg merge
8h 18m
Merged PRs (30d)
1

Description

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:
``` go
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:
```json
{
"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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.