Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

Within my lambda function, which takes in event api query strings, I want to check if one is present. The below works if it is:

if event['queryStringParameters']['order'] == 'desc':

        file_names.append('hello')

I have tried event['queryStringParameters']['order'] != null but if there is no order query string used the lambda function the function breaks causing a 502 response. How do I check if a query string is not used without it breaking?

1 Answer

0 votes
by (44.4k points)
edited by

Check if the dict has a key before referencing it.

if 'queryStringParameters' in event and 'order' in event['queryStringParameters']:

Are you looking to crack the AWS Certification Exam? Check out Intellipaat's AWS Course page! 

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories

...