Last active
January 31, 2023 16:20
-
-
Save srcecde/0eda249843a92a5c9e08d96a53952959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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