0

I made a REST API with AWS Lambda+ API Gateway.

my API Gateway's Integration Request is LAMBDA_PROXY Type,

and I use params in Lambda like this. ( myparam is list type)

def lambda_handler(event, context):
    # TODO implement
    try:
        myparam = event['multiValueQueryStringParameters']['param1']
    #...

I tested my REST API in python like this.

url = 'https://***.amazonaws.com/default/myAPI'

param = {'param1':['1','2']}

res = requests.get(url=url,params=param).json()
print(res)

It works. but when I tried with another way like this,

url = 'https://***.amazonaws.com/default/myAPI?param1=1,2'

res = requests.get(url=url).json()
print(res)

It didn't work with this way. How to query parameters in case if I want to insert parameter into url directly?

1 Answer 1

2

Those tow requests are not equivalent. In order to prove it, we can print the formatted URL for the first request:

url = 'https://***.amazonaws.com/default/myAPI'

param = {'param1':['1','2']}

res = requests.get(url=url,params=param).json()

# Print the request URL
print(res.request.url)

This will print something like:

https://***.amazonaws.com/myAPI?param1=1&param1=2

So, in your second snippet, you probably would want to create your URL as follows:

url = 'https://***.amazonaws.com/myAPI?param1=1&param1=2'

res = requests.get(url=url).json()
print(res)

If you want to separate your parameters with commas, the value for param1 will be a string ('1,2'), not an list.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.