5

I have a lambda function that is invoked with API Gateway. The function is working using the GET method with this code:

func handleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {

    // add code here

    return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
}

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

I have this event.APIGatewayProxyRequest and GET method. But when I try to migrate the URL to a Function URLs, I have nothing similar to set the GET method. How was the URL supposed to know which method to use in the POSTMAN? and...

Do we have an equivalent for event.APIGatewayProxyRequest to do the request?

When I invoke it with URL, I got a 502 BAD GATEWAY error.

1 Answer 1

12

The AWS event for Lambda Function URL is events.LambdaFunctionURLRequest and the related types.

So your handler signature should look like:

func handleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error) {
    // add code here
    return events.LambdaFunctionURLResponse{Body: request.Body, StatusCode: 200}, nil
}

Once you create the URL of your Lambda, the caller (e.g. Postman) can specify whatever HTTP method, which you can access inside your handler with:

// request is LambdaFunctionURLRequest
request.RequestContext.HTTP.Method
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.