Cameleer

AWS Bedrock component

The aws-bedrock component calls foundation models on Amazon Bedrock (Claude, Llama, Titan, Mistral and others) with the Converse and InvokeModel APIs, including streaming and guardrails.

Scheme: aws-bedrock: · Also: aws2-bedrock: (same component) · Crate: cameleer-cloud · Cargo feature: cloud · Consumer: no · Producer: yes · Apache Camel: AWS Bedrock

When to use it

  • Summarize, classify or translate messages with a large language model inside a route.
  • Build AI agents: the Converse API takes a message list, a system prompt and tool definitions, and returns the model's answer, stop reason and token usage.
  • Create embeddings for retrieval (invokeEmbeddingsModel) or images (invokeImageModel).
  • Check prompts and answers against a Bedrock guardrail before they reach users.

For knowledge bases and Bedrock Agents, use aws-bedrock-agent-runtime.

URI format

text
aws-bedrock://label?modelId=...[&options]

The path is a free label. modelId is the Bedrock model id or an inference profile id.

Example

Summarize support tickets from a queue with Claude and publish the summary to a topic:

yaml example: aws-bedrock-summarize-tickets
- route:
    id: summarize-tickets
    from:
      uri: "aws2-sqs://support-tickets?region={{env:AWS_REGION:us-east-1}}"
      steps:
        - setHeader:
            name: CamelAwsBedrockConverseSystem
            constant: "Summarize the support ticket in one sentence."
        - to: "aws-bedrock://summarizer?region={{env:AWS_REGION:us-east-1}}&modelId={{env:BEDROCK_MODEL_ID:anthropic.claude-3-haiku-20240307-v1:0}}&operation=converse"
        - log: "summary (${header.CamelAwsBedrockConverseStopReason}): ${body}"
        - to: "aws2-sns://ticket-summaries?region={{env:AWS_REGION:us-east-1}}&autoCreateTopic=true"

With converse, a text body becomes one user message and the body after the call is the model's answer text. The full output message, the stop reason and the token usage are in headers.

Rust DSL

rust
ctx.add_routes(|b| {
    b.from("aws2-sqs://support-tickets?region={{env:AWS_REGION:us-east-1}}")
        .set_header("CamelAwsBedrockConverseSystem", constant("Summarize the support ticket in one sentence."))
        .to("aws-bedrock://summarizer?region={{env:AWS_REGION:us-east-1}}&modelId={{env:BEDROCK_MODEL_ID:anthropic.claude-3-haiku-20240307-v1:0}}&operation=converse")
        .log("summary (${header.CamelAwsBedrockConverseStopReason}): ${body}")
        .to("aws2-sns://ticket-summaries?region={{env:AWS_REGION:us-east-1}}&autoCreateTopic=true");
})?;

Options

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

optiondefaultdescription
modelIdModel or inference profile id (CamelAwsBedrockModelId overrides it).
operationinvokeTextModelinvokeTextModel, invokeImageModel, invokeEmbeddingsModel, converse, invokeTextModelStreaming, invokeImageModelStreaming, invokeEmbeddingsModelStreaming, converseStream, applyGuardrail.
streamOutputModecompleteStreaming operations: complete (body = whole text) or chunks (body = list of chunks).
streamingChunkProcessor#bean of a processor called for every chunk while the response streams (body = chunk text).
guardrailIdentifier, guardrailVersionGuardrail used by applyGuardrail and applied to invoke and converse requests.
guardrailTracefalseAsk for the guardrail trace.

The invoke operations post the body as is (a map is sent as JSON): you write the request in the model's own format (for Anthropic models the Messages API body, for Titan {"inputText": ...}), and the parsed JSON response becomes the body.

Message headers

headerdirectiondescription
CamelAwsBedrockOperation, CamelAwsBedrockModelIdinOverride operation and modelId.
CamelAwsBedrockContentType, CamelAwsBedrockAcceptContentTypeinContent types of invoke requests (default application/json).
CamelAwsBedrockConverseMessagesinConverse message list ({role, content} maps); otherwise the body is used.
CamelAwsBedrockConverseSysteminSystem prompt (text or content blocks).
CamelAwsBedrockConverseInferenceConfiginMap such as {maxTokens, temperature, topP}.
CamelAwsBedrockConverseToolConfiginTool definitions for agentic tool use.
CamelAwsBedrockConverseStopReasonoutend_turn, max_tokens, tool_use, ...
CamelAwsBedrockConverseUsageoutToken usage (map).
CamelAwsBedrockConverseOutputMessageoutThe assistant message, including tool use blocks.
CamelAwsBedrockStreamOutputModeinOverrides streamOutputMode.
CamelAwsBedrockStreamingChunkCount, CamelAwsBedrockStreamingCompletionReason, CamelAwsBedrockStreamingTokenCountoutStreaming results.
CamelAwsBedrockStreamingChunkIndexoutIndex of the chunk given to streamingChunkProcessor.
CamelAwsBedrockGuardrailIdentifier, CamelAwsBedrockGuardrailVersioninGuardrail.
CamelAwsBedrockGuardrailSourceinINPUT (default) or OUTPUT for applyGuardrail.
CamelAwsBedrockGuardrailActionoutResult of applyGuardrail (NONE, GUARDRAIL_INTERVENED).

Run it with Docker

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

Common questions

How do I give the model tools (function calling)?

Set CamelAwsBedrockConverseToolConfig to a map with tools (each a toolSpec with name, description and JSON schema). When the model wants a tool, the stop reason is tool_use and CamelAwsBedrockConverseOutputMessage holds the tool use block; run the tool in the route and send the next turn with CamelAwsBedrockConverseMessages.

How do I stream the answer?

Use operation=converseStream (or an ...Streaming invoke operation). The response is decoded as it arrives; with streamingChunkProcessor=#myProcessor each chunk is handed to your processor while the rest is still streaming.

Which model id should I use?

Any id enabled in your account and region, for example anthropic.claude-3-haiku-20240307-v1:0 or a cross-region inference profile such as us.anthropic.claude-3-5-sonnet-20241022-v2:0.

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