From 991c4e91b066f85d7cc2e0f09a5d5d625a7cd981 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Le Duigou Date: Wed, 3 Apr 2024 19:51:16 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20verify=20that=20lambda=20?= =?UTF-8?q?context=20was=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/handler.go b/handler.go index aaa6193..4136c19 100644 --- a/handler.go +++ b/handler.go @@ -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 { @@ -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 @@ -52,4 +55,4 @@ func getLogLevel() slog.Leveler { } return l -} \ No newline at end of file +}