// amplify/data/custom-authorizer.ts
// This is sample code. Update this to suite your needs
import type { AppSyncAuthorizerHandler } from 'aws-lambda'; // types imported from @types/aws-lambda
type ResolverContext = {
userid: string;
info: string;
more_info: string;
};
export const handler: AppSyncAuthorizerHandler<ResolverContext> = async (
event
) => {
console.log(`EVENT: ${JSON.stringify(event)}`);
const {
authorizationToken,
requestContext: { apiId, accountId }
} = event;
const response = {
isAuthorized: authorizationToken === 'custom-authorized',
resolverContext: {
// eslint-disable-next-line spellcheck/spell-checker
userid: 'user-id',
info: 'contextual information A',
more_info: 'contextual information B'
},
deniedFields: [
"name", "address",
],
ttlOverride: 300
};
console.log(`RESPONSE: ${JSON.stringify(response, null, 2)}`);
return response;
};
Here is an example for simplicity. The lambda authorizer expects optional an deniedFields
, where i can define all fields that i want to turn to null
, however my data is big over 20 fields, and i actually just want to show for example 3 fields, that means i need to deny the rest, is it possible to somehow “allow” certain fields instead of denying?