itsmostafa/aws-agent-skills / skills/sns
sns
VerifiedAWS SNS notification service for pub/sub messaging. Use when creating topics, managing subscriptions, configuring message filtering, sending notifications, or setting up mobile push.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 9.6 KB |
| notification-patterns.md | markdown | 7.7 KB |
notification-patterns.md
View on GitHub# SNS Notification Patterns
Advanced notification patterns and configurations.
## Topic Policies
### Allow Cross-Account Publishing
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:root"
},
"Action": "sns:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-topic"
}
]
}
```
### Allow S3 Events
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": "sns:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:my-topic",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:::my-bucket"
}
}
}
]
}
```
### Allow CloudWatch Alarms
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "cloudwatch.amazonaws.com"
},
"Action": "sns:Publish",
"Resource": "arn:aws:sns:us-east-1:123456789012:alerts-topic"
}
]
}
```
## Delivery Policies
### HTTP/HTTPS Retry Policy
```json
{
"http": {
"defaultHealthyRetryPolicy": {
"minDelayTarget": 1,
"maxDelayTarget": 60,
"numRetries": 50,
"numMaxDelayRetries": 0,
"numNoDelayRetries": 3,
"numMinDelayRetries": 2,
"backoffFunction": "exponential"
},
"disableSubscriptionOverrides": false,
"defaultThrottlePolicy": {
"maxReceivesPerSecond": 10
}
}
}
```
### Configure Delivery Policy
```bash
aws sns set-topic-attributes \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-topic \
--attribute-name DeliveryPolicy \
--attribute-value file://delivery-policy.json
```
## Dead-Letter Queues
### Configure DLQ for Subscription
```bash
# Create DLQ
aws sqs create-queue --queue-name sns-dlq
# Get DLQ ARN
DLQ_ARN=$(aws sqs get-queue-attributes \
--queue-url https://sqs.us-east-1.amazonaws.com/123456789012/sns-dlq \
--attribute-names QueueArn --query 'Attributes.QueueArn' --output text)
# Set DLQ on subscription
aws sns set-subscription-attributes \
--subscription-arn arn:aws:sns:us-east-1:123456789012:my-topic:abc123 \
--attribute-name RedrivePolicy \
--attribute-value "{\"deadLetterTargetArn\":\"${DLQ_ARN}\"}"
```
## SMS Notifications
### Send SMS
```python
import boto3
sns = boto3.client('sns')
# Direct publish to phone number
sns.publish(
PhoneNumber='+12025551234',
Message='Your verification code is 123456',
MessageAttributes={
'AWS.SNS.SMS.SMSType': {
'DataType': 'String',
'StringValue': 'Transactional' # or 'Promotional'
},
'AWS.SNS.SMS.SenderID': {
'DataType': 'String',
'StringValue': 'MyApp'
}
}
)
```
### SMS Preferences
```bash
aws sns set-sms-attributes \
--attributes '{
"DefaultSMSType": "Transactional",
"DefaultSenderID": "MyApp",
"MonthlySpendLimit": "100"
}'
```
### Check SMS Status
```bash
# Check spending
aws sns get-sms-attributes \
--attributes MonthlySpendLimit
```
## Mobile Push Notifications
### Create Platform Application
```bash
# For iOS (APNS)
aws sns create-platform-application \
--name MyApp-iOS \
--platform APNS \
--attributes '{
"PlatformCredential": "<private-key>",
"PlatformPrincipal": "<certificate>"
}'
# For Android (FCM)
aws sns create-platform-application \
--name MyApp-Android \
--platform GCM \
--attributes '{
"PlatformCredential": "<server-key>"
}'
```
### Register Device Endpoint
```python
import boto3
sns = boto3.client('sns')
# Register device
response = sns.create_platform_endpoint(
PlatformApplicationArn='arn:aws:sns:us-east-1:123456789012:app/GCM/MyApp-Android',
Token='device-token-from-fcm'
)
endpoint_arn = response['EndpointArn']
```
### Send Push Notification
```python
import boto3
import json
sns = boto3.client('sns')
# Direct to device
sns.publish(
TargetArn=endpoint_arn,
Message=json.dumps({
'default': 'Default message',
'GCM': json.dumps({
'notification': {
'title': 'New Message',
'body': 'You have a new message'
},
'data': {
'message_id': '12345'
}
})
}),
MessageStructure='json'
)
```
## Multi-Protocol Messages
### Protocol-Specific Messages
```python
import boto3
import json
sns = boto3.client('sns')
sns.publish(
TopicArn='arn:aws:sns:us-east-1:123456789012:my-topic',
Message=json.dumps({
'default': 'Default message for all protocols',
'email': 'Detailed email message with formatting',
'sms': 'Short SMS msg',
'lambda': json.dumps({'action': 'process', 'data': {...}}),
'sqs': json.dumps({'queue_message': {...}}),
'http': json.dumps({'webhook_payload': {...}})
}),
MessageStructure='json',
Subject='Email Subject Line'
)
```
## Raw Message Delivery
### Enable Raw Delivery for SQS
By default, SNS wraps messages. Raw delivery sends just the message body.
```bash
aws sns set-subscription-attributes \
--subscription-arn arn:aws:sns:us-east-1:123456789012:my-topic:abc123 \
--attribute-name RawMessageDelivery \
--attribute-value true
```
### Message Format Comparison
**Without raw delivery (wrapped):**
```json
{
"Type": "Notification",
"MessageId": "...",
"TopicArn": "arn:aws:sns:...",
"Subject": "...",
"Message": "{\"actual\":\"content\"}",
"Timestamp": "...",
"SignatureVersion": "1",
"Signature": "...",
"SigningCertURL": "...",
"UnsubscribeURL": "..."
}
```
**With raw delivery:**
```json
{"actual": "content"}
```
## FIFO Topics
### Create FIFO Topic
```bash
aws sns create-topic \
--name orders.fifo \
--attributes FifoTopic=true,ContentBasedDeduplication=true
```
### Subscribe FIFO Queue to FIFO Topic
```bash
# Create FIFO queue
aws sqs create-queue \
--queue-name order-processing.fifo \
--attributes FifoQueue=true
# Subscribe
aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:orders.fifo \
--protocol sqs \
--notification-endpoint arn:aws:sqs:us-east-1:123456789012:order-processing.fifo
```
### Publish to FIFO Topic
```python
sns.publish(
TopicArn='arn:aws:sns:us-east-1:123456789012:orders.fifo',
Message=json.dumps({'order_id': '12345'}),
MessageGroupId='customer-abc',
MessageDeduplicationId='order-12345-v1'
)
```
## Monitoring
### CloudWatch Metrics
Key metrics:
- `NumberOfMessagesPublished`
- `NumberOfNotificationsDelivered`
- `NumberOfNotificationsFailed`
- `PublishSize`
### Enable Delivery Status Logging
```bash
# Create IAM role for logging
aws sns set-topic-attributes \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-topic \
--attribute-name LambdaSuccessFeedbackRoleArn \
--attribute-value arn:aws:iam::123456789012:role/sns-delivery-status-role
aws sns set-topic-attributes \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-topic \
--attribute-name LambdaFailureFeedbackRoleArn \
--attribute-value arn:aws:iam::123456789012:role/sns-delivery-status-role
# Sample percentage (0-100)
aws sns set-topic-attributes \
--topic-arn arn:aws:sns:us-east-1:123456789012:my-topic \
--attribute-name LambdaSuccessFeedbackSampleRate \
--attribute-value 100
```
### Alarm for Failed Deliveries
```bash
aws cloudwatch put-metric-alarm \
--alarm-name "SNS-DeliveryFailures" \
--metric-name NumberOfNotificationsFailed \
--namespace AWS/SNS \
--dimensions Name=TopicName,Value=my-topic \
--statistic Sum \
--period 60 \
--threshold 1 \
--comparison-operator GreaterThanOrEqualToThreshold \
--evaluation-periods 1 \
--alarm-actions arn:aws:sns:us-east-1:123456789012:alerts-topic
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |