New AWS HTTP APIs

Earlier this week, we announced support for AWS HTTP APIs and talked a bit about what is possible with them. If you’d like to learn more about the AWS HTTP API and the new event source we’ve added integrate with it check that post out.

In this post, however we’ll jump in to using the new AWS HTTP APIs with one of the new features they offer - the JSON Web Token integration. I’ll show you how to use Amazon Cognito to add authentication and authorization to your AWS HTTP API endpoints.

You can choose to follow along with examples in either Node.js or Python and towards the end, I’ll show how you could modify the examples in order to work with a tool like Auth0 or Okta instead of Amazon Cognito.

Let’s get started!

Setup

In this guide, we will create an Amazon Cognito User Pool, App Client, and Domain all from scratch in the resources section of serverless.yml. You can choose to use either the Node.js or the Python version of the code. Run one of the following commands to get started:

  • For Node.js - git clone https://github.com/fernando-mc/aws-http-api-node-cognito.git
  • For Python - git clone https://github.com/fernando-mc/aws-http-api-python-cognito.git

After you have the code, make sure you’ve also installed the Serverless Framework, setup and configured the AWS CLI, and (optionally) created a Framework Pro account.

Deploying the Project

With the repository cloned, change directories into the repository and make sure you’re on the same level as the serverless.yml file. Then you can make a few changes to the demo code:

  1. Either configure your own org and app name with Framework Pro or remove the org and app from the top of serverless.yml.
  2. Update the DOMAIN_SUFFIX value in the provider environment section to something unique. I recommend you use something like your name and favorite mythical animal.
  3. After that, save the file and run serverless deploy.

This should deploy all the Amazon Cognito resources required as well as all the parts of our new HTTP API.

#serverless #aws #api #http

Serverless Auth with AWS HTTP APIs
2.10 GEEK