1

When using serverless offline, logs aren't logged to console instead returned as an HTTP response when triggered as an endpoint

serverless.yml

service: go-sls # Define your service name

provider:
  name: aws
  runtime: go1.x
  region: eu-central-1 # Put your AWS region



functions:
  health:
    handler: main.go # route to binary
    events:
      - http:
          path: /health
          method: get
          cors: true
          private: false

plugins:
  - serverless-offline

main.go

package main

import (
    "context"
    "fmt"
    "log"

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

type Response events.APIGatewayProxyResponse

func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
    log.Println("trying log")
    fmt.Println("it prints")
 return events.APIGatewayProxyResponse{Body: "It works!", StatusCode: 200}, nil
}

func main() {
 lambda.Start(Handler)
}

Result fmt.Println isn't logged to the console log.Println is returned as an http response postman screenshot

Expected Behavior Both it prints and trying log should be logged to the console

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.