https://serverless-stack.com/ logo
#sst
Title
# sst
o

outaTiME

05/20/2022, 5:02 PM
hello guys, for some reason I’m having problems when I configure the lambda authorizer for an endpoint, this was previously working and after the migration I can’t get it to work, in all cases I get
"Internal Server Error"
unless I disable it by putting
"none"
. Here I could see the call to the authorizer does it correctly but then it does not execute the endpoint:
Copy code
0a034172-e51c-4560-9206-f7758fd9aee0 REQUEST dev-ambito-dolar-stack-AuthorizerBD825682-RMeuTtqz2uyr [src/authorizers/basic.main] invoked by API GET /social-notify
0a034172-e51c-4560-9206-f7758fd9aee0 RESPONSE {"isAuthorized":true}
I tried to reduce everything to the minimum possible code, here I attach my definitions:
Copy code
// stack
const api = new sst.Api(stack, 'Api', {
  accessLog: {
    retention: 'one_week',
  },
  authorizers: {
    basicAuthorizer: {
      type: 'lambda',
      function: new sst.Function(stack, 'Authorizer', {
        handler: 'src/authorizers/basic.main',
      }),
    },
  },
  defaults: {
    authorizer: 'none',
    function: {
      environment: {
        SNS_TOPIC: topic.topicArn,
      },
    },
  },
  routes: {
    'GET /social-notify': {
      authorizer: 'basicAuthorizer',
      function: 'src/routes/social-notify.handler',
    },
  },
});
// src/authorizers/basic.main
export const main = async (event) => {
  const isAuthorized = process.env.SECRET_KEY === event?.headers?.authorization;
  return {
    isAuthorized,
  };
};
// src/routes/social-notify.handler
export async function handler(event) {
  // pass
  return {
    headers: { 'Content-Type': 'application/json; charset=utf-8' },
    body: JSON.stringify({
      // pass
    }),
    statusCode: 200,
  };
}
Solved, the missing piece is
responseTypes: ['simple']
which was not in the github examples or in the SST v1 documentation. This is how the definition would be:
Copy code
// stack
const api = new sst.Api(stack, 'Api', {
  accessLog: {
    retention: 'one_week',
  },
  authorizers: {
    basicAuthorizer: {
      type: 'lambda',
      function: new sst.Function(stack, 'Authorizer', {
        handler: 'src/authorizers/basic.main',
      }),
      responseTypes: ['simple'], // <<< MISSING PART
    },
  },
  defaults: {
    authorizer: 'none',
    function: {
      environment: {
        SNS_TOPIC: topic.topicArn,
      },
    },
  },
  routes: {
    'GET /social-notify': {
      authorizer: 'basicAuthorizer',
      function: 'src/routes/social-notify.handler',
    },
  },
});
f

Frank

05/25/2022, 2:58 AM
Hey @outaTiME, sorry about the confusion. I’ve added the default value for
responseType
in the Api doc.
Yeah, the default response type is
iam
Did you get the above code snippet from our example/doc by any chance?
o

outaTiME

05/25/2022, 11:31 AM
Hi @Frank, no problem, I took the code from the github examples folder, I even did a PR to fix it: https://github.com/serverless-stack/serverless-stack/pull/1712