I'm struggling to properly connect API Gateway to a simple Go Lambda I've configured.
The Lambda is a really simple function like:
func foo(bar string) (string, error) {
return fmt.Println(bar)
}
func main() {
lambda.Start(foo)
}
I can do a simple test event with a value of "HelloWorld" and it returns as expected.
However, I can't seem to figure out out how to set up API Gateway to allow me to either just call /HelloWorld or ?bar=HelloWorld and have it return. I know I can use events.APIGatewayProxyRequest as an argument and return events.APIGatewayProxyResponse, but is there no other way? It would seem that doing that pigeon holes me into ONLY accessing this function via API Gateway, which seems silly.
Your Lambda function should have a valid signature in order to be triggered by API Gateway or any other event sources. In case of API Gateway, your Lambda function handler will look like this:
func handler(ctx context.Context, request events.APIGatewayProxyRequest (events.APIGatewayProxyResponse, error) {
}
you can get the parameters from request
, call your foo
function with proper parameter and return a APIGatewayProxyResponse. This way your foo
function only does what it is supposed to do and knows nothin about AWS events and your handler
function is in charge of communication with API Gateway.