# Fluxpipe AWS Lambda Fun(ction)

*... InfluxDB is* [*going back to SQL*](https://www.influxdata.com/blog/tldr-influxdb-tech-tips-downsampling-flight-sql-aws-lambda) *with Flight in I0X - but the greatness of Flux lives on!*

> 💡 **Fluxpipe** is a stand-alone, serverless **Flux** API/Pipeline for querying, analyzing and interacting with data on the cloud. *TLDR: Flux scripts outside of InfluxDB!*

❓ New to Flux? [Catch up in less than 3 minutes](https://github.com/metrico/fluXpipe/blob/main/flux.md)!

[**Fluxpipe**](https://fluxpipe.fly.dev) is a service emulating the **InfluxDB API** compatible with any existing API clients as well as data sources such as Grafana, *but that's only the beginning!*

[**Fluxpipe**](https://fluxpipe.fly.dev) is also designed to unleash *Flux scripts* within **serverless functions** at lightning speeds, with a *minuscule footprint* compared to its direct competition.

### TLDR; Here's a [Live Demo](https://fluxpipe.fly.dev)

<iframe src="https://fluxpipe.fly.dev" width="100%" height="500"></iframe>

<center>☝️☝️☝️ This is not an image ☝️☝️☝️</center>

> 💡 Fluxpipe is built and tested against the latest stable Flux release, and includes several contrib modules designed for qryn.cloud and clickhouse interoperability.

## Lambda Flux

*This article describes how to:*

1. Create and test an **AWS Lambda** function for Fluxpipe.
    
2. Use **Fluxpipe Gigapipe** to query [any supported data source](https://docs.influxdata.com/flux/v0.x/stdlib/experimental/).
    
3. Use [**Flux scripts**](https://docs.influxdata.com/flux/v0.x/stdlib/experimental/) to filter, process and downsample the data.
    
4. Write the data back to [**qryn**](https://qryn.cloud), **InfluxDB** or any [supported data source](https://docs.influxdata.com/flux/v0.x/stdlib/experimental/).
    
5. Use **CloudWatch** or **EventBridge** to trigger your functions automatically.
    

## Create an AWS Lambda Function

To create an AWS Lambda function, log into your AWS console.

➡ Search for **AWS Lambda** and select the service. Then, click **Create Function**.

![create function](https://images.ctfassets.net/o7xu9whrs0u9/5XE0x5uBoOA4oJYZFwzNea/79493c8495c8d60c726cfeeae73a2b84/create_function.png align="left")

➡ Choose **Container Image** and use the public *Fluxpipe* ***ECR*** *instance URI.*

> Push the [latest fluxpipe-lambda container](https://github.com/metrico/fluXpipe/pkgs/container/fluxpipe-lambda) to your ECR storage for best results

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679827245221/dd810081-cb17-4f07-8a50-7bb94083481e.png align="center")

➡ Click **Create Function** at the bottom right when you’re done.

### Validation

Let's **test** our new **Fluxpipe Lambda** using a *Flux script.*

The Lamba expects JSON requests with a **query** key:

```plaintext
{
   'query': 'import g "generate" g.from(start: 2022-04-01T00:00:00Z, stop: 2022-04-01T00:03:00Z, count: 5, fn: (n) => n+1)'
}
```

And the response would look like this:

```plaintext
#datatype,string,long,dateTime:RFC3339,long
#group,false,false,false,false
#default,_result,,,
,result,table,_time,_value
,,0,2022-04-01T00:00:00Z,1
,,0,2022-04-01T00:00:36Z,1
,,0,2022-04-01T00:01:12Z,1
,,0,2022-04-01T00:01:48Z,1
,,0,2022-04-01T00:02:24Z,1
```

### Ready

*Once your Lambda is validated, sky's the limit! Move your existing Influx/Flux workflows into your lambdas and use them to downsample, forecast and report.*

💡 For additional security, use [AWS Secrets Manager](https://aws.amazon.com/blogs/compute/securely-retrieving-secrets-with-aws-lambda/) and **ENV** variables to control sensible fields *(such as authentication ids, tokens, etc)* in your *Flux scripts.*

### Automation

If you’re looking to perform a downsampling task, you’ll need to run your Lambda script on a schedule. You can use **CloudWatch** or **EventBridge** to create a rule and target your AWS Lambda function to run Flux scripts on a user-defined schedule.

Use the following documentation depending on your preferred service:

* [CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html)
    
* [EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-run-lambda-schedule.html)
    

### **Conclusion**

Just a few clicks and you are all set with a *low-cost, high-power* **Fluxpipe Lambda** function ready to perform simple and complex data processing tasks at any scale.

[*Flux with Logs, Metrics and Traces for end-to-end visibility using qryn's polyglot API and data from Loki, Prometheus, Opentelemetry, InfluxDB, Elastic and many more.*](https://qryn.cloud)

[![](https://cdn.hashnode.com/res/hashnode/image/upload/v1676413342775/491ef8fb-6764-4786-8d87-02d3a0e60642.png?auto=compress,format&format=webp&auto=compress,format&format=webp align="left")](https://qryn.cloud/)
