Skip to content

Foundatio.AWS

Foundatio provides AWS implementations for file storage, queuing, and messaging using Amazon S3, Amazon SQS, and Amazon SNS. View source on GitHub →

Overview

ImplementationInterfacePackage
S3FileStorageIFileStorageFoundatio.AWS
SQSMessageBusIMessageBusFoundatio.AWS
SQSQueue<T>IQueue<T>Foundatio.AWS

Installation

bash
dotnet add package Foundatio.AWS

S3FileStorage

Store files in Amazon S3 with full support for buckets, prefixes, and metadata.

csharp
using Foundatio.Storage;

var storage = new S3FileStorage(o =>
{
    o.ConnectionString = connectionString;
    // Or: o.Bucket = "my-files"; o.Region = RegionEndpoint.USEast1;
});

await storage.SaveFileAsync("documents/report.pdf", pdfStream);

Configuration

OptionTypeRequiredDescription
BucketstringS3 bucket name
RegionRegionEndpointAWS region
ConnectionStringstringParses all settings
CredentialsAWSCredentialsAWS credentials
ServiceUrlstringCustom endpoint (LocalStack)

For additional options, see S3FileStorageOptions source.

SQSMessageBus

AWS SNS/SQS message bus for pub/sub messaging using the SNS fan-out pattern.

csharp
using Foundatio.Messaging;

var messageBus = new SQSMessageBus(o =>
{
    o.ConnectionString = connectionString;
    o.Topic = "events";
    // Optional: Specify queue name for durable subscriptions
    // o.SubscriptionQueueName = "my-service-queue";
});

await messageBus.SubscribeAsync<OrderCreated>(async order =>
{
    Console.WriteLine($"Order created: {order.OrderId}");
});

await messageBus.PublishAsync(new OrderCreated { OrderId = 123 });

Configuration

OptionTypeRequiredDefaultDescription
TopicstringSNS topic name for publishing
ConnectionStringstringConnection string
CredentialsAWSCredentialsAWS credentials
RegionRegionEndpointAWS region
ServiceUrlstringCustom endpoint (LocalStack)
CanCreateTopicbooltrueAuto-create SNS topic if missing
SubscriptionQueueNamestringRandomSQS queue name (use for durable subscriptions)
SubscriptionQueueAutoDeletebooltrueAuto-delete queue on dispose (set false for durable)
ReadQueueTimeoutTimeSpan20sLong polling timeout
DequeueIntervalTimeSpan1sInterval between dequeue attempts
MessageVisibilityTimeoutTimeSpan?30s (SQS)Message visibility timeout
SqsManagedSseEnabledboolfalseEnable SQS managed encryption (SSE-SQS)
KmsMasterKeyIdstringKMS key ID for encryption (SSE-KMS)
KmsDataKeyReusePeriodSecondsint300KMS key reuse period
TopicResolverFunc<Type, string>Route message types to different topics

For additional options, see SQSMessageBusOptions source.

Architecture

The SQSMessageBus uses the SNS fan-out pattern:

  • Publishing: Messages are published to an SNS topic
  • Subscribing: Each subscriber gets its own SQS queue subscribed to the SNS topic
  • Durable Subscriptions: Use SubscriptionQueueName and set SubscriptionQueueAutoDelete = false to persist queues across restarts
  • Policy Management: Queue policies are automatically configured to allow SNS to deliver messages

Durable Subscriptions Example

csharp
var messageBus = new SQSMessageBus(o =>
{
    o.ConnectionString = connectionString;
    o.Topic = "events";
    o.SubscriptionQueueName = "order-service-events";
    o.SubscriptionQueueAutoDelete = false; // Queue persists across restarts
});

SQSQueue

AWS SQS queue implementation for reliable work item processing.

csharp
using Foundatio.Queues;

var queue = new SQSQueue<WorkItem>(o =>
{
    o.ConnectionString = connectionString;
    o.Name = "work-items";
});

await queue.EnqueueAsync(new WorkItem { Data = "Hello" });
var entry = await queue.DequeueAsync();

Configuration

OptionTypeRequiredDefaultDescription
NamestringQueue name
ConnectionStringstringConnection string
RegionRegionEndpointAWS region
CanCreateQueuebooltrueAuto-create queue
SupportDeadLetterbooltrueEnable DLQ support
ReadQueueTimeoutTimeSpan20sLong polling timeout

For additional options, see SQSQueueOptions source.

Next Steps

Released under the Apache 2.0 License.