Lambda
There are bento binaries specifically tailored for deployment as an AWS Lambda function, these are available from the [releases][releases] page.
The bento-lambda-al2023 distribution supports the provided.al2023 runtime,
which runs Amazon Linux 2 on either the x86_64 or arm64 architecture.
The bento-lambda-al2 distribution is set to be deprecated by AWS on July 31st
2026.
They use the same configuration format as a regular Bento instance, which can be provided in 1 of 2 ways:
- Inline via the
BENTO_CONFIGenvironment variable (YAML format). - Via the filesystem using a layer, extension, or container image. By default,
Bento Lambda distributions will look for a valid configuration file in
the locations listed below. Alternatively, the configuration file path can be
set explicity by passing a
BENTO_CONFIG_PATHenvironment variable.
./bento.yaml./config.yaml/bento.yaml/etc/bento/config.yaml/etc/bento.yaml
Also, the http, input and buffer sections are ignored as the service wide
HTTP server is not used, and messages are inserted via function invocations.
If the output section is omitted in your config then the result of the
processing pipeline is returned back to the caller, otherwise the resulting data
is sent to the output destination.
Running with an output
The flow of a Bento lambda function with an output configured looks like this:
bento-lambda
+------------------------------+
| |
-------> Processors ----> Output -----> Somewhere
invoke | | |
<-------------------------------------------/
| <Ack/Noack> |
| |
+------------------------------+
Where the call will block until the output target has confirmed receipt of the
resulting payload. When the message is successfully propagated a JSON payload is
returned of the form {"message":"request successful"}, otherwise an error is
returned containing the reason for the failure.
Running without an output
The flow when an output is not configured looks like this:
bento-lambda
+--------------------+
| |
-------> Processors --\ |
invoke | | |
<---------------------/ |
| <Result> |
| |
+--------------------+
Where the function returns the result of processing directly back to the caller. The format of the result differs depending on the number of batches and messages of a batch that resulted from the invocation:
- Single message of a single batch:
{}(JSON object) - Multiple messages of a single batch:
[{},{}](Array of JSON objects) - Multiple batches:
[[{},{}],[{}]](Array of arrays of JSON objects, batches of size one are a single object array in this case)
Processing Errors
The default behaviour of a Bento lambda is that the handler will not return an error unless the output fails. This means that errors that occur within your processors will not result in the handler failing, which will instead return the final state of the message.
The handler will fail if messages have encountered an uncaught error during execution.
However, it is also possible to configure your output to use the [reject output][output.reject]
in order to trigger a handler error on processor errors:
output:
switch:
retry_until_success: false
cases:
- check: '!errored()'
output:
sync_response: {}
- output:
reject: "processing failed due to: ${! error() }"
If you are using partial batch responses then throwing an exception will cause the entire batch to be considered a failure.
Running a combination
It's possible to configure pipelines that send messages to third party
destinations and also return a result back to the caller. This is done by
configuring an output block and including an output of the type
sync_response.
For example, if we wished for our lambda function to send a payload to Kafka and also return the same payload back to the caller we could use a [broker][output-broker]:
output:
broker:
pattern: fan_out
outputs:
- kafka:
addresses:
- todo:9092
client_id: bento_serverless
topic: example_topic
- sync_response: {}
Upload to AWS
provided.al2023 on arm64
Grab an archive labelled bento-lambda-al2023 for arm64 from the [releases page][releases]
page and then upload it to S3:
aws s3api create-bucket --bucket lambdas
aws s3api put-object --bucket lambdas --key bento-lambda.zip --body
bento-lambda-al2023_1.16.1_linux_arm64.zip
Then create your function (AWS CLI v2 only):
LAMBDA_ENV=`cat yourconfig.yaml | jq -csR {Variables:{BENTO_CONFIG:.}}`
aws lambda create-function \
--runtime provided.al2023 \
--handler not.used.for.provided.al2023.runtime \
# note: handler is not used for this runtime: lambda will execute a binary
# named 'bootstrap' in the root of the zip archive.
--architectures arm64 \
--role arn:aws:iam::000000000000:role/bento-example-role \
--code S3Bucket=lambdas,S3Key=bento-lambda.zip \
--environment "$LAMBDA_ENV" \
--function-name bento-example
There is also an example [SAM template][sam-template-al2023] and [Terraform resource][tf-example-al2023] in the repo to copy from.
Note that you can also run bento-lambda-al2023 on x86_64, just use the amd64 zip instead.
Invoke
aws lambda invoke \
--function-name bento-example \
--payload '{"your":"document"}' \
--cli-binary-format raw-in-base64-out \
out.txt && cat out.txt && rm out.txt
Build
You can build and archive the function yourself with:
go build github.com/warpstreamlabs/bento/cmd/serverless/bento-lambda
zip bento-lambda.zip bento-lambda
go build -o bootstrap github.com/warpstreamlabs/bento/cmd/serverless/bento-lambda
zip bento-lambda.zip bootstrap
[releases]: https://github.com/warpstreamlabs/bento/releases
[sam-template-al2023]: https://github.com/warpstreamlabs/bento/tree/main/resources/serverless/lambda/bento-lambda-al2023-sam.yaml
[tf-example-al2023]: https://github.com/warpstreamlabs/bento/tree/main/resources/serverless/lambda/bento-lambda-al2023.tf
[output-broker]: /docs/components/outputs/broker
[output.reject]: /docs/components/outputs/reject
[makenew/serverless-bento]: https://github.com/makenew/serverless-bento
[makenew/bento-plugin]: https://github.com/makenew/bento-plugin