Anarchy.Toolkit.Infrastructure.Messaging.Aws
4.1.0
See the version list below for details.
dotnet add package Anarchy.Toolkit.Infrastructure.Messaging.Aws --version 4.1.0
NuGet\Install-Package Anarchy.Toolkit.Infrastructure.Messaging.Aws -Version 4.1.0
<PackageReference Include="Anarchy.Toolkit.Infrastructure.Messaging.Aws" Version="4.1.0" />
<PackageVersion Include="Anarchy.Toolkit.Infrastructure.Messaging.Aws" Version="4.1.0" />
<PackageReference Include="Anarchy.Toolkit.Infrastructure.Messaging.Aws" />
paket add Anarchy.Toolkit.Infrastructure.Messaging.Aws --version 4.1.0
#r "nuget: Anarchy.Toolkit.Infrastructure.Messaging.Aws, 4.1.0"
#:package Anarchy.Toolkit.Infrastructure.Messaging.Aws@4.1.0
#addin nuget:?package=Anarchy.Toolkit.Infrastructure.Messaging.Aws&version=4.1.0
#tool nuget:?package=Anarchy.Toolkit.Infrastructure.Messaging.Aws&version=4.1.0
Anarchy.Toolkit.Infrastructure.Messaging.Aws
Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Infrastructure · Package catalog
AWS SNS and SQS publishers implementing the toolkit's message-broker abstractions.
dotnet add package Anarchy.Toolkit.Infrastructure.Messaging.Aws
- Register publishers with
AddSnsMessageBrokerorAddSqsMessageBrokerandAwsMessagingOptions, or useModuleSnsMessageBrokerandModuleSqsMessageBrokerwith configuration-based options factories. - The package also provides shared publisher and request-builder bases, inbound mapping and compression.
InboundMessage.BeginCorrelationScope(logger)is the consumer entry point for correlation: it reads the correlation and attempt IDs from the mapped message's string attributes and opens the provider-neutral scope fromInfrastructure.CorrelationId.- For integration tests, see Testing.Aws and its SNS/SQS helpers, which the toolkit runs against Moto.
When to use it
Use this package at the composition root when application code depends on IMessageBrokerPublisher and the deployment uses SNS topics or SQS queues. It implements publishing and inbound message mapping; the application remains responsible for creating destinations, permissions and message consumption.
How to use it
Register AppTelemetry and the required broker adapters. The example uses explicit options; obtain real account and region values from your host configuration:
using Anarchy.Toolkit.Infrastructure.Messaging.Aws.Entity.Configuration.Amazon;
using Anarchy.Toolkit.Infrastructure.Messaging.Aws.Extensions.Microsoft.Extensions.DependencyInjection;
var options = new AwsMessagingOptions("eu-west-1", "123456789012");
services.AddSnsMessageBroker(options);
services.AddSqsMessageBroker(options);
Alternatively, register the modules with options factories using UseModule. Resolve the keyed topic or queue publisher (MessageBrokerPublisherKeys.Topic / MessageBrokerPublisherKeys.Queue) and build messages with OutboundMessageBuilder from the abstractions package. Configure AWS credentials and permissions for the actual destinations, and plan for broker size limits, batch failures and duplicate delivery.
Options and overrides
AwsMessagingOptions also carries BatchSize (messages per batch request, 1 to 10, default 10), Compression (applied above the 256 KB limit, default Gzip; Uncompressed rejects oversized messages) and ServiceUrl (default null; set it to an emulator endpoint such as Moto's http://localhost:4566 to point the default clients and the SQS queue URLs at it).
The options you pass replace any registered earlier. Every other registration uses TryAdd/TryAddKeyed: register your own IAmazonSQS or IAmazonSimpleNotificationService (scoped), request builder or keyed publisher before the call or module and it is kept.
Enriching outbound messages
Every registered IOutboundMessageEnricher runs on each message, in registration order, before the request is built, so the attributes it adds count towards the size limit and the compression decision. None is registered by default. AddCorrelationMessageEnricher() opts in to the built-in CorrelationMessageEnricher, which writes the ambient CorrelationContext ids to the CorrelationIdOptions.CorrelationIdAttributeName and AttemptIdAttributeName attributes (default CorrelationId and AttemptId; separate from the header and log property names) and keeps any attribute the caller already set. Enrichers apply to every Toolkit publisher in the container, Kafka included; register them as singletons.
services.AddSnsMessageBroker(options).AddCorrelationMessageEnricher();
Consuming messages with correlation
The package maps inbound messages (InboundMessageMapper.FromSqs(sqsEvent)) but does not ship a consumer loop, so nothing propagates correlation IDs on its own: your handler opts in by opening the scope around each message.
using Anarchy.Toolkit.Infrastructure.Messaging.Aws.Extensions.Core.Messaging.Abstractions.Entity.MessageBroker;
using Anarchy.Toolkit.Infrastructure.Messaging.Aws.Helpers.MessageBroker;
foreach (var message in InboundMessageMapper.FromSqs(sqsEvent))
{
using (message.BeginCorrelationScope(logger))
await processor.HandleAsync(message, cancellationToken);
}
The scope sets the async-flowing CorrelationContext, opens a standard ILogger scope with the correlation and attempt properties (so every logging provider sees them) and tags the current Activity. The attribute names default to CorrelationId and AttemptId; pass other names, or the registered CorrelationIdOptions (message.BeginCorrelationScope(logger, correlationOptions)) to use its attribute names and aliases: the attribute name is read first, then each alias, and the first non-empty value wins. A missing attribute falls back to the current context's ID, then to a new one; it never throws. Custom pipelines can call CorrelationContext.BeginScopeFromAttributes(logger, attributes, options) directly. Publishers add the attributes only when an enricher such as CorrelationMessageEnricher is registered.
Structured CloudEvents over SQS and SNS
AwsCloudEventMapper.ToSqsRequest and ToSnsRequest serialize a CloudEvent as structured CloudEvents JSON and use the configured AWS request builders. Pass an OutboundMessage with the destination name, message attributes and optional FIFO partition and deduplication IDs; its body is replaced, and its ID is not sent by AWS. The builders derive the queue URL or topic ARN and apply FIFO fields only for .fifo destinations. If compression causes the builder to produce an empty body, the bridge throws AwsCloudEventEmptyBodyException: SQS and SNS require a nonempty message. With compression disabled, the builder rejects oversized messages with UncompressedMessageTooLargeException. Reduce the payload or store it externally instead. Keep the CloudEvent ID and source stable across retries.
Both request types carry the formatter's structured-envelope media type, application/cloudevents+json (with any formatter-supplied parameters), in an AWS String message attribute named ContentType. This is application metadata, not an HTTP content-type header or an AWS-reserved field, and differs from the event's datacontenttype, which describes its data. The bridge copies caller attributes and overwrites the exact, case-sensitive ContentType key if present; it does not mutate the caller's dictionary. Other casing is a distinct AWS attribute and is not interpreted as the content type. The receive methods expect structured JSON and do not validate or require this attribute. It counts against AWS message-attribute limits; configure consumers and SNS filters accordingly.
using Anarchy.Toolkit.Core.Messaging.Abstractions.Entity.MessageBroker;
using Anarchy.Toolkit.Infrastructure.Messaging.Aws.Helpers.MessageBroker;
using Anarchy.Toolkit.Infrastructure.Messaging.Aws.Service.MessageBroker.Aws.Publisher.RequestBuilder;
var metadata = new OutboundMessage("outbound-1", "orders.fifo", "placeholder",
partitionKey: "order-42", deduplicationId: "dedup-1",
attributes: new Dictionary<string, string> { ["CorrelationId"] = "correlation-1", ["Source"] = "ordering" });
var request = AwsCloudEventMapper.ToSqsRequest(cloudEvent, metadata, new SqsAwsPublisherRequestBuilder(options));
// Send request through the AWS SDK. On receipt:
var received = AwsCloudEventMapper.FromSqs(sqsLambdaRecord);
var eventFromBody = received.CloudEvent;
var brokerMetadata = received.Message;
FromSqs accepts either a Lambda record or an SDK receive Message (the latter also requires the queue ARN or URL). It returns the event alongside the received message, retaining the AWS-assigned ID, receipt handle, queue source, group ID, body and string message attributes. For compressed messages the inbound mapper returns the decompressed body; if it is a JSON-encoded string, the event is decoded from the unwrapped string. FromSnsNotification reads an actual SNS Notification JSON document, and FromSnsSqs reads that wrapper from an SQS record or SDK message, keeping SNS and SQS metadata separately. For SNS raw delivery use FromSqs instead. A publish request is not a received notification; AWS assigns its own SNS and SQS IDs. SNS topic ARN and SQS queue source are transport locations, not the CloudEvent source. Known typed CloudEvent extensions can be passed to the receive methods; otherwise the SDK treats unknown extensions as strings.
Only structured JSON is supported, not the CloudEvents binary binding. String broker attributes are carried independently of CloudEvent extensions; binary and number attributes, SNS signatures and timestamps, most SQS system attributes, and received deduplication IDs are not represented in these result models. Request the required SQS message/system attributes when receiving. SNS non-raw envelopes are not signature-verified by this mapper; validate them separately when your trust boundary requires it. Inbound compressed messages may use CompressionType and binary CompressionData attributes. Size, AWS attribute limits, delivery and deduplication guarantees remain the broker's responsibility.
See the registration example and toolkit overview.
Third-party dependencies
This package brings these libraries, which its name does not announce:
| Library | Why | In the public API? |
|---|---|---|
| CloudNative.CloudEvents (with its Newtonsoft.Json formatter) | Sends and receives structured CloudEvents over SNS and SQS (AwsCloudEventMapper) |
Yes: AwsCloudEventMapper takes and returns CloudEvent |
Releases
See the release notes for the complete release history.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Amazon.Lambda.SQSEvents (>= 3.0.1)
- Anarchy.Toolkit.Core (>= 3.0.0)
- Anarchy.Toolkit.Core.Messaging.Abstractions (>= 4.1.0)
- Anarchy.Toolkit.Core.Telemetry (>= 2.1.0)
- Anarchy.Toolkit.Infrastructure.CorrelationId (>= 3.1.0)
- AWSSDK.Core (>= 4.1.1.2)
- AWSSDK.SimpleNotificationService (>= 4.1.0.2)
- AWSSDK.SQS (>= 4.1.0.2)
- CloudNative.CloudEvents.NewtonsoftJson (>= 2.9.0)
- Humanizer (>= 3.0.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Diagnostics (>= 10.0.15)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Logging (>= 10.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Anarchy.Toolkit.Infrastructure.Messaging.Aws:
| Package | Downloads |
|---|---|
|
Anarchy.Toolkit.Testing.Aws
AWS test helpers: SNS/SQS helpers (typically against Moto), SqsMessageFixture with gzip/zlib bodies, and LambdaContextFixture for Lambda handlers under test. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.2.0 | 0 | 12/1/2026 |
| 4.1.0 | 49 | 12/1/2026 |
| 4.0.0 | 66 | 11/27/2026 |
| 3.0.0 | 111 | 11/24/2026 |
| 2.0.1 | 116 | 11/21/2026 |
| 2.0.0 | 103 | 11/20/2026 |
| 1.1.1 | 109 | 11/17/2026 |
| 1.1.0 | 106 | 11/17/2026 |
| 1.0.7 | 105 | 11/16/2026 |
| 1.0.6 | 105 | 11/14/2026 |
| 1.0.5 | 109 | 11/13/2026 |
| 1.0.4 | 106 | 11/9/2026 |
| 1.0.3 | 101 | 11/9/2026 |
| 1.0.1 | 106 | 11/6/2026 |
| 1.0.0 | 111 | 11/5/2026 |
## Releases
### 4.1.0
- Add outbound correlation enrichers, configurable messaging options and injectable AWS clients; calculate message size after enrichment.
- feat(Core)!: Add health and telemetry extension points
- feat(Infrastructure): Add configurable provider and messaging seams
### 4.0.0
- **Breaking:** extension classes take the `Extensions` suffix under `Extensions/<extended namespace>/`, helpers live in `Helpers/<Subject>/`, and their namespaces follow those folders: update `using` directives.
- **Breaking:** depends on the new major versions of `Core` and `Core.Messaging.Abstractions`.
### 3.0.0
- Add structured CloudEvents conversion for SQS messages, SNS notifications, and publish requests, with broker context kept separate.
- Adopt the broker-neutral inbound reference contract.
### 2.0.1
- chore(build): Format package release notes property
### 2.0.0
- Route publisher logs and metrics through the host's `AppTelemetry` instead of `Observer`.
- Added `InboundMessage.BeginCorrelationScope(logger)`, the consumer entry point that opens a provider-neutral correlation scope from a mapped message's attributes.
### 1.1.1
- docs(packages): identify each package's pillar and layer
- build(packages): attribute the copyright to Leandro Melão Medeiros
- build: relicense under Apache-2.0 and update the package metadata
### 1.1.0
- build(deps): upgrade Swashbuckle.AspNetCore to 11.0.1 and Microsoft.OpenApi to 3.11.1
### 1.0.7
- docs: expand XML docblocks across all projects for the DocFX API reference
### 1.0.6
- refactor(src): clean up code style across library packages
- chore(deps): update AWS SDK, Lambda ASP.NET Core server and MySqlConnector packages
### 1.0.5
- chore(deps): update AWS SDK packages
### 1.0.3
- build: migrate local automation to build tooling
### 1.0.2
- docs: expand package guides and release histories
- chore(deps): update AWS, Polly, and xUnit packages
### 1.0.1
- Added a package-specific NuGet README.
### 1.0.0
- Introduced SNS and SQS publishers, request builders, optional payload compression, inbound mapping and dependency-injection modules.