Telegraf as a AWS Lambda function

My requirement is to replicate metric values from CloudWatch to InfluxDB. I really don’t want to manage servers, so opsless/serverless deployment is prefered. Telegraf with CloudWatch input plugin is a good candidate. But it is not serverless solution.

Has anyone any hackish recommendation how to run Telegraf as a stateless function and not as a daemon? I have already checked the common sources (GitHub, Google), but without any success.

Thx

It isn’t possible today, this feature request seems relevant, perhaps you could share your use case on that issue?

Thanks. It is similar, but it’s still about the app. I will need golang module/package. Something, what I can just “include” and use in my Lambda:

package main

import (
        "fmt"

        "github.com/aws/aws-lambda-go/lambda"
        "github.com/influxdata/telegraf"
)

func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
        config := ...
        telegraf := telegraf.New(config)
        telegraf.addPlugin("github.com/influxdata/telegraf/plugins/cloudwatch")
        ...
        return fmt.Sprintf("Hello %s!", telegraf.run() ), nil
}

func main() {
        lambda.Start(HandleRequest)
}

You might be able to hack it together but you would need to move some code out of the internal package. Check cmd/telegraf/telegraf.go to see how to create a agent.Agent using a config.Config. Also, this code does not have a stable API, even if it is publically exported, and in fact there is some ongoing work right now that will switch some code around. The only public API we maintain backwards compatibility for is the config file.

This issue may be more relevant:

1 Like