简体   繁体   中英

Using, in a aws LAMBDA, parameters of axios

I use reactjs to create a web page, and I need to use GET from axios to send some parameters to my lambda.

For that i'm using this code:

await axios.get("endpoint-API",
  { params: {
resultat_net_N1:`${resultat_net_N1_form}, ${resultat_net_N1}, ${resultat_net_N1_form_1}, ${resultat_net_N1_1}`,
resultat_net_N: `${resultat_net_N_form}, ${resultat_net_N}, ${resultat_net_N_form_1}, ${resultat_net_N_1}`,
              }
         }
    )

And my lambda is:

exports.handler = (event, context, callback) => {
    console.log(event.queryStringParameters)
    //or
    // console.log(event.pathParameters )
    const response = {
    statusCode: 200,
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Credentials': true,
    },
    body: JSON.stringify('Hello from new Lambda!'),
   };
};

But when i'm trying to use this codes, my lambda is printing all the time undefined . Which brings me to my question, are there a few things I do wrong in my way of sending these parameters with get? or on the lambda aws? I also used the following method, and I had the same problem:

axios.get('my_endpoint/?foo=bar')

Thanks for the help

From the comments, it appears that you are using a HTTP API Gateway integration with no mapping. This is why your event object is empty.

You should have a look at the different types of API Gateway integration here and decide which is the best fit for you.

But with your current Lambda code, you just need to tick the HTTP Proxy integration box in Integration Request on API Gateway console to get this to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM