BenShen98 / aws-serverless-trial

experiment with AWS and serverless framework, 2019

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Let's play

  1. go to https://benshen98.github.io/aws-serverless-trial/
  2. Click login and use
    • Username: hello@world
    • Password: 123456

Yes, I know I had chosen the most unbreakable password in the world!

Intention

This project is built in order for me to get familiar with the cloud and serverless, as I had no previous experience relate to it.

If you are also like me, want to get into serverless, but don't know where to start. I find these step might be helpful and could save you some valuable time

  1. watch aws essential from udemy, especially IAM, VPC and Lambda
  2. install serverless and follow the quickstart guide.
    Note that you don't need to give serverless full admin right, only the rights listed here is enough.
  3. Follow the guide by andreivmaksimov, both part1 and part2.
  4. Just play around with the config files and js, for example,
    • I used github page instead of AWS S3, since it will always be free and available

Notes about js

|| and && in js can return non-bool value ref

var WildRydes = window.WildRydes || {};

global variable use var, scope use let

var foo can be called use window.foo as window is the root scope

var WildRydes = window.WildRydes || {};

promises, resolve and reject ref

then for resolve, catch for reject
Both resolve and reject are callback(async), i.e. it will execute until the result of Promise is know, non-blocking

// cognito-auth.js
    WildRydes.authToken = new Promise(function fetchCurrentAuthToken(resolve, reject) {
     var cognitoUser = userPool.getCurrentUser();

     if (cognitoUser) {
         cognitoUser.getSession(function sessionCallback(err, session) {
             if (err) {
                 reject(err);
             } else if (!session.isValid()) {
                 resolve(null);
             } else {
                 resolve(session.getIdToken().getJwtToken());
             }
         });
     } else {
         resolve(null);
     }
 });
 
 //ride.js
 var authToken;
 WildRydes.authToken.then(function setAuthToken(token) {
     if (token) {
         authToken = token;
     } else {
         window.location.href = 'signin.html';
     }
 }).catch(function handleTokenError(error) {
     alert(error);
     window.location.href = 'signin.html';
 });

About

experiment with AWS and serverless framework, 2019


Languages

Language:JavaScript 100.0%