The course is part of this learning path
This course explores Amazon Cognito and how it can be used to manage authentication and authorization to your apps. We'll start with a general overview of Amazon Cognito and when to use it. Then we move on to user pools and identity pools. We round off the course by looking at how Amazon Cognito can be integrated with mobile and web apps and how to sync your app's user data across various platforms.
Learning Objectives
- Create your own authentication mechanisms using Amazon Cognito
- Create your own customized UI for user sign in
- Create a secure user directory for all your applications and users
Intended Audience
This course is intended for anyone who is trying to understand what mechanisms are available for user authentication within AWS and specifically, those who want to use third-party identity providers, such as Apple, Facebook, Google, and Amazon.
Prerequisites
- A decent understanding of cloud computing and cloud architectures, specifically with Amazon Web Services
- Familiarity with basic security terminology, IAM, user authentication, and federation
- It is helpful to know about Active Directory and other AD type services
Now that we know the backgrounds on both Cognito user pools and the identity pools, let's take a look at some examples of how these parts of the service work together and with your applications.
For our first example imagine we have a simple mobile / web game that allows you to store your high scores after completing a session.
In order to save that data, however, we need to have sign up, log in, and authentication working.
Your application will need to integrate with Cognito by using the Cognito SDKs and libraries. These SDKs are provided by the AWS Amplify Framework.
AWS Amplify is a mobile and web toolset that AWS offers to help developers create scalable front-end applications. Amplify supports Javascript, React, Angular, Vue and Next.JS on the web side, and Android, IOS, React Native, Ionic, and flutter for the mobile side. (hurray list of tech names)
Now you might be asking - do I really have to use Amplify and this mobile SDK? The answer is no you don't have to, you can of course just call the server-side APIs directly. But there is a reason that AWS wants you to use amplify and these mobile SDKs. In general, they have been working on this suite of SDKs for a while, and they think it will be easier for you, than doing it yourself.
Anywhoo, you will have to install the Amplify dependencies and reference them within your application. That will look a little something like this for web.
And somewhere within your applications start/entry point, you will need to reference those libraries.
I want to point out the last line here (the configure part) and show what the might entail. You can have this reference an external file or can set it up within your application itself. Either way, it might look something like this.
All we are doing here is letting Amplify / Cognito know what user pools and identity pools we actually care about, what region to find them in, and any other qualifying information your authentication process might need. In this example the Cognito region is us-east-1, we specify the pool ID, a web client ID (this is just an APP id), an identity pool id, and whether or not we will allow users to get AWS creds if they are not signed in.
You can have a lot more information here if you need it of course.
When your users need to sign to upload their scores - the code will look something like the following.
Since we have already configured all the extra information previously, we just have to send a username and password with this function for allowing sign-in.
And as we mentioned before, you can have a backend process listening for all of these sign-in and authentication event and having some kind of work done in response to them.
Once your users are signed in and authenticated - they can then send their high scores to whatever leaderboard mechanisms they need.
For more direct information about using Amplify, Cognito, and the specifics around how to set up web and mobile authentication, dive into the docs over here:
https://docs.amplify.aws/lib/auth/getting-started/q/platform/js
William Meadows is a passionately curious human currently living in the Bay Area in California. His career has included working with lasers, teaching teenagers how to code, and creating classes about cloud technology that are taught all over the world. His dedication to completing goals and helping others is what brings meaning to his life. In his free time, he enjoys reading Reddit, playing video games, and writing books.