AWS API Gateway only passing 1st variable to function, but lambda test passes all
AWS API Gateway only passing 1st variable to function, but lambda test passes all
I'm finding this odd issue where AWS is passing the URL String parameters to a Lambda function properly but there is a break down in API gateway only when Lambda runs a Python handler function that calls
KeywordSearch(keyword,page,RPP)
that passes 3 variables to keywordSearch. In the lambda IDE test, it works without issue and prints out all 3 variables as seen in the logs as
InsideKeywordSearch, Vars=:
keyword:
bombing
page:
1
RPP:
10
But when I run an API Gateway test the log is showing the variable is not passed into the function as seen in the log showing no variable for RPP or Page.
The keyword is passed only. Am I not defining the function correctly? it works in Lambda why not API gateway if this is so?
here is a snippet of the code.
Function Call
def handler(event, context):
print('Inside Handler Funciton')
keyword = event.get('search_keyword', None)
id = event.get('id', None)
RPP = event.get('RPP', 10)
page = event.get('page', 1)
#get event variables, if passed and filter bad input
print("keyword")
print(keyword)
print("id")
print(id)
print('RPP')
print(RPP)
print('page')
print(page)
if keyword is not None:
return keywordSearch(keyword,page,RPP)
elif id is not None:
return idSearch(id)
else:
return ""
Function
def keywordSearch (keyword, page, RPP):
print('InsideKeywordSearch, Vars=: ')
print("keyword: ")
print(keyword)
print(" page: ")
print(page)
print(" RPP: ")
print(RPP)
Lambda Logs shows
Function Logs:
6d Version: $LATEST
Inside Handler Funciton
keyword
bombing
id
None
RPP
10
page
1
InsideKeywordSearch, Vars=:
keyword:
bombing
page:
1
RPP:
10
[INFO] 2018-06-30T03:04:56.240Z 5dc7a2cc-7c12-11e8-8f39-f5112d2e976d SUCCESS: Connection to RDS mysql instance succeeded
API Gateway call shows
{
"errorMessage": "unsupported operand type(s) for -: 'str' and 'int'",
"errorType": "TypeError",
"stackTrace": [
[
"/var/task/app.py",
144,
"handler",
"return keywordSearch(keyword,page,RPP)"
],
[
"/var/task/app.py",
93,
"keywordSearch",
"sql = f"SELECT attackid, SUM(MATCH(attack_fulltext) AGAINST('%{keyword}%' IN BOOLEAN MODE)) as score FROM search_index WHERE MATCH(attack_fulltext) AGAINST('%{keyword}%' IN BOOLEAN MODE) GROUP BY attackid ORDER BY score DESC Limit { ((page-1)*RPP) },{(RPP)};""
]
]
}
Which tells me that it's not passing the variables because the SQL sting becomes invalid.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment