Skip to content

Instantly share code, notes, and snippets.

@loginov-rocks
Created January 22, 2024 04:08
Show Gist options
  • Save loginov-rocks/f56ee046f69256a99f6227bcdc9dff2e to your computer and use it in GitHub Desktop.
Save loginov-rocks/f56ee046f69256a99f6227bcdc9dff2e to your computer and use it in GitHub Desktop.
WebSocket API Gateway Cognito Authorizer
/**
* @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
*/
const generatePolicy = (principalId, effect, resource, context) => ({
context,
policyDocument: {
Version: '2012-10-17',
Statement: [
{
Action: 'execute-api:Invoke',
Effect: effect,
Resource: resource,
},
],
},
principalId,
});
export const generateAllowPolicy = (principalId, resource, context) => (
generatePolicy(principalId, 'Allow', resource, context)
);
export const generateDenyPolicy = (principalId, resource, context) => (
generatePolicy(principalId, 'Deny', resource, context)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment