Go Lambda function no request body from docker

Viewed 33

I am trying to deploy Go in a dockerized lambda function that responds to LambdaFunctionURLRequest. When I test locally I do not get the request body.

If I deploy a normal zip to lambda it works just fine. I do get the error back and the docker does print
Here is the basic code + docker
main.go

package main

import (
    "context"
    "errors"
    "log"
    "net/http"
    "time"
    "github.com/aws/aws-lambda-go/events"
    "github.com/aws/aws-lambda-go/lambda"
)

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

func init() {
    log.Println("Init Function")
}

func HandleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (ev events.LambdaFunctionURLResponse, err error) {
    log.Println("Received Handle Request")
    log.Println(request.Body)
    if request.Body == ""{
        return ev, errors.New("No request body")
    }
    return
}

Docker

FROM golang AS build
WORKDIR /app
COPY . .
RUN go mod download
RUN go build -o main

ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie
RUN chmod 755 /usr/bin/aws-lambda-rie
COPY entry.sh /
RUN chmod 755 /entry.sh
ENTRYPOINT [ "/entry.sh" ]

Entry.sh

#!/bin/sh
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
  exec /usr/bin/aws-lambda-rie "./main"
else
  exec "$@"
fi  

Curl

curl --location --request POST 'http://localhost:9000/2015-03-31/functions/function/invocations' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Hello There": "Some Data"
}'
0 Answers
Related