Skip to content

Instantly share code, notes, and snippets.

@AngelChaidez
Created April 19, 2023 00:41
Show Gist options
  • Save AngelChaidez/f7f215ce7168fe5c7e1e792fcd513421 to your computer and use it in GitHub Desktop.
Save AngelChaidez/f7f215ce7168fe5c7e1e792fcd513421 to your computer and use it in GitHub Desktop.
#!/usr/bin/ env python3.11
# This script will send messages to an SQS queue
import boto3
import json
import random
from datetime import datetime
from botocore.exceptions import ClientError
import string
# Function will send in messages to our SQS queue, the messages will compose of todays date followed by
# 5 random alphanumeric characters. We will send our messages to our QueueUrl
def lambda_handler(event, context):
todays_date = datetime.now().strftime("%Y-%m-%d")
message = todays_date +"".join(random.choices(string.ascii_letters + string.digits, k=5))
sqs = boto3.client('sqs')
print(message)
sqs = boto3.client('sqs')
response = sqs.send_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/758719472525/SQS_2023-04-17',
MessageBody= (f"Sucessfully sent: {message}")
)
return {
'statusCode': 200,
'body': json.dumps(response, indent=4)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment