This example shows how to configure and use a custom authorizer. This is a trivially simple authorizer that just checks for anything in the Authorization header. It expects the header to contain a username and a access key/password separated by a dash.
Custom authorizer support requires claudia-api-builder 1.6.0, and claudia 1.7.1
Follow these steps:
npm installto grab the dependenciesnpm run create-authorizerto set up a new Lambda function for the authorizernpm run create-apito set up the REST API using the custom authorizer
Grab the URL of your API (printed by the create-api step), and execute using CURL:
- the root resource has no authorizer attached, so you should be able to directly call it without the
Authorizationheader - the
/lockedGET resource has an authorizer, but the authorizer policy won't allow access to any user. Try it with and without theAuthorizationheader and see the difference in results - the
/unlockedGET resource has an authorizer, and the authorizer policy allows access to any user. It will print the user ID (first part of the header, before a dash). Try it with and without an authorization header to see the different results.
Check out the authorizer.js to see the implementation of the trivial authorizer. Then see index.js for how this authorizer is used in the API Gateway.
