Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Support V2 payloads for Echo #104

Merged
merged 1 commit into from
Dec 21, 2021
Merged

Support V2 payloads for Echo #104

merged 1 commit into from
Dec 21, 2021

Conversation

AlexLast
Copy link
Contributor

Issue #, if available:

Description of changes:
Adds support for API Gateway HTTP V2 payloads for the Echo framework

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

echo/adapter.go Outdated
@@ -17,6 +17,7 @@ import (
// creates a proxy response object from the http.ResponseWriter
type EchoLambda struct {
core.RequestAccessor
v2 core.RequestAccessorV2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to separate V2 like the Gin adapter (since that is already in) - https://github.com/awslabs/aws-lambda-go-api-proxy/tree/master/gin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@speza I used #100 as an example, which was also merged. But happy to refactor if that is the preferred way of adding V2 support?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't see that one! I think my personal preference would be separate. But it appears there is not any consistency!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing as Gin is one of the main framework examples for this project I think it makes sense to follow the same pattern, will refactor 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have refactored to match the pattern set in the Gin adapter

@yasuoza
Copy link

yasuoza commented Nov 10, 2021

Any update for this PR?
This works fine for me.

@AlexLast
Copy link
Contributor Author

Any update for this PR? This works fine for me.

@yasuoza Unfortunately It's still waiting for a review, currently I'm just using my own build

@yasuoza
Copy link

yasuoza commented Nov 26, 2021

FYI: Bypass to echo.ServeHTTP also works. This may be useful until this PR is merged.

package main

import (
	"context"
	"log"
	"net/http"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
	"github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc"
	"github.com/labstack/echo/v4"
)

var (
	httpLambda *handlerfunc.HandlerFuncAdapterV2
)

func init() {
	// stdout and stderr are sent to AWS CloudWatch Logs
	log.Printf("echo cold start")
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		return c.JSON(http.StatusOK, map[string]string{"message": "pong"})
	})

	httpLambda = handlerfunc.NewV2(e.ServeHTTP)
}

// Handler handles request from API Gateway V2
func Handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
	return httpLambda.ProxyWithContext(ctx, req)
}

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

@sapessi sapessi merged commit f6f827b into awslabs:master Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants