
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@airhornjs/aws
Advanced tools
AWS SNS and SES provider for Airhorn.
npm install airhorn @airhornjs/aws
import { Airhorn } from 'airhorn';
import { AirhornAws } from '@airhornjs/aws';
// Create AWS provider for SMS
const awsProvider = new AirhornAws({
region: 'us-east-1',
accessKeyId: 'your-access-key', // Optional, uses AWS SDK credential chain
secretAccessKey: 'your-secret-key', // Optional, uses AWS SDK credential chain
});
// Create Airhorn instance with AWS provider
const airhorn = new Airhorn({
providers: [awsProvider],
});
// Send SMS
const message = {
from: '+1234567890', // Your sender ID or phone number
content: 'Hello John!, your order #12345 has been shipped!',
type: AirhornSendType.SMS,
};
const result = await airhorn.send(
'+0987654321', // to
message,
);
import { Airhorn } from 'airhorn';
import { AirhornAws } from '@airhornjs/aws';
// Create AWS provider with SES support
const awsProvider = new AirhornAws({
region: 'us-east-1',
accessKeyId: 'your-access-key', // Optional
secretAccessKey: 'your-secret-key', // Optional
});
// Create Airhorn instance
const airhorn = new Airhorn({
providers: [awsProvider],
});
const data = {
orderId: '656565',
customerName: 'John',
};
// Send Email
const template = {
from: 'sender@example.com', // Must be verified in SES
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', // to
template,
data,
AirhornSendType.Email
);
By default, the provider supports both SMS and email notifications:
const provider = new AirhornAws({
region: 'us-east-1',
// AWS credentials can be provided explicitly or loaded from environment
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key',
sessionToken: 'your-session-token', // Optional for temporary credentials
});
// Provider capabilities will include both 'sms' and 'email' by default
console.log(provider.capabilities); // ['sms', 'email']
You can specify which services to enable using the capabilities
option:
// SMS only
const smsProvider = new AirhornAws({
region: 'us-east-1',
capabilities: [AirhornSendType.SMS],
});
// Email only
const emailProvider = new AirhornAws({
region: 'us-east-1',
capabilities: [AirhornSendType.Email],
});
// Both (explicit)
const bothProvider = new AirhornAws({
region: 'us-east-1',
capabilities: [AirhornSendType.SMS, AirhornSendType.Email],
});
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], // SNS handles mobile push
});
const airhorn = new Airhorn({
providers: [awsProvider],
});
const data = {
orderId: '12345',
};
// Send to iOS device via APNs
const template = {
from: 'YourApp', // Sender ID
content: JSON.stringify({
aps: {
alert: {
title: 'New Order',
body: 'You have a new order #<%= orderId %>',
},
badge: 1,
sound: 'default',
},
// Custom data
orderId: '12345',
}),
};
// Send to Apple device endpoint ARN
await airhorn.send(
'arn:aws:sns:us-east-1:123456789012:endpoint/APNS/YourApp/abc123', // iOS endpoint ARN
template,
AirhornSendType.MobilePush,
{
MessageStructure: 'json', // Required for platform-specific payloads
MessageAttributes: {
'AWS.SNS.MOBILE.APNS.PUSH_TYPE': {
DataType: 'String',
StringValue: 'alert', // or 'background'
},
},
},
);
Note: Before sending push notifications, you need to:
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 credentialscapabilities
(optional): Array of AirhornSendType
values to specify which services to enable (defaults to both SMS and Email)You can pass additional provider-specific options as the second parameter to the send method:
await airhorn.send(to, message, {
smsType: 'Promotional', // or 'Transactional' (default)
maxPrice: '0.50', // Maximum price in USD
// ... other SNS PublishCommand 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' }
],
// ... other SES SendEmailCommand options
});
The AWS SDK will automatically look for credentials in the following order:
AirhornAwsOptions
AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
)~/.aws/credentials
)Minimum required IAM permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ses:SendEmail"
],
"Resource": "*"
}
]
}
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
.
This project is MIT License © Jared Wray
FAQs
AWS SNS and SES provider for Airhorn
We found that @airhornjs/aws demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.