From 2970589db62501690bcc3d1e23e0ffe17f48af58 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Wed, 16 Aug 2023 11:08:46 +1000 Subject: [PATCH 1/2] auto decode binary media types. --- cloud/aws/runtime/gateway/lambda.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cloud/aws/runtime/gateway/lambda.go b/cloud/aws/runtime/gateway/lambda.go index 5dc9fcc7c..8cc3c7733 100644 --- a/cloud/aws/runtime/gateway/lambda.go +++ b/cloud/aws/runtime/gateway/lambda.go @@ -181,8 +181,21 @@ func (s *LambdaGateway) handleApiEvent(ctx context.Context, evt events.APIGatewa } } + data := []byte(evt.Body) + if evt.IsBase64Encoded { + data, err = base64.StdEncoding.DecodeString(evt.Body) + if err != nil { + return events.APIGatewayProxyResponse{ + StatusCode: 400, + Body: "Error processing lambda request", + // TODO: Need to determine best case when to use this... + IsBase64Encoded: false, + }, nil + } + } + req := &v1.TriggerRequest{ - Data: []byte(evt.Body), + Data: data, Context: &v1.TriggerRequest_Http{ Http: &v1.HttpTriggerContext{ Method: evt.RequestContext.HTTP.Method, From fb38b64ec3e6d7adcc997ce9b2524103f6147b4e Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Wed, 16 Aug 2023 11:13:16 +1000 Subject: [PATCH 2/2] cleanup TODOs --- cloud/aws/runtime/gateway/lambda.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cloud/aws/runtime/gateway/lambda.go b/cloud/aws/runtime/gateway/lambda.go index 8cc3c7733..7a8d39b98 100644 --- a/cloud/aws/runtime/gateway/lambda.go +++ b/cloud/aws/runtime/gateway/lambda.go @@ -186,9 +186,8 @@ func (s *LambdaGateway) handleApiEvent(ctx context.Context, evt events.APIGatewa data, err = base64.StdEncoding.DecodeString(evt.Body) if err != nil { return events.APIGatewayProxyResponse{ - StatusCode: 400, - Body: "Error processing lambda request", - // TODO: Need to determine best case when to use this... + StatusCode: 400, + Body: "Error processing lambda request", IsBase64Encoded: false, }, nil } @@ -233,10 +232,9 @@ func (s *LambdaGateway) handleApiEvent(ctx context.Context, evt events.APIGatewa responseString := base64.StdEncoding.EncodeToString(response.Data) return events.APIGatewayProxyResponse{ - StatusCode: int(response.GetHttp().Status), - Headers: lambdaHTTPHeaders, - Body: responseString, - // TODO: Need to determine best case when to use this... + StatusCode: int(response.GetHttp().Status), + Headers: lambdaHTTPHeaders, + Body: responseString, IsBase64Encoded: true, }, nil }