- go to https://benshen98.github.io/aws-serverless-trial/
- Click login and use
- Username: hello@world
- Password: 123456
Yes, I know I had chosen the most unbreakable password in the world!
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
- watch aws essential from udemy, especially IAM, VPC and Lambda
- 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. - Follow the guide by andreivmaksimov, both part1 and part2.
- 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
||
and &&
in js can return non-bool value ref
var WildRydes = window.WildRydes || {};
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';
});