Goa.Clients.Sns
0.0.2-preview.2
This is a prerelease version of Goa.Clients.Sns.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Goa.Clients.Sns --version 0.0.2-preview.2
NuGet\Install-Package Goa.Clients.Sns -Version 0.0.2-preview.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Goa.Clients.Sns" Version="0.0.2-preview.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Goa.Clients.Sns" Version="0.0.2-preview.2" />
<PackageReference Include="Goa.Clients.Sns" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Goa.Clients.Sns --version 0.0.2-preview.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Goa.Clients.Sns, 0.0.2-preview.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Goa.Clients.Sns@0.0.2-preview.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Goa.Clients.Sns&version=0.0.2-preview.2&prerelease
#tool nuget:?package=Goa.Clients.Sns&version=0.0.2-preview.2&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Goa.Clients.Sns
SNS client for messaging in high-performance AWS Lambda functions. This package provides a lightweight, AOT-ready SNS client optimized for minimal cold start times.
Installation
dotnet add package Goa.Clients.Sns
Features
- Native AOT support for faster Lambda cold starts
- Minimal dependencies and memory allocations
- Built-in error handling with ErrorOr pattern
- Support for topics, SMS, and push notifications
- Message attributes and FIFO topic support
- Type-safe message publishing
Usage
Basic Setup
using Goa.Clients.Sns;
using Microsoft.Extensions.DependencyInjection;
// Register SNS client
services.AddSns();
// Or with custom configuration
services.AddSns(config =>
{
config.ServiceUrl = "http://localhost:4566"; // For LocalStack
config.Region = "us-west-2";
config.LogLevel = LogLevel.Debug;
});
Publishing Messages
using System.Text.Json;
using ErrorOr;
using Goa.Clients.Sns;
using Goa.Clients.Sns.Operations.Publish;
public class NotificationService
{
private readonly ISnsClient _sns;
public NotificationService(ISnsClient sns)
{
_sns = sns;
}
public async Task<ErrorOr<Success>> SendNotificationAsync(string message)
{
var request = new PublishRequest
{
TopicArn = "arn:aws:sns:us-east-1:123456789012:notifications",
Message = message
};
var result = await _sns.PublishAsync(request);
return result.IsError ? result.FirstError : ErrorOr.Success;
}
}
Publishing with Attributes
using Goa.Clients.Sns.Models;
public async Task<ErrorOr<Success>> SendOrderNotificationAsync(Order order)
{
var request = new PublishRequest
{
TopicArn = "arn:aws:sns:us-east-1:123456789012:orders",
Message = JsonSerializer.Serialize(order),
Subject = "New Order Received",
MessageAttributes = new Dictionary<string, SnsMessageAttributeValue>
{
{ "OrderId", SnsMessageAttributeValue.Create(order.Id) },
{ "Priority", SnsMessageAttributeValue.Create("High") },
{ "Amount", SnsMessageAttributeValue.Create(order.Total) }
}
};
var result = await _sns.PublishAsync(request);
return result.IsError ? result.FirstError : ErrorOr.Success;
}
SMS Messaging
public async Task<ErrorOr<Success>> SendSmsAsync(string phoneNumber, string message)
{
var request = new PublishRequest
{
PhoneNumber = phoneNumber,
Message = message
};
var result = await _sns.PublishAsync(request);
if (result.IsError)
{
Console.WriteLine($"Failed to send SMS: {result.FirstError}");
return result.FirstError;
}
Console.WriteLine($"SMS sent successfully. Message ID: {result.Value.MessageId}");
return ErrorOr.Success;
}
Push Notification to Mobile Endpoint
public async Task<ErrorOr<Success>> SendPushNotificationAsync(string targetArn, object notification)
{
var request = new PublishRequest
{
TargetArn = targetArn, // Mobile platform endpoint ARN
Message = JsonSerializer.Serialize(notification),
MessageStructure = "json" // For structured notifications
};
var result = await _sns.PublishAsync(request);
return result.IsError ? result.FirstError : ErrorOr.Success;
}
FIFO Topic Publishing
public async Task<ErrorOr<Success>> SendFifoMessageAsync(string message, string groupId)
{
var request = new PublishRequest
{
TopicArn = "arn:aws:sns:us-east-1:123456789012:orders.fifo",
Message = message,
MessageGroupId = groupId,
MessageDeduplicationId = Guid.NewGuid().ToString() // Or use content-based deduplication
};
var result = await _sns.PublishAsync(request);
return result.IsError ? result.FirstError : ErrorOr.Success;
}
Custom Message Attributes
public async Task<ErrorOr<Success>> SendWithCustomAttributesAsync()
{
var binaryData = System.Text.Encoding.UTF8.GetBytes("Hello World");
var request = new PublishRequest
{
TopicArn = "arn:aws:sns:us-east-1:123456789012:notifications",
Message = "Message with custom attributes",
MessageAttributes = new Dictionary<string, SnsMessageAttributeValue>
{
{ "StringAttr", SnsMessageAttributeValue.Create("Value") },
{ "NumberAttr", SnsMessageAttributeValue.Create(42) },
{ "BinaryAttr", SnsMessageAttributeValue.Create(binaryData) },
{ "CustomType", SnsMessageAttributeValue.Create("CustomValue", "String.Custom") }
}
};
var result = await _sns.PublishAsync(request);
return result.IsError ? result.FirstError : ErrorOr.Success;
}
Error Handling
var result = await _sns.PublishAsync(request);
if (result.IsError)
{
// Handle errors
foreach (var error in result.Errors)
{
Console.WriteLine($"SNS Error: {error.Description}");
}
return;
}
var response = result.Value;
Console.WriteLine($"Message published successfully. Message ID: {response.MessageId}");
// For FIFO topics, you can also access the sequence number
if (!string.IsNullOrEmpty(response.SequenceNumber))
{
Console.WriteLine($"FIFO Sequence Number: {response.SequenceNumber}");
}
Available Message Attribute Types
The SNS client supports various message attribute data types:
- String:
SnsMessageAttributeValue.Create("value")
orAddStringAttribute("name", "value")
- Number:
SnsMessageAttributeValue.Create(42)
- Binary:
SnsMessageAttributeValue.Create(byteArray)
orSnsMessageAttributeValue.CreateBase64("base64data")
- Custom Types:
SnsMessageAttributeValue.Create("value", "String.Custom")
Documentation
For more information and examples, visit the main Goa documentation.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- ErrorOr (>= 2.0.1)
- Goa.Clients.Core (>= 0.0.2-preview.2)
-
net9.0
- ErrorOr (>= 2.0.1)
- Goa.Clients.Core (>= 0.0.2-preview.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.0.3-preview.1 | 47 | 8/23/2025 |
0.0.2-preview.2.3 | 109 | 8/18/2025 |
0.0.2-preview.2.2 | 117 | 8/17/2025 |
0.0.2-preview.2.1 | 90 | 8/17/2025 |
0.0.2-preview.2 | 107 | 8/9/2025 |
0.0.0-alpha.0.32 | 83 | 12/7/2024 |
0.0.0-alpha.0.20 | 75 | 10/27/2024 |