Skip to content

Commit

Permalink
Update send_message.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichman authored Jan 25, 2019
1 parent ab23608 commit afc98a4
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions Triggering-Lambda-from-SQS/send_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,41 @@
from faker import Faker


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--queue-name", "-q", required=True,
help="SQS queue URL")
parser.add_argument("--interval", "-i", required=True,
help="timer interval", type=float)
parser.add_argument("--message", "-m", help="message to send")
parser.add_argument("--log", "-l", default="INFO",
help="logging level")
args = parser.parse_args()
parser = argparse.ArgumentParser()
parser.add_argument("--queue-name", "-q", required=True,
help="SQS queue name")
parser.add_argument("--interval", "-i", required=True,
help="timer interval", type=float)
parser.add_argument("--message", "-m", help="message to send")
parser.add_argument("--log", "-l", default="INFO",
help="logging level")
args = parser.parse_args()

if args.log:
logging.basicConfig(
format='[%(levelname)s] %(message)s', level=args.log)
if args.log:
logging.basicConfig(
format='[%(levelname)s] %(message)s', level=args.log)

else:
parser.print_help(sys.stderr)
else:
parser.print_help(sys.stderr)

sqs = boto3.client('sqs')
sqs = boto3.client('sqs')

response = sqs.get_queue_url(QueueName=args.queue_name)
response = sqs.get_queue_url(QueueName=args.queue_name)

queue_url = response['QueueUrl']
queue_url = response['QueueUrl']

logging.info(queue_url)
logging.info(queue_url)

while True:
message = args.message
if not args.message:
fake = Faker()
message = fake.text()
while True:
message = args.message
if not args.message:
fake = Faker()
message = fake.text()

logging.info('Sending message: ' + message)
logging.info('Sending message: ' + message)

response = sqs.send_message(
QueueUrl=queue_url, MessageBody=message)
response = sqs.send_message(
QueueUrl=queue_url, MessageBody=message)

logging.info('MessageId: ' + response['MessageId'])
sleep(args.interval)
logging.info('MessageId: ' + response['MessageId'])
sleep(args.interval)

0 comments on commit afc98a4

Please sign in to comment.