# help

Michael James Munar

03/11/2022, 9:12 AM
Hi guys I wrote a custom handler which checks if the authorization token is present in out DB Lambda Function :
export const main = customHandler(async (event) =>{})
Custom Handler:
Copy code
export default function customHandler(lambda) {
// function here to do axios post to auth server
return async function (event, context) {
      var verifyStatus = await verify(event)
      let body, statusCode;
      try {
        // Run the Lambda
        body = await lambda(event, context);
        statusCode = 200;
      } catch (e) {
        body = { error: e.message };
        statusCode = 500;
      // Return HTTP response
      return {
        body: JSON.stringify(body),
It proceeds normally until I reference event.body Whether I do
Copy code
var test = event.body
var test2 = JSON.parse(event.body)
I keep getting this error Error:
Copy code
lambda Promise {
  <rejected> TypeError: Cannot read properties of undefined (reading 'body')
      at D:\WebProjects\serverless-referral\.sst\artifacts\kakima-referral-referral-Api-Lambda_POST_-protected-create\src\post\protected\referralLink.js:2854:30
      at withAuthHandler (D:\WebProjects\serverless-referral\.sst\artifacts\kakima-referral-referral-Api-Lambda_POST_-protected-create\src\post\protected\referralLink.js:2827:25)
      at Object.<anonymous> (D:\WebProjects\serverless-referral\.sst\artifacts\kakima-referral-referral-Api-Lambda_POST_-protected-create\src\post\protected\referralLink.js:2853:12)
      at Module._compile (node:internal/modules/cjs/loader:1103:14)
      at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
      at Module.load (node:internal/modules/cjs/loader:981:32)
      at Function.Module._load (node:internal/modules/cjs/loader:822:12)
      at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29)
      at (node:internal/modules/esm/module_job:195:25)
      at async Promise.all (index 0)
Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: Cannot read properties of undefined (reading 'body')","reason":"TypeError: Cannot read properties of undefined (reading 'body')","promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: Cannot read properties of undefined (reading 'body')","    at process.<anonymous> (file:///D:/WebProjects/serverless-referral/node_modules/@serverless-stack/aws-lambda-ric/lib/index.js:34:23)","    at process.emit (node:events:520:28)","    at emit (node:internal/process/promises:133:20)","    at processPromiseRejections (node:internal/process/promises:260:27)"," 
   at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
Can someone give me an insight on this? TLDR: Post request on a lambda with custom handler, cannot reference event.body

Ross Coundon

03/11/2022, 9:25 AM
There might be a way to configure the authorizer to receive the body but the standard way of doing things is for the authorizer to interrogate only the headers of the request. See this for what the input contains


03/11/2022, 10:49 AM
@Michael James Munar Parameter mapping might help in this case. Essentially, you would map somethign from
. But I’m not sure if that mapping is done prior to hitting the authorizer or after.
Might be eaiser if u passed the token through header?