Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any way to handle event from api gateway to lambda ? #26

Open
xoraes opened this issue Aug 17, 2016 · 3 comments
Open

any way to handle event from api gateway to lambda ? #26

xoraes opened this issue Aug 17, 2016 · 3 comments

Comments

@xoraes
Copy link

xoraes commented Aug 17, 2016

Is there a way to handle event from api gateway to lambda ? I have no idea what the json format is for this.

@polds
Copy link

polds commented Aug 23, 2016

@xoraes The type is just a standard json.RawMessage for an API Gateway handler. Check out this functional example. It expects a json input of: {"username": "me"}

package main

import (
    "encoding/json"
    "github.com/apex/go-apex"
)

type ExampleRequest struct {
    Username string `json:"username"`
}

type ExampleResponse struct {
    Username    string `json:"username"`
    RequestID   string
}

func main() {
    apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context)) (interface{}, error) {
        var req ExampleRequest
        err := json.Unmarshal(event, &req)
        if err != nil {
            // Don't forget to handle your error
            return nil, err
        }

        return ExampleResponse{
            Username: req.Username,
            RequestID: ctx.RequestID,
        }, nil
    }
}

@xoraes
Copy link
Author

xoraes commented Aug 29, 2016

Thanks! Ah, I didn't realize until now that api gateway needed a custom template defined for the json format. Serverless seems to have the ability to push such templates as well. Wonder if that sort of functionality is being considered for apex?

@polds
Copy link

polds commented Aug 29, 2016

For full swagger and SDK support API Gateway does require this. But more often than not you can get away with not defining templates.

That said, there is a proposal on adding Gateway support with Apex. Specifically the routing layers, not specifically the templating layer. Check out apex/apex/issues/37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants