Skip to content

Instantly share code, notes, and snippets.

@benrules2
Last active October 8, 2017 18:31
Show Gist options
  • Select an option

  • Save benrules2/7dec72a521d9caa8f8631d1965d21e87 to your computer and use it in GitHub Desktop.

Select an option

Save benrules2/7dec72a521d9caa8f8631d1965d21e87 to your computer and use it in GitHub Desktop.
Queue Service
import boto3
access_key = "YOUR_ACCESS_KEY"
access_secret = "YOUR_ACCCESS_SECRET"
region ="YOUR_REGION"
queue_url = "YOUR_QUEUE_URL"
def post_message(client, message_body, url):
response = client.send_message(QueueUrl = url, MessageBody= message_body)
def pop_message(client, url):
response = client.receive_message(QueueUrl = url, MaxNumberOfMessages = 10)
#last message posted becomes messages
message = response['Messages'][0]['Body']
receipt = response['Messages'][0]['ReceiptHandle']
client.delete_message(QueueUrl = url, ReceiptHandle = receipt)
return message
client = boto3.client('sqs', aws_access_key_id = access_key, aws_secret_access_key = access_secret, region_name = region)
post_message(client, "test", queue_url)
message = pop_message(client, queue_url)
print(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment