Tuesday, March 27, 2018

How to setup Serverless server on AWS (User Management)?

Prerequisite

- Register an AWS account

Note: AWS has given a very details step by step guide. This is for my own note taking and reference

Create an Amazon Cognito User Pool
  • Login to AWS website, select "Services" menu and "Cognito" sub menu under the "Security, Identity & Compliance" section.

  • Click on "Manage your User Pools" button
  • Click on "Click here to create a user pool" link
  • Provide a name for user pool such as "BeezPool", select "Review Defaults".
  • Click on "Create Pool", user pool with new pool id is created.
Create an Amazon Cognito User Pool
  • Select "App Clients" in the "General settings" section of the left menu
  • Click "Add an app client" hyperlink
  • Enter the App client name such as "BeezWebApp"
  • Uncheck "Generate client secret" checkbox
  • Click on "Create app client" button
  • Newly generated "App client id" is generated

Update the config.js File in Your Website Bucket
  • Based on the source code use in previous tutorial, https://github.com/awslabs/aws-serverless-workshops/archive/master.zip, alter /js/config.js file.
  • Click on the "General Settings" of the left menu, you can find the "Pool id" in the pool details page
  • Click on the "App Client Settings" of the left menu,  you can find the "App Client id" in the app client details page
  • Alter /js/config.js with the user pool id and app client id as shown below. 

window._config = {
    cognito: {
        userPoolId: 'XX-XXXXXXXXX-X_XXXXXXXXX', // e.g. us-east-2_uXboG5pAb
        userPoolClientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXX', // e.g. 25ddkmj4v6hfsfvruhpfi7n4hv
        region: 'XX-XXXXXXXXX-X' // e.g. us-east-2
    },
    api: {
        invokeUrl: '' // e.g. https://rc7nyt4tql.execute-api.us-west-2.amazonaws.com/prod',
    }
};
 
  • Open the Amazon S3 console by visiting https://console.aws.amazon.com/s3/.
  • Select "beez-firstname-lastname" website bucket that has been created in the previous tutorial
  • Browse to the js prefix, click on the "Upload" button, upload /js/config.js that we have edited in the previous step to overwrite config.js file
Validate your implementation
  • Visit /register.html under the website domain


  • Fill in the form, submit the user details. Verify email page will be displayed.


  • A confirmation code will be sent to the email account. Enter the email and confirmation code, follow by "Verify" button, user will be redirected to login page. Login again and user will be redirected to /ride.html page and a "Successful Authenticated" message will be displayed.





No comments: