up icon indicating copy to clipboard operation
up copied to clipboard

None of the variables come through in an Lambda Invoke

Open iamtomcat opened this issue 6 years ago • 6 comments

Prerequisites

  • [x] I am running the latest version. (up upgrade)
  • [x] I searched to see if the issue already exists.
  • [x] I inspected the verbose debug output with the -v, --verbose flag.
  • [x] Are you an Up Pro subscriber?

Description

When I invoke a function through the lambda interface it seems to call it just fine, but none of the variables passed in make it through with the request. Just trying to see if I missed something in the setup.

Steps to Reproduce

Attached is the code I used.

package main

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

func main() {
	addr := ":" + os.Getenv("PORT")
	http.HandleFunc("/", hello)
	log.Fatal(http.ListenAndServe(addr, nil))
}

func hello(w http.ResponseWriter, r *http.Request) {
	requestDump, err := httputil.DumpRequest(r, true)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(requestDump))

	fmt.Fprintln(w, "Hello World from Go")
}

Log Output

 Nov 3rd 11:39:25am INFO staging $LATEST initializing
  Nov 3rd 11:39:25am INFO staging $LATEST starting app: PORT=35577 command=./server
  Nov 3rd 11:39:25am INFO staging $LATEST started app
  Nov 3rd 11:39:25am INFO staging $LATEST waiting for app to listen on PORT
  Nov 3rd 11:39:25am INFO staging $LATEST app listening: duration=254ms
  Nov 3rd 11:39:25am INFO staging $LATEST initialized: duration=257ms
  Nov 3rd 11:39:25am INFO staging $LATEST request: method=GET
  Nov 3rd 11:39:25am INFO staging $LATEST response: duration=19ms method=GET size=20 B status=200  Nov 3rd 11:39:25am INFO REPORT RequestId: 26347803-def0-11e8-81ce-6bbe7f8a55e9        Duration: 486.31 ms     Billed Duration: 500
 ms     Memory Size: 512 MB     Max Memory Used: 67 MB
  Nov 3rd 11:44:30am INFO staging $LATEST initializing
  Nov 3rd 11:44:30am INFO staging $LATEST starting app: PORT=36071 command=./server
  Nov 3rd 11:44:30am INFO staging $LATEST started app
  Nov 3rd 11:44:30am INFO staging $LATEST waiting for app to listen on PORT
  Nov 3rd 11:44:30am INFO staging $LATEST app listening: duration=250ms
  Nov 3rd 11:44:30am INFO staging $LATEST initialized: duration=251ms
  Nov 3rd 11:44:30am INFO staging $LATEST request: method=GET
  Nov 3rd 11:44:30am INFO staging $LATEST GET / HTTP/1.1
  Nov 3rd 11:44:30am INFO staging $LATEST Host: 127.0.0.1:36071
  Nov 3rd 11:44:30am INFO staging $LATEST Connection: close
  Nov 3rd 11:44:30am INFO staging $LATEST Accept-Encoding: gzip
  Nov 3rd 11:44:30am INFO staging $LATEST Connection: close
  Nov 3rd 11:44:30am INFO staging $LATEST X-Context: {"apiId":"","resourceId":"","requestId":"","accountId":"","stage":"","identity":{"apiKey":"","accountId":"","userAgent":"","sourceIp":"","accessKey":"","caller":"","user":"","userARN":"","cognitoIdentityId":"","cognitoIdentityPoolId":"","cognitoAuthenticationType":"","cognitoAuthenticationProvider":""},"authorizer":null}
  Nov 3rd 11:44:30am INFO staging $LATEST X-Request-Id:
  Nov 3rd 11:44:30am INFO staging $LATEST X-Stage:
  Nov 3rd 11:44:30am INFO staging $LATEST
  Nov 3rd 11:44:30am INFO staging $LATEST
  Nov 3rd 11:44:30am INFO staging $LATEST response: duration=8ms method=GET size=20 B status=200
  Nov 3rd 11:44:30am INFO REPORT RequestId: dbce075b-def0-11e8-af74-2f6feb99ce1f        Duration: 478.90 ms     Billed Duration: 500 ms     Memory Size: 512 MB     Max Memory Used: 41 MB

iamtomcat avatar Nov 02 '18 22:11 iamtomcat

hmm yeah might be a little tricky, you'd have to craft the right object to match what API Gateway would invoke Lambda with, then it shoulddddd be ok. https://github.com/apex/up/blob/master/internal/proxy/request.go can maybe provide a bit of insight there

tj avatar Nov 02 '18 23:11 tj

Cool I'll take a look into it.

iamtomcat avatar Nov 03 '18 00:11 iamtomcat

Just wondering where would I build this object. Trying to figure out the flow. Seems like currently js shim -> main (which I'm assuming is the proxy) -> server (my go code).

Maybe I'm just missing something here.

iamtomcat avatar Nov 03 '18 03:11 iamtomcat

Your plan was to skip API Gateway? If I understand that right then you'd have to invoke with that object, althoughhhh I'm actually not sure if it's even possible to popular the context object manually, that would be in AWS' / API Gateway's control I'd think.

tj avatar Nov 04 '18 01:11 tj

Yeah it's kind of a one off thing I'm trying to do. Just writing a lamda authenticator for auth0.

https://github.com/PayNoMind/lambda-authenticator

I got it working by switching the handler to be main and use go runtime directly. Also still grabs all the logs and etc, which is nice.

I've got another project that I'm working on getting up working with that is going through the api gateway.

iamtomcat avatar Nov 04 '18 22:11 iamtomcat

Ah So I think I figured out what the issue is, the type events that come through aren't always Api Gateway requests. So I have to look into extending the proxy to support other types.

iamtomcat avatar Dec 31 '18 04:12 iamtomcat