Skip to content

Commit

Permalink
Refactor lambdaHandler function to process request
Browse files Browse the repository at this point in the history
data and print headers
  • Loading branch information
alexanderfanz authored Dec 6, 2023
1 parent 5c38ef0 commit 4b58bfe
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ package main
import (
"context"
"fmt"
"log"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)

type MyEvent struct {
Name string `json:"name"`
}
func lambdaHandler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
fmt.Printf("Processing request data for request %s.\n", request.RequestContext.RequestID)
fmt.Printf("Body size = %d.\n", len(request.Body))

func lambdaHandler(ctx context.Context, event *MyEvent) (*string, error) {
log.Printf("Received event: %v", event)
if event == nil {
return nil, fmt.Errorf("received nil event")
fmt.Println("Headers:")
for key, value := range request.Headers {
fmt.Printf(" %s: %s\n", key, value)
}
message := fmt.Sprintf("Hello %s!", event.Name)
return &message, nil

return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
}

func main() {
Expand Down

0 comments on commit 4b58bfe

Please sign in to comment.