AWS Certified Solutions Architect - Professional 2020

Sign Up Free or Log In to participate!

Error in EC2 Scaling with SQS Lab

Hello,

I know this not directly related to this class (which I plan to take shortly) but I thought it would be the best place to ask a python scripting question on a lab. I was working through the EC2 scaling with SQS lab and got the following error when I attempted to run the send_messages.py script:

while True:

try:

message = str(uuid.uuid4())

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

response = sqs.sendmessage(QueueUrl=queueurl, MessageBody=message)

logging.info("MessageId: " + response["MessageId"])

sleep(args.interval)

except ClientError as e:

logging.error(e)

exit(1)

[cloud_user@ip-10-0-1-187 ~]$

[cloud_user@ip-10-0-1-187 ~]$

[clouduser@ip-10-0-1-187 ~]$ python sendmessages.py

File "send_messages.py", line 27

logging.info(f"Getting queue URL for queue: {args.queue_name}")

^

SyntaxError: invalid syntax

[clouduser@ip-10-0-1-187 ~]$ nano sendmessages.py

[clouduser@ip-10-0-1-187 ~]$ nano sendmessages.py

[clouduser@ip-10-0-1-187 ~]$ python sendmessages.py

File "send_messages.py", line 35

logging.info(f"Queue URL: {queue_url}")

^

SyntaxError: invalid syntax

[clouduser@ip-10-0-1-187 ~]$ nano sendmessages.py

[clouduser@ip-10-0-1-187 ~]$ python sendmessages.py

File "send_messages.py", line 35

logging.info(f"Queue URL: {queue_url}")

^

SyntaxError: invalid syntax

I tried to edit the script by commenting out the lines with errors (not sure this would work anyway) but I could not get any of my changes to run in the next time I ran the script. Would you be able to take a look at the above error and offer a workaround?

Thanks

1 Answers

Hi Bill,

I’m not a real Python guru, but I ran the code block below through a Python syntax checker and it passed.   

while True:  
    try:  
        message = str(uuid.uuid4())  
        logging.info("Sending message: " + message)  
        response = sqs.sendmessage(QueueUrl=queueurl, MessageBody=message)  
        logging.info("MessageId: " + response["MessageId"])  
        sleep(args.interval)  
    except ClientError as e:  
        logging.error(e)  
exit(1)

I do see in your example that your syntax error is on a line that has an extra f in there…normally, I’d expect to see args at the end and not in the front…

logging.info(**f**"Queue URL: {queue_url}")
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?