Integrating Cognito with your Mobile or Web Applications
Start course
2h 33m

This course provides detail on the AWS Security, Identity, and compliance services relevant to the AWS Developer - Associate exam. These services are used to help secure and protect your resources and environment through access control mechanisms and encryption.

Want more? Try a lab playground or do a Lab Challenge!

Learning Objectives

  • Learn what Identity Federation is
  • Learn about the AWS services that can be used with it
  • Understand how it's implemented
  • Understand the benefits of AWS SSO and how it can be used to simplify user access at scale
  • 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
  • Understand what is meant identity and access management and the difference between authentication, authorization, and access control
  • Learn the components of IAM as well as its reporting features
  • Understand the core principles of cross-account access using IAM
  • How to implement and configure cross-account access
  • Define how the Key encryption process works
  • Explain the differences between the different key types 
  • Create and modify Key policies
  • Understand how to rotate, delete and reinstate keys
  • Define how to import your own Key material



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:


About the Author
Learning Paths

Stuart has been working within the IT industry for two decades covering a huge range of topic areas and technologies, from data center and network infrastructure design, to cloud architecture and implementation.

To date, Stuart has created 150+ courses relating to Cloud reaching over 180,000 students, mostly within the AWS category and with a heavy focus on security and compliance.

Stuart is a member of the AWS Community Builders Program for his contributions towards AWS.

He is AWS certified and accredited in addition to being a published author covering topics across the AWS landscape.

In January 2016 Stuart was awarded ‘Expert of the Year Award 2015’ from Experts Exchange for his knowledge share within cloud services to the community.

Stuart enjoys writing about cloud technologies and you will find many of his articles within our blog pages.