Skip to content

Instantly share code, notes, and snippets.

@gungoren
Last active February 1, 2023 23:08
Show Gist options
  • Save gungoren/0d1e19e076607384bec3cf7c9a78b1f2 to your computer and use it in GitHub Desktop.
Save gungoren/0d1e19e076607384bec3cf7c9a78b1f2 to your computer and use it in GitHub Desktop.
import os
import boto3
from time import sleep
sqs = boto3.client('sqs')
queue_url = os.getenv("QUEUE_URL")
def fib(num):
if num <= 1:
return 1
return fib(num - 1) + fib(num - 2)
if __name__ == '__main__':
while True:
try:
response = sqs.receive_message(
QueueUrl=queue_url,
AttributeNames=['SentTimestamp'],
MaxNumberOfMessages=1,
MessageAttributeNames=['All'],
VisibilityTimeout=10,
WaitTimeSeconds=10
)
if 'Messages' in response:
message = response['Messages'][0]
receipt_handle = message['ReceiptHandle']
msg = message['Body']
print(f"{msg} => {fib(int(msg))}")
sqs.delete_message(QueueUrl=queue_url, ReceiptHandle=receipt_handle)
sleep(2)
except:
print('Queue empty')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment