Skip to content

Commit

Permalink
fix 🐛 verify that lambda context was found
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleduigou committed Apr 3, 2024
1 parent f5a807a commit febeca5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"context"
"log/slog"
"os"
"testing"

"github.com/aws/aws-lambda-go/lambdacontext"
"github.com/stretchr/testify/assert"
)

type LambdaHandler struct {
Expand All @@ -25,7 +23,12 @@ func NewAWSLambdaHandler(ctx context.Context, opts *slog.HandlerOptions) slog.Ha
}

// Retrieve AWS Request ID and lambda function arn
lc, _ := lambdacontext.FromContext(ctx)
lc, found := lambdacontext.FromContext(ctx)

if !found {
return slog.NewJSONHandler(os.Stdout, opts)
}

requestID := lc.AwsRequestID
arn := lc.InvokedFunctionArn

Expand All @@ -52,4 +55,4 @@ func getLogLevel() slog.Leveler {
}

return l
}
}

0 comments on commit febeca5

Please sign in to comment.