Skip to content

Commit

Permalink
Merge pull request #5 from logzio/development
Browse files Browse the repository at this point in the history
Fail the lambda function when cant find access key in headers
  • Loading branch information
yotamloe authored May 25, 2022
2 parents 5f2c7d2 + 7c054c3 commit 0c7ecd3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
28 changes: 2 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```

7 changes: 5 additions & 2 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c7ecd3

Please sign in to comment.