Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the queue parameter and logs in lambda func #25

Merged
merged 3 commits into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ Buildkite > (Pipeline) > ScheduledJobsCount
Buildkite > (Pipeline) > UnfinishedJobsCount
```

## AWS Lambda

An AWS Lambda bundle is created and published as part of the build process.

It's entrypoint is `handler.handle`, it requires a `python2.7` environment and makes use of the following env vars:

- BUILDKITE_ORG
- BUILDKITE_TOKEN
- BUILDKITE_BACKEND
- BUILDKITE_QUEUE

Checkout https://github.com/buildkite/elastic-ci-stack-for-aws/blob/master/templates/metrics.yml for examples of usage.

## License

See [LICENSE.md](LICENSE.md) (MIT)
11 changes: 6 additions & 5 deletions lambda.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bytes"
"encoding/json"
"log"
"os"
Expand All @@ -15,12 +14,10 @@ import (
)

func handle(evt json.RawMessage, ctx *runtime.Context) (interface{}, error) {
output := &bytes.Buffer{}
log.SetOutput(output)

org := os.Getenv("BUILDKITE_ORG")
token := os.Getenv("BUILDKITE_TOKEN")
backendOpt := os.Getenv("BUILDKITE_BACKEND")
queue := os.Getenv("BUILDKITE_QUEUE")

config, err := buildkite.NewTokenConfig(token, false)
if err != nil {
Expand All @@ -35,6 +32,10 @@ func handle(evt json.RawMessage, ctx *runtime.Context) (interface{}, error) {
Historical: time.Hour * 24,
})

if queue != "" {
col.Queue = queue
}

var bk backend.Backend
if backendOpt == "statsd" {
bk, err = backend.NewStatsDBackend(os.Getenv("STATSD_HOST"), strings.ToLower(os.Getenv("STATSD_TAGS")) == "true")
Expand All @@ -58,7 +59,7 @@ func handle(evt json.RawMessage, ctx *runtime.Context) (interface{}, error) {
}

log.Printf("Finished in %s", time.Now().Sub(t))
return output.String(), nil
return "", nil
}

func init() {
Expand Down