Skip to content

Commit

Permalink
Merge pull request #25 from buildkite/add-queue-to-lambda
Browse files Browse the repository at this point in the history
Support the queue parameter and logs in lambda func
  • Loading branch information
lox authored Dec 20, 2016
2 parents 1e478dc + ba24f8e commit f328dca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
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

0 comments on commit f328dca

Please sign in to comment.