Skip to content

Commit bb0bf5b

Browse files
authored
Merge pull request #9 from FireTail-io/dev
merge dev into main
2 parents f5960ee + a23577b commit bb0bf5b

File tree

4 files changed

+68
-24
lines changed

4 files changed

+68
-24
lines changed

README.md

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,16 @@ Create an account at [Firetail.App](https://firetail.app/), then:
7272

7373
### Building The Firetail AppSync Lambda
7474

75-
The Firetail AppSync Lambda is written in Go, and can be built using the standard `go build` command. First, clone the repository and change directory into `logs-handler`, where the Lambda's source is located:
76-
77-
```bash
78-
git clone [email protected]:FireTail-io/firetail-appsync-lambda.git
79-
cd firetail-appsync-lambda/logs-hander
80-
```
81-
82-
Before building the source into a binary, set `GOARCH` to `amd64` and `GOOS` to `linux` to ensure the binary will be compatible with the [Lambda Go runtime](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html):
83-
84-
```bash
85-
GOARCH=amd64 GOOS=linux
86-
```
87-
88-
Next, build the binary and output it into a `bin` directory at the root of the repository. `-ldflags="-s -w"` can be used to marginally reduce the size of the binary:
89-
90-
```bash
91-
go build -ldflags="-s -w" -o ../bin/logs-handler
92-
```
93-
94-
The [serverless.yml](./serverless.yml) provided in the root of this repository can be used to deploy this binary to Lambda, and expects the binary to be found in a `bin` directory at the root of the repository, hence `-o ../bin/logs-handler`.
95-
96-
The process of building the Firetail AppSync Lambda binary can alternatively be performed using [the Makefile at the root of this repository](./Makefile), using the `build` target:
75+
The process of building the Firetail AppSync Lambda binary can be performed using [the Makefile at the root of this repository](./Makefile), using the `build` target:
9776

9877
```bash
9978
git clone [email protected]:FireTail-io/firetail-appsync-lambda.git
10079
cd firetail-appsync-lambda
10180
make build
10281
```
10382

83+
A more in-depth explanation of how to build the Firetail AppSync Lambda from source can be found in [docs/build-from-src.md](./docs/build-from-src.md).
84+
10485

10586

10687
### Deploying The Firetail AppSync Lambda With Serverless

docs/build-from-src.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Building The Firetail AppSync Lambda From Source
2+
3+
The Firetail AppSync Lambda is written in Go, and can be built using the standard `go build` command. First, clone the repository and change directory into `logs-handler`, where the Lambda's source is located:
4+
5+
```bash
6+
git clone [email protected]:FireTail-io/firetail-appsync-lambda.git
7+
cd firetail-appsync-lambda/logs-hander
8+
```
9+
10+
Before building the source into a binary, set `GOARCH` to `amd64` and `GOOS` to `linux` to ensure the binary will be compatible with the [Lambda Go runtime](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html):
11+
12+
```bash
13+
export GOARCH=amd64 GOOS=linux
14+
```
15+
16+
Next, build the binary and output it into a `bin` directory at the root of the repository. `-ldflags="-s -w"` can be used to marginally reduce the size of the binary:
17+
18+
```bash
19+
go build -ldflags="-s -w" -o ../bin/logs-handler
20+
```
21+
22+
The [serverless.yml](./serverless.yml) provided in the root of this repository can be used to deploy this binary to Lambda, and expects the binary to be found in a `bin` directory at the root of the repository, hence `-o ../bin/logs-handler`.

logs-handler/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@ import (
66
"github.com/aws/aws-lambda-go/lambda"
77
)
88

9+
const DefaultFiretailApiUrl string = "https://api.logging.eu-west-1.prod.firetail.app/logs/aws/appsync"
10+
911
var firetailApiUrl string
1012
var firetailApiToken string
1113

14+
func loadEnvVars() {
15+
var firetailApiUrlSet bool
16+
firetailApiUrl, firetailApiUrlSet = os.LookupEnv("FIRETAIL_API_URL")
17+
if !firetailApiUrlSet {
18+
firetailApiUrl = DefaultFiretailApiUrl
19+
}
20+
firetailApiToken = os.Getenv("FIRETAIL_API_TOKEN")
21+
}
22+
1223
func main() {
13-
firetailApiUrl = "https://api.logging.eu-west-1.prod.firetail.app/logs/aws/appsync"
14-
firetailApiToken = os.Getenv("FIRETAIL_API_TOKEN")
24+
loadEnvVars()
1525
lambda.Start(Handler)
1626
}

logs-handler/main_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestLoadEnvVars(t *testing.T) {
10+
const MockFiretailApiUrl = "MOCK_FIRETAIL_API_URL"
11+
const MockFiretailApiToken = "MOCK_FIRETAIL_API_TOKEN"
12+
13+
t.Setenv("FIRETAIL_API_URL", MockFiretailApiUrl)
14+
t.Setenv("FIRETAIL_API_TOKEN", MockFiretailApiToken)
15+
16+
loadEnvVars()
17+
18+
assert.Equal(t, firetailApiUrl, MockFiretailApiUrl)
19+
assert.Equal(t, firetailApiToken, MockFiretailApiToken)
20+
}
21+
22+
func TestLoadEnvVarsApiUrlUnset(t *testing.T) {
23+
const MockFiretailApiToken = "MOCK_FIRETAIL_API_TOKEN"
24+
25+
t.Setenv("FIRETAIL_API_TOKEN", MockFiretailApiToken)
26+
27+
loadEnvVars()
28+
29+
assert.Equal(t, firetailApiUrl, DefaultFiretailApiUrl)
30+
assert.Equal(t, firetailApiToken, MockFiretailApiToken)
31+
}

0 commit comments

Comments
 (0)