AWS API Gateway Not Passing Query Parameters to Lambda Function - 'NoneType' scenarios
I'm stuck on something that should probably be simple. I need help solving After trying multiple solutions online, I still can't figure this out. I'm sure I'm missing something obvious here, but I'm working with an scenario with AWS API Gateway where my Lambda function is not receiving query parameters as expected. I've set up a simple API Gateway with a Lambda integration, and I'm trying to pass a query parameter called `userId`. However, when I invoke the API endpoint, my Lambda function logs show that the event object contains `None` for `queryStringParameters`, leading to a `NoneType` behavior when I try to access it. Here's the relevant part of my API Gateway configuration: - **HTTP Method**: GET - **Integration Request**: Lambda Function - **Request Mapping Template**: I have a mapping template to convert the incoming request to JSON, but I might not be doing it correctly. In my Lambda function, I'm expecting the `userId` parameter like this: ```python import json def lambda_handler(event, context): user_id = event['queryStringParameters']['userId'] if user_id is None: return { 'statusCode': 400, 'body': json.dumps('userId parameter is required') } # process user_id here ``` To troubleshoot, I tested the API directly in the AWS console with the following URL: ``` https://my-api-id.execute-api.us-east-1.amazonaws.com/prod/users?userId=123 ``` But the logs show that `event['queryStringParameters']` is `None`. I've also checked that the API Gateway is deployed correctly and that the method request settings allow for query string parameters. I tried adding a mapping template like this: ```json { "userId": "$input.params('userId')" } ``` But it doesn't seem to have made a difference. What am I missing? Is there a specific step or configuration in the API Gateway setup that I might be overlooking? For context: I'm using Python on Linux. Is there a better approach? Any suggestions would be helpful. I'm working in a Ubuntu 22.04 environment. What's the best practice here? What are your experiences with this?