Cameleer

AWS SNS component

The aws2-sns component publishes messages to Amazon SNS topics, including FIFO topics and batches.

Scheme: aws2-sns: · Crate: cameleer-cloud · Cargo feature: cloud · Consumer: no · Producer: yes · Apache Camel: AWS Simple Notification System (SNS)

When to use it

  • Fan out an event to many subscribers (SQS queues, Lambda functions, e-mail, SMS, HTTPS).
  • Send operational alerts from a route to an on-call topic.
  • Connect a Cameleer route on an edge device to a serverless backend that subscribes to the topic.

URI format

text
aws2-sns://topicNameOrArn[?options]

When the path is a topic ARN it is used as is. Otherwise the topic is looked up by name (ListTopics) or created with autoCreateTopic=true.

Example

Forward alerts from an SQS queue to an SNS topic with a subject:

yaml example: aws2-sns-publish-alerts
- route:
    id: alerts-to-sns
    from:
      uri: "aws2-sqs://alerts?region={{env:AWS_REGION:us-east-1}}"
      steps:
        - to: "aws2-sns://ops-alerts?region={{env:AWS_REGION:us-east-1}}&subject=Ops alert&autoCreateTopic=true"
        - log: "published ${header.CamelAwsSnsMessageId}"

Credentials come from the default AWS chain; see Cloud credentials.

Rust DSL

rust
ctx.add_routes(|b| {
    b.from("aws2-sqs://alerts?region={{env:AWS_REGION:us-east-1}}")
        .to("aws2-sns://ops-alerts?region={{env:AWS_REGION:us-east-1}}&subject=Ops alert&autoCreateTopic=true")
        .log("published ${header.CamelAwsSnsMessageId}");
})?;

Options

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

optiondefaultdescription
subjectMessage subject (CamelAwsSnsSubject wins).
messageStructurejson to send a different message per protocol.
autoCreateTopicfalseCreate the topic when it does not exist.
messageGroupIdStrategyFIFO topics: useConstant, useExchangeId or usePropertyValue.
messageDeduplicationIdStrategyuseExchangeIdFIFO topics: useExchangeId or useContentBasedDeduplication.
subscribeSNStoSQSfalseSubscribe the SQS queue queueArn to the topic when the endpoint starts.
queueArnQueue to subscribe with subscribeSNStoSQS.
policyTopic policy (JSON text, or a file: / classpath: resource).
serverSideEncryptionEnabled, kmsMasterKeyIdfalseTopic encryption.
batchEnabledfalsePublish a list body with PublishBatch (10 per request); body = {successful, failed}.

Message headers

headerdirectiondescription
CamelAwsSnsMessageIdoutId of the published message.
CamelAwsSnsSubjectinSubject.
CamelAwsSnsMessageStructureinMessage structure.
CamelAwsSnsMessageGroupIdin (property)Group id with messageGroupIdStrategy=usePropertyValue.

Other message headers are published as SNS message attributes.

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/alerts.camel.yaml

Common questions

How do I fan out to an SQS queue?

Add subscribeSNStoSQS=true&queueArn=arn:aws:sqs:<region>:<account>:<queue>; the subscription is created when the endpoint starts (it is idempotent). The queue policy must allow the topic to send.

Can I consume from SNS?

No. SNS pushes to subscribers; subscribe an SQS queue and consume it with aws2-sqs.

How do I publish many messages in one call?

Send a list body with batchEnabled=true.

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