awslabs / aws-lambda-go-api-proxy

lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin (https://gin-gonic.github.io/gin/ ) to AWS Lambda and Amazon API Gateway.
Apache License 2.0
1.04k stars 197 forks source link

Lambda - using gateway 301 error #77

Open felix0324324 opened 3 years ago

felix0324324 commented 3 years ago

i had added follow sameple code, zip and upload to aws lambda but its not work for me... Any suggestion please?

[

螢幕截圖 2020-09-23 下午12 48 38

](url)

螢幕截圖 2020-09-23 下午12 48 53

import (
    "fmt"
    "log"
    "net/http"
    "os"

    "github.com/apex/gateway"
)

func main() {
    http.HandleFunc("/", hello)
    log.Fatal(gateway.ListenAndServe(":3000", nil))
}

func hello(w http.ResponseWriter, r *http.Request) {
    // example retrieving values from the api gateway proxy request context.
    requestContext, ok := gateway.RequestContext(r.Context())
    if !ok || requestContext.Authorizer["sub"] == nil {
        fmt.Fprint(w, "Hello World from Go")
        return
    }

    userID := requestContext.Authorizer["sub"].(string)
    fmt.Fprintf(w, "Hello %s from Go", userID)
}