Skip to content

Instantly share code, notes, and snippets.

@srcecde
Last active January 31, 2023 16:20
Show Gist options
  • Save srcecde/0eda249843a92a5c9e08d96a53952959 to your computer and use it in GitHub Desktop.
Save srcecde/0eda249843a92a5c9e08d96a53952959 to your computer and use it in GitHub Desktop.
import os
import json
import boto3
def lambda_handler(event, context):
region_name = os.environ['AWS_REGION']
if event:
sqs = boto3.client('sqs', region_name=region_name)
queue_name = event['Records'][0]['eventSourceARN'].split(':')[-1]
queue_url = sqs.get_queue_url(
QueueName=queue_name,
)
for record in event['Records']:
body = record['body']
print(body)
# process message
response = sqs.delete_message(
QueueUrl=queue_url['QueueUrl'],
ReceiptHandle=record['receiptHandle']
)
return {
'statusCode': 200,
'body': json.dumps('Message processed successfully!')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment