Skip to content

This package will generate AWS auth policy for API Gateway lambda authorizer.

License

Notifications You must be signed in to change notification settings

kdcio/aws-policy

Repository files navigation

AWS Policy Generator

This package will generate AWS auth policy for API Gateway lambda authorizer.

ver size build Known Vulnerabilities Quality Gate Status Code Smells Coverage license

Install

npm i @kdcio/aws-policy

Usage

import generatePolicy from '@kdcio/aws-policy';

export const handler = (event) => {
  const user = {
    name: 'Ian',
    username: 'ian',
    role: 'admin',
  };
  const resources = [
    'GET/users',
    'POST/users',
    'GET/users/*',
    'PUT/users/*',
    'DELETE/users/*',
  ];

  return generatePolicy({
    context: { ...user },
    principalId: user.username,
    effect: 'Allow',
    methodArn: event.methodArn,
    resources,
  });
};

Further Reading

Output from an Amazon API Gateway Lambda authorizer