question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot access event.queryStringParameters[ ... ][ ... ]

See original GitHub issue

I believe i’m having issues with this topic as well… How do you access queryStringParameter?, if I remove the extra JSON argument in the call to API.get it works perfect! I’m just trying to figure out if this is indeed a problem with AWS amplify and how i’m sending the JSON parameter. Thank you in advance if you can push me in the correct direction.

My client side code (aws-amplify 0.2.11 ): return API.get('trips','/days', {'queryStringParameters': {'param1': "99b60260-363c-11e8-b7ca-250a890d0675"}})

My API side code ( using serverless-webpack v 1.6.0, aws sdk v 2.202.0 ) : serverless.yml file :

listDays:
        handler: listDays.main
        events:
          - http:
              path: days
              method: get
              cors: true
              authorizer: aws_iam

API-javascript listDays.js code trying to access the event, the event.queryStringParameter.param1 just causes an error because it’s null:

export async function main(event,context,callback) {

    const params = {
        TableName: "DAYS",

        KeyConditionExpression: "tripId = :tripId",
        ExpressionAttributeValues: {
            ":tripId": event.queryStringParameters.param1
        }
    }

  //console.log(data.tripId)
    try {
        //result will return an array of trips
        const result = await dynamoDbLib.call("query", params)
        callback(null, success(result.Items))
    } catch (e) {
        callback(null, failure({status: false}))
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
causingchaos2commented, Apr 6, 2018

For any amature coder like myself: Because appending a JSON object queryStringParamaters is currently not implemented yet, Calling using AWS-amplify, on the client code side by appending to URL:

return API.get('trips',/days?param1=${this.props.tripId})

API-side Node.js code: serverless yml file:

listDays:
        handler: listDays.main
        events:
          - http:
              path: days
              method: get
              cors: true
              authorizer: aws_iam

you access param1 by doing the following, also in the API-side Node.js code:

if (event.queryStringParameters !== null && event.queryStringParameters !== undefined) {
        if (event.queryStringParameters.param1 !== undefined &&
          event.queryStringParameters.param1 !== null &&
          event.queryStringParameters.param1 !== "") {
          console.log("Received proxy: " + event.queryStringParameters.param1);
          tripId = event.queryStringParameters.param1;
        }
      }
1reaction
franciscocpgcommented, Apr 5, 2018

@HyperBrain I’ve never used aws-amplify too, but as you’ve mentioned, 1. It’s just an API URL call with query parameter and 2. it’s necessary to check queryStringParameters before using it. Here is an example from aws docs.

if (event.queryStringParameters !== null && event.queryStringParameters !== undefined) {
        if (event.queryStringParameters.name !== undefined && 
            event.queryStringParameters.name !== null && 
            event.queryStringParameters.name !== "") {
            console.log("Received name: " + event.queryStringParameters.name);
            name = event.queryStringParameters.name;
        }
}

Also it looks like that queryStringParameters is not working in aws-amplify: https://github.com/aws/aws-amplify/issues/127.

And there is an opened PR about this issue: https://github.com/aws/aws-amplify/pull/378

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correctly call queryStringParameters for AWS Lambda ...
I recommend adding a couple of diagnostics, as follows: import json def lambda_handler(event, context): print('event:', json.dumps(event)) ...
Read more >
queryStringParameters not working with redirect on production
Given the redirect above, I would expect a GET to /thing to proxy a call to the netlify function URL, which would result...
Read more >
API (REST) - Fetching data - JavaScript - AWS Amplify Docs
Using the GET API REST in Amplify - JavaScript - AWS Amplify Docs. ... queryStringParameters res.json({ event: req.apiGateway.event, // to view all event...
Read more >
Accessing query parameter in Lambda with Python - Edureka
I am able to access body part using <Event> like <event['Number1']> but not able to access other request or header parameter . Have...
Read more >
Set up Lambda proxy integrations in API Gateway
GET |POST|PUT|... /{proxy+} : The client can set a particular resource path hierarchy, any headers, query string parameters, and applicable payload to pass ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found