-
Notifications
You must be signed in to change notification settings - Fork 9
/
lambda.go
37 lines (31 loc) · 863 Bytes
/
lambda.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"context"
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"log"
)
type myReturn struct {
Response string `json:"response"`
}
func handle(ctx context.Context, name events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
log.Print("Request body: ", name)
log.Print("context ", ctx)
headers := map[string]string{"Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"}
code := 200
response, err := json.Marshal(myReturn{Response:"Hello, " + name.Body})
if err != nil {
log.Println(err)
response = []byte("Internal Server Error")
code = 500
}
return events.APIGatewayProxyResponse {
StatusCode: code,
Headers: headers,
Body: string(response),
}, nil
}
func main() {
lambda.Start(handle)
}