

@airhornjs/aws
AWS SNS and SES provider for Airhorn.
Installation
npm install airhorn @airhornjs/aws
Features
- SMS sending via Amazon SNS (Simple Notification Service)
- Email sending via Amazon SES (Simple Email Service)
- Automatic error handling and retry support
- Integration with Airhorn's notification system
- Support for AWS credentials from environment variables or explicit configuration
Usage
SMS with Amazon SNS
import { Airhorn } from 'airhorn';
import { AirhornAws } from '@airhornjs/aws';
const awsProvider = new AirhornAws({
region: 'us-east-1',
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key',
});
const airhorn = new Airhorn({
providers: [awsProvider],
});
const message = {
from: '+1234567890',
content: 'Hello John!, your order #12345 has been shipped!',
type: AirhornSendType.SMS,
};
const result = await airhorn.send(
'+0987654321',
message,
);
Email with Amazon SES
import { Airhorn } from 'airhorn';
import { AirhornAws } from '@airhornjs/aws';
const awsProvider = new AirhornAws({
region: 'us-east-1',
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key',
});
const airhorn = new Airhorn({
providers: [awsProvider],
});
const data = {
orderId: '656565',
customerName: 'John',
};
const template = {
from: 'sender@example.com',
subject: 'Order <%= orderId %> Confirmation',
content: '<h1>Hello <%= customerName %></h1><p>Your order #<%= orderId %> has been confirmed!</p>',
};
const result = await airhorn.send(
'recipient@example.com',
template,
data,
AirhornSendType.Email
);
Both SMS and Email
By default, the provider supports both SMS and email notifications:
const provider = new AirhornAws({
region: 'us-east-1',
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key',
sessionToken: 'your-session-token',
});
console.log(provider.capabilities);
Custom Capabilities
You can specify which services to enable using the capabilities option:
const smsProvider = new AirhornAws({
region: 'us-east-1',
capabilities: [AirhornSendType.SMS],
});
const emailProvider = new AirhornAws({
region: 'us-east-1',
capabilities: [AirhornSendType.Email],
});
const bothProvider = new AirhornAws({
region: 'us-east-1',
capabilities: [AirhornSendType.SMS, AirhornSendType.Email],
});
Push Notifications to Mobile Devices (iOS/Android)
Amazon SNS can send push notifications to mobile devices through platform application endpoints. Here's how to send notifications to Apple (APNs) and Android (FCM/GCM) devices:
import { Airhorn } from 'airhorn';
import { AirhornAws } from '@airhornjs/aws';
const awsProvider = new AirhornAws({
region: 'us-east-1',
capabilities: [AirhornSendType.SMS],
});
const airhorn = new Airhorn({
providers: [awsProvider],
});
const data = {
orderId: '12345',
};
const template = {
from: 'YourApp',
content: JSON.stringify({
aps: {
alert: {
title: 'New Order',
body: 'You have a new order #<%= orderId %>',
},
badge: 1,
sound: 'default',
},
orderId: '12345',
}),
};
await airhorn.send(
'arn:aws:sns:us-east-1:123456789012:endpoint/APNS/YourApp/abc123',
template,
AirhornSendType.MobilePush,
{
MessageStructure: 'json',
MessageAttributes: {
'AWS.SNS.MOBILE.APNS.PUSH_TYPE': {
DataType: 'String',
StringValue: 'alert',
},
},
},
);
Note: Before sending push notifications, you need to:
- Create platform applications in SNS for APNs/FCM
- Register device tokens and create platform endpoints
- Optionally create SNS topics for broadcasting
- Configure proper IAM permissions for SNS platform endpoints
Configuration
AirhornAwsOptions
region (required): AWS region (e.g., 'us-east-1', 'eu-west-1')
accessKeyId (optional): AWS access key ID (uses AWS SDK credential chain if not provided)
secretAccessKey (optional): AWS secret access key (uses AWS SDK credential chain if not provided)
sessionToken (optional): AWS session token for temporary credentials
capabilities (optional): Array of AirhornSendType values to specify which services to enable (defaults to both SMS and Email)
Additional Options
You can pass additional provider-specific options as the second parameter to the send method:
Amazon SNS Options
await airhorn.send(to, message, {
smsType: 'Promotional',
maxPrice: '0.50',
});
Amazon SES Options
await airhorn.send(to, message, {
ccAddresses: ['cc@example.com'],
bccAddresses: ['bcc@example.com'],
replyToAddresses: ['reply@example.com'],
returnPath: 'bounces@example.com',
configurationSetName: 'my-configuration-set',
tags: [
{ Name: 'campaign', Value: 'summer-sale' },
{ Name: 'customer', Value: 'vip' }
],
});
Prerequisites
AWS Credentials
The AWS SDK will automatically look for credentials in the following order:
- Credentials passed explicitly in
AirhornAwsOptions
- Environment variables (
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
- Shared credentials file (
~/.aws/credentials)
- IAM role (when running on EC2, ECS, Lambda, etc.)
Amazon SNS Setup
- Ensure your AWS account has SNS permissions
- Configure SMS settings in SNS console if needed
- Note that SMS capabilities and pricing vary by region
Amazon SES Setup
- Verify your sender email address or domain in SES
- Request production access (SES starts in sandbox mode)
- Configure any necessary SES settings (configuration sets, etc.)
IAM Permissions
Minimum required IAM permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ses:SendEmail"
],
"Resource": "*"
}
]
}
How to Contribute
Now that you've set up your workspace, you're ready to contribute changes to the airhorn repository you can refer to the CONTRIBUTING guide. If you have any questions please feel free to ask by creating an issue and label it question.
Licensing and Copyright
This project is MIT License Š Jared Wray