microscopic-zoo-3564
05/01/2021, 4:41 AMevent
in the main
function?
I'm coming from the serverless framework, where I would have used PreTokenGenerationTriggerEvent from @types/aws-lambda
, but this results in a typescript error as it's not compatible with the type of callback: main
in the lambda function definition.
import * as aws from '@pulumi/aws'
import { HASURA_USER_ID_ATTRIBUTE_NAME, getName } from '../constants'
import { HASURA_ACCESS_TOKEN_NAMESPACE } from '../../../constants'
const functionName = getName('cognitoPreTokenGeneration')
function main(event: any) {
const {
sub,
[`custom:${HASURA_USER_ID_ATTRIBUTE_NAME}`]: hasuraUserId,
} = event.request.userAttributes
if (!hasuraUserId) {
console.error(message)
throw Error(message)
}
event.response = {
claimsOverrideDetails: {
claimsToAddOrOverride: {
[HASURA_ACCESS_TOKEN_NAMESPACE]: JSON.stringify({
'x-hasura-allowed-roles': ['user'],
'x-hasura-default-role': 'user',
'x-hasura-user-id': hasuraUserId,
}),
},
},
}
return event
}
export const preTokenGenerationLambda = new aws.lambda.CallbackFunction(
functionName,
{
callback: main,
runtime: 'nodejs14.x',
memorySize: 128,
timeout: 25,
},
)