Skip to content

Instantly share code, notes, and snippets.

@tfhartmann
Created February 12, 2014 14:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfhartmann/8956049 to your computer and use it in GitHub Desktop.
Save tfhartmann/8956049 to your computer and use it in GitHub Desktop.
Example script on how to publish a message to an AWS SNS Queue
#!//opt/boxen/homebrew/bin/python
import boto.sns
import json
REGION = 'us-west-2'
TOPIC = '<ARN>'
URL = '<Body of Message in this example I used a url>'
conn = boto.sns.connect_to_region( REGION )
pub = conn.publish( topic = TOPIC, message = URL )
@chris-hailstorm
Copy link

For those seeing this post years later -- the boto3 approach is much different.

@Shemeikka
Copy link

This page is quite high on google search results so here's an example on how to do this with Boto3

This requires that you have set AWS credentials to your ~/.aws/credentials and the default region in ~/.aws/config

import boto3

client = boto3.client('sns')

response = client.publish(
    TopicArn='<your topic arn>',    
    Message='<your message>'
)
print("Response: {}".format(response))

Documentation

@vivshri
Copy link

vivshri commented May 23, 2018

Added region name too

`
import boto3

client = boto3.client('sns',, region_name='us-east-1')

response = client.publish(
TopicArn='',
Message=''
)
print("Response: {}".format(response))
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment