I've done this several time with API Gateway. I'm now trying to do it with a function URL. When I try to add a GET style parameter onto the end of the function URL I get error: KeyName - In other words, the parameter is not being passed to the function. If I dump the entire event to the console, I see that the request has not been mapped into an event Json. This is how the API Gateway does it. The online directions say that the function URL also maps to an event (just like the api gateway) but that isn't what I am seeing.
This is the event that is being passed when using Function URL:
{'version': '2.0', 'routeKey': '$default', 'rawPath': '/', 'rawQueryString': 'epoch=1724773643', 'headers': {'sec-fetch-mode': 'navigate', 'x-amzn-tls-version': 'TLSv1.3', 'sec-fetch-site': 'none', 'x-forwarded-proto': 'https', 'accept-language': 'en-US,en;q=0.9', 'x-forwarded-port': '443', 'dnt': '1', 'x-forwarded-for': '73.40.230.54', 'sec-fetch-user': '?1', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7', 'x-amzn-tls-cipher-suite': 'TLS_AES_128_GCM_SHA256', 'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"', 'x-amzn-trace-id': 'Root=TTTTTT', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'host': 'TTTTT.lambda-url.us-east-1.on.aws', 'upgrade-insecure-requests': '1', 'cache-control': 'max-age=0', 'accept-encoding': 'gzip, deflate, br, zstd', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0', 'sec-fetch-dest': 'document'}, 'queryStringParameters': {'epoch': '1724773643'}, 'requestContext': {'accountId': 'anonymous', 'apiId': 'kXXXe', 'domainName': 'XXXXmbda-url.us-east-1.on.aws', 'domainPrefix': 'TTTTTTTe', 'http': {'method': 'GET', 'path': '/', 'protocol': 'HTTP/1.1', 'sourceIp': 'TTTTT', 'userAgent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0'}, 'requestId': 'eXXXXXfc019', 'routeKey': '$default', 'stage': '$default', 'time': '27/Aug/2024:16:25:14 +0000', 'timeEpoch': 1724775914041}, 'isBase64Encoded': False}
And here is what I get when I execute it from the "test" button in lambda or via API Gateway:
{'epoch': 1724773643}
Any idea why the event is mapped to the correct JSON when using test button, but when accessing from Function URL it is completely different?
It is the same code. The only difference is if I click the "test" button in the lambda editor screen, or if the code runs via someone connecting to the Function URL. I placed the lambda function behind API Gateway and it now works as expected.
I'm just not sure why it doesn't work the same via 'test' or via connecting to the URL.
I'm attempting to access the parameters via the EVENT variable:
def lambda_handler(event, context):
If I then perform:
print(event)
I see the differences described above for how it looks from API Gateway (or test button) and how it looks from someone hitting the Function URL.