asked    Herman     2018-10-22       python       79 view        1 Answer

[SOLVED] AWS / Python Lambda function checking if a query string is present

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  

        answered    Madge     2018-10-22      

Always check if the dict contains an key before referencing it.

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




Your Answer





 2018-10-22         Kay

Get json field value by variable with jq

I am trying to read the value of a field of a json variable, the field name is stored in a variable as well.What I tried:$ jsonVar=`cat test-config.json`$ echo $jsonVar{ "server-test": "xxx", "server2-test": "xxx", "server3-test": "xxx"}$ echo $itserver-test$ itVersion=$(jq --arg test "${it}" '.["${test}"]' <<< $jsonVar);$ echo $itVersionnull$itVersion should now have the value of "server-test" but is null, it seems my JQ command is wrong, but I cant figure out why. The variable is only accessible as $var, not ${var}. Additionnaly, it is expanded to a quoted str...
 bash                     1 answers                     61 view
 2018-10-22         Glenn

How to get elapsed time with system.time?

Is there a way to get just the numerical value of elapsed time from system.time?I want to measure the elapsed time of a bunch of functions I wrote. I call those functions like this:time_f1 <- system.time({ function_1(x,y,z) and some other stuff})time_f2 <- system.time({ function_2(x,y,z) and some other stuff})...time_f1 and the other measured times are objects of type proc_time and I have to extract the elapsed time.Is there a possibility to directly get only the numerical value of the elapsed times, so i can store them in a vector like this:time_f[1] <- system...
 r                     1 answers                     61 view
 2018-10-22         Leo

Rotate transformation on matplotlib axis in subplot

I am trying to create a four-panel figure where the bottom-left panel contains a scatter plot, and the other three panels contain histograms. The top-left will be a standard histogram across the x-dimension of the scatter, the bottom-right will be a 90° rotated histogram for the y-dimension. Both of these are easy to do in matplotlib.I am running into problems with the third histogram, which is to be a 45° rotated plot in the top-right of the figure giving the distribution of the differences between the x and y points. I have made such figures before by manually rotating an...
 python                     1 answers                     61 view