Integrate an API with lambda - Part 2


Let us look at the configuration of method request section

The first setting is about authorization. Default option is none. The provided option is AWS IAM. But we can also use custom authorization if we need such a feature. We can create and add an authorizer to the section as shown below

During the creation of authorizer several options are available. The first choice we have is the type of authorizer. Two possible values are lambda or cognito. If we choose lambda then we have a set of options. We need to provide the name of the lambda function.  This lambda function is responsible for validating the user and providing the necessary policy back. This policy will be evaluated and the user is either allowed or denied access to the resource. 

For the lambda based authorization there are couple of options. We could use either token based approach or request based approach. 

In the token based approach the user is expected to provide a valid token and this token will be used for authentication/authorization. There is a feature to validate the token format. Even before sending the token to back end lambda for decrypting, AWS provides an ability to perform regex on the token format. This regex can be provided in the token validation field.

In the request based approach we have the ability to configure multiple tokens or fields that need to be provided by the user for validation. Below is the screenshot which shows the configuration with the request option selected. 


Once an authorizer is created we can quickly test the configuration in the console. Below is the screenshot which shows an authorizer created with token  type


If we go back to the resource method and refresh the page, we can see the newly created custom authorizer involving lambda available. In our example we created the authorizer called custom and that shows up in the drop down options.

In the part 3 of the blog we will look at request validation and other configurations.

Comments

Popular posts from this blog

Integrate an API with lambda - Part 5

Custom authorizer