From 7c054c3bc9a2ddf93e726f9dd24973455a4fe05a Mon Sep 17 00:00:00 2001 From: yotamloe Date: Wed, 25 May 2022 19:34:59 +0300 Subject: [PATCH] Fail the lambda function when cant find access key in headers --- README.md | 28 ++-------------------------- handler/handler.go | 7 +++++-- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index a88437d..2d5bf59 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,8 @@ # metric-stream-lambda Lambda function that receives OTLP (0.7.0) data from AWS metric stream and exports the data to logz.io using prometheus remote write -## How to create function.zip +### How to create function.zip ``` make function ``` -## Deploy to AWS with cli -After creating `function.zip` -### Dev -```shell -aws lambda update-function-code \ ---region us-east-1 \ ---function-name cloudwatch-stream-otlp-dev \ ---zip-file fileb://function.zip -``` -### Prod -```shell -aws lambda update-function-code \ ---region us-east-1 \ ---function-name cloudwatch-stream-otlp \ ---zip-file fileb://function.zip -``` -## Stream test data to cloudwatch-stream-otlp-dev function -* start stream: -```shell -aws cloudwatch start-metric-streams --names test-otel-format -``` -* stop stream: -```shell -aws cloudwatch stop-metric-streams --names test-otel-format -``` \ No newline at end of file + diff --git a/handler/handler.go b/handler/handler.go index 62bf0b5..410c1e2 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -5,6 +5,7 @@ import ( _ "context" base64 "encoding/base64" "encoding/json" + "errors" "fmt" "github.com/aws/aws-lambda-go/events" "github.com/golang/protobuf/proto" @@ -213,8 +214,10 @@ func HandleRequest(ctx context.Context, request events.APIGatewayProxyRequest) ( } if LogzioToken == "" { - log.Printf("Cant find access key in 'X-Amz-Firehose-Access-Key' or 'x-amz-firehose-access-key' headers") - return generateValidFirehoseResponse(400, requestId, "Cant find access key in 'X-Amz-Firehose-Access-Key' or 'x-amz-firehose-access-key' headers", nil), nil + message := "cant find access key in 'X-Amz-Firehose-Access-Key' or 'x-amz-firehose-access-key' headers" + err := errors.New(message) + log.Printf(message) + return generateValidFirehoseResponse(400, requestId, message, err), err } // Initializing prometheus remote write exporter