outaTiME
05/20/2022, 5:02 PM"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:
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:
// 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,
};
}
outaTiME
05/20/2022, 8:57 PMresponseTypes: ['simple']
which was not in the github examples or in the SST v1 documentation.
This is how the definition would be:
// 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',
},
},
});
Frank
responseType
in the Api doc.Frank
iam
Frank
outaTiME
05/25/2022, 11:31 AM