Skip to content

Instantly share code, notes, and snippets.

@benrules2
Last active October 13, 2017 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benrules2/c6ab906d94e4988c92b1596d20b5f7a2 to your computer and use it in GitHub Desktop.
Save benrules2/c6ab906d94e4988c92b1596d20b5f7a2 to your computer and use it in GitHub Desktop.
Read Queue on Target Platform
import boto3
import os
import time
access_key = "ACCESS_KEY"
access_secret = "ACCESS_SECRET"
region = "REGION"
queue_url = "QUEUE_URL"
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, regio
n_name = region)
waittime = 20
client.set_queue_attributes(QueueUrl = queue_url, Attributes = {'ReceiveMessageWaitTimeSeconds': str(waittime)})
time_start = time.time()
while (time.time() - time_start < 60):
print("Checking...")
try:
message = pop_message(client, queue_url)
print(message)
if message == "on":
os.system("~/tvon.sh")
elif message == "off":
os.system("~/tvoff.sh")
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment