Skip to content

Instantly share code, notes, and snippets.

@Konboi
Created January 30, 2018 04:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Konboi/2c5c735ce2f9f966515abc3b566c2c2e to your computer and use it in GitHub Desktop.
Save Konboi/2c5c735ce2f9f966515abc3b566c2c2e to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-lambda-go/lambdacontext"
)
type Request struct {
Body string `json:"body"`
}
type Response struct {
Body string `json:"body"`
Time time.Time `json:"time"`
}
type ErrorResponse struct {
Message string `json:"message"`
Time time.Time `json:"time"`
}
func (er *ErrorResponse) Error() string {
return fmt.Sprintf("error:%s at:%s", er.Message, er.Time.String())
}
func main() {
lambda.Start(EchoHandler)
}
func EchoHandler(ctx context.Context, req *Request) (*Response, error) {
lctx, ok := lambdacontext.FromContext(ctx)
if !ok {
return nil, &ErrorResponse{
Message: "FromContextError",
Time: time.Now(),
}
}
log.Printf("lambda ctx info:%+v", lctx)
return &Response{
Body: req.Body,
Time: time.Now(),
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment