Cameleer

AWS Lambda component

The aws2-lambda component invokes AWS Lambda functions and manages functions, versions, aliases, tags and event source mappings.

Scheme: aws2-lambda: · Crate: cameleer-cloud · Cargo feature: cloud · Consumer: no · Producer: yes · Apache Camel: AWS Lambda

When to use it

  • Call serverless business logic from a route and continue with its result.
  • Offload heavy work (image resizing, PDF rendering, model inference) from an edge device to Lambda.
  • Expose a Lambda function to an AI agent as a tool behind a queue or an HTTP route.
  • Deploy or update functions from a CI route (createFunction, updateFunction, publishVersion).

URI format

text
aws2-lambda://functionNameOrArn[?options]

Example

Invoke a function for each message of a queue and send its response to another queue:

yaml example: aws2-lambda-invoke-function
- route:
    id: resize-images
    from:
      uri: "aws2-sqs://images-to-resize?region={{env:AWS_REGION:us-east-1}}"
      steps:
        - to: "aws2-lambda://resize-image?region={{env:AWS_REGION:us-east-1}}&operation=invokeFunction"
        - to: "aws2-sqs://resized-images?region={{env:AWS_REGION:us-east-1}}&autoCreateQueue=true"

The body is sent as the payload; the response payload becomes the body. When the function fails, the CamelAwsLambdaFunctionError header is set and the body holds the error document.

Rust DSL

rust
ctx.add_routes(|b| {
    b.from("aws2-sqs://images-to-resize?region={{env:AWS_REGION:us-east-1}}")
        .to("aws2-lambda://resize-image?region={{env:AWS_REGION:us-east-1}}&operation=invokeFunction")
        .to("aws2-sqs://resized-images?region={{env:AWS_REGION:us-east-1}}&autoCreateQueue=true");
})?;

Options

Common AWS options (region, credentials, endpoint override, proxy) are listed in Cloud credentials.

optiondefaultdescription
operationinvokeFunctioninvokeFunction, listFunctions, getFunction, deleteFunction, createFunction, updateFunction, createEventSourceMapping, deleteEventSourceMapping, listEventSourceMapping, listTags, tagResource, untagResource, publishVersion, listVersions, createAlias, deleteAlias, getAlias, listAliases. The CamelAwsLambdaOperation header overrides it.

Every operation except invokeFunction sets the response document (a map, or a list for the list operations) as the body.

Message headers

headerdirectiondescription
CamelAwsLambdaOperationinOverrides operation.
CamelAwsLambdaInvocationTypeinRequestResponse (default), Event (asynchronous) or DryRun.
CamelAwsLambdaFunctionErroroutSet when the function returned an error.
CamelAwsLambdaStatusCodeoutHTTP status of the invocation.
CamelAwsLambdaS3Bucket, CamelAwsLambdaS3Key, CamelAwsLambdaS3ObjectVersioninCode location of createFunction / updateFunction (otherwise the body is the zip).
CamelAwsLambdaRole, CamelAwsLambdaRuntime, CamelAwsLambdaHandler, CamelAwsLambdaDescription, CamelAwsLambdaTargetArn, CamelAwsLambdaMemorySize, CamelAwsLambdaKMSKeyArn, CamelAwsLambdaPublish, CamelAwsLambdaTimeout, CamelAwsLambdaTracingConfig, CamelAwsLambdaEnvironmentVariables, CamelAwsLambdaTags, CamelAwsLambdaSecurityGroupIds, CamelAwsLambdaSubnetIdsinFunction settings of createFunction.
CamelAwsLambdaEventSourceArn, CamelAwsLambdaEventSourceBatchSize, CamelAwsLambdaEventSourceUuid, CamelAwsLambdaEventSourceStartingPositioninEvent source mappings (StartingPosition is a Cameleer extension).
CamelAwsLambdaResourceArn, CamelAwsLambdaResourceTags, CamelAwsLambdaResourceTagKeysinTag operations.
CamelAwsLambdaVersionDescription, CamelAwsLambdaFunctionVersion, CamelAwsLambdaAliasFunctionName, CamelAwsLambdaAliasFunctionDescriptioninVersions and aliases.

Run it with Docker

sh
docker run --rm -e AWS_REGION -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY \
  -v "$PWD:/routes:ro" pmsudhi/cameleer run /routes/resize.camel.yaml

Common questions

How do I invoke a function asynchronously?

Set the header CamelAwsLambdaInvocationType to Event. Lambda queues the event and returns at once.

How do I call a specific version or alias?

Use the qualified ARN as the path, for example aws2-lambda://arn:aws:lambda:eu-west-1:123456789012:function:resize-image:prod.

How does the route know the function failed?

A function error does not throw: check ${header.CamelAwsLambdaFunctionError} (for example in a choice) and read the error document from the body.

Found a problem?

If something on this page doesn't match what Cameleer does, or you hit a bug while building with it, please help fix it, whether you are a person or a coding agent: open an issue that describes what you saw, then fork the repository, fix it, add or update a test, run cargo test --workspace, and open a pull request. CONTRIBUTING.md explains the ground rules.

Edit this page on GitHub