AWS: Frontend web application with Javascript, DynamoDB and Amazon Cognito
This tutorial will explain how to create a serverless and backendless javascript frontend application using DynamoDB and Cognito.
User ► HTML/JS ► Cognito / DynamoDB
Reference of my previous video for more information on AWS using a backend service and API gateway and hosting static HTML files:
https://www.youtube.com/watch?v=SgvkU1yNuGM
My first video where I explain how to configure AWS:
https://www.youtube.com/watch?v=Yl3mCQns4iQ
AWS Javascript API files:
https://github.com/amazon-archives/amazon-cognito-identity-js/tree/master/dist
https://github.com/amazon-archives/amazon-cognito-auth-js/tree/master/dist
Javascript Examples for DynamoDB:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.JavaScript.html
-----
Javascript:
var idToken = null;
function checkLogin() {
var url_string = window.location.href;
var url = new URL(url_string);
idToken = url.searchParams.get("id_token");
if (idToken != null) {
document.getElementById("welcomeMsg").innerHTML = "signed in";
auth();
}
}
function auth() {
AWS.config.update({
region: "us-east-2",
// endpoint: 'http://localhost:8000', // If you use dynamoDB installed locally
// accessKeyId: "(ACCESS_KEY_ID)",
// secretAccessKey: "(SECRET_ACCESS_KEY)"
});
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId : '(IDENTITY POOL ID)',
Logins : {
"cognito-idp.(AWS_REGION).amazonaws.com/(POOL_ID)": idToken
}
});
}
function insertItem() {
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName :"Person",
Item:{
"FirstName": "John", // Partition Key
"LastName": "Smith", // Sort Key
"info": {
"FavoriteColor": "blue",
"YearOfBirth": 1942
}
}
};
docClient.put(params, function(err, data) {
if (err) {
document.getElementById('textarea').innerHTML = "Unable to add item: " + "\n" + JSON.stringify(err, undefined, 2);
} else {
document.getElementById('textarea').innerHTML = "PutItem succeeded: " + "\n" + JSON.stringify(data, undefined, 2);
}
});
}
function readItem() {
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: "Person",
Key:{
"FirstName": "John",// Partition Key
"LastName": "Smith" // Sort/Range Key
}
};
docClient.get(params, function(err, data) {
if (err) {
document.getElementById('textarea').innerHTML = "Unable to read item: " + "\n" + JSON.stringify(err, undefined, 2);
} else {
document.getElementById('textarea').innerHTML = "GetItem succeeded: " + "\n" + JSON.stringify(data, undefined, 2);
}
});
}
-----
Javascript if you want to login internally inside your page.
Recommended video for that: https://www.youtube.com/watch?v=rOaUyCM-fcE
function signInButton() {
var authenticationData = {
Username : document.getElementById("inputUsername").value,
Password : document.getElementById("inputPassword").value,
};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId : "(POOL_ID)", // Your user pool id here
ClientId : "(APP_CLIENT_ID)", // Your client id here
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username : document.getElementById("inputUsername").value,
Pool : userPool,
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log(JSON.stringify(result));
// var accessToken = result.getAccessToken().getJwtToken();
// console.log(accessToken);
},
onFailure: function(err) {
alert(err.message || JSON.stringify(err));
},
});
}
-- Contents of this video --
0:00 Intro
1:52 Configure Cognito
7:40 Create DynamoDB table
8:20 Create IAM role and permission
10:52 More Cognito configuration
16:02 Javascript and HTML code
22:41 Tests and final comments
Видео AWS: Frontend web application with Javascript, DynamoDB and Amazon Cognito канала Learn By Examples
User ► HTML/JS ► Cognito / DynamoDB
Reference of my previous video for more information on AWS using a backend service and API gateway and hosting static HTML files:
https://www.youtube.com/watch?v=SgvkU1yNuGM
My first video where I explain how to configure AWS:
https://www.youtube.com/watch?v=Yl3mCQns4iQ
AWS Javascript API files:
https://github.com/amazon-archives/amazon-cognito-identity-js/tree/master/dist
https://github.com/amazon-archives/amazon-cognito-auth-js/tree/master/dist
Javascript Examples for DynamoDB:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.JavaScript.html
-----
Javascript:
var idToken = null;
function checkLogin() {
var url_string = window.location.href;
var url = new URL(url_string);
idToken = url.searchParams.get("id_token");
if (idToken != null) {
document.getElementById("welcomeMsg").innerHTML = "signed in";
auth();
}
}
function auth() {
AWS.config.update({
region: "us-east-2",
// endpoint: 'http://localhost:8000', // If you use dynamoDB installed locally
// accessKeyId: "(ACCESS_KEY_ID)",
// secretAccessKey: "(SECRET_ACCESS_KEY)"
});
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId : '(IDENTITY POOL ID)',
Logins : {
"cognito-idp.(AWS_REGION).amazonaws.com/(POOL_ID)": idToken
}
});
}
function insertItem() {
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName :"Person",
Item:{
"FirstName": "John", // Partition Key
"LastName": "Smith", // Sort Key
"info": {
"FavoriteColor": "blue",
"YearOfBirth": 1942
}
}
};
docClient.put(params, function(err, data) {
if (err) {
document.getElementById('textarea').innerHTML = "Unable to add item: " + "\n" + JSON.stringify(err, undefined, 2);
} else {
document.getElementById('textarea').innerHTML = "PutItem succeeded: " + "\n" + JSON.stringify(data, undefined, 2);
}
});
}
function readItem() {
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: "Person",
Key:{
"FirstName": "John",// Partition Key
"LastName": "Smith" // Sort/Range Key
}
};
docClient.get(params, function(err, data) {
if (err) {
document.getElementById('textarea').innerHTML = "Unable to read item: " + "\n" + JSON.stringify(err, undefined, 2);
} else {
document.getElementById('textarea').innerHTML = "GetItem succeeded: " + "\n" + JSON.stringify(data, undefined, 2);
}
});
}
-----
Javascript if you want to login internally inside your page.
Recommended video for that: https://www.youtube.com/watch?v=rOaUyCM-fcE
function signInButton() {
var authenticationData = {
Username : document.getElementById("inputUsername").value,
Password : document.getElementById("inputPassword").value,
};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId : "(POOL_ID)", // Your user pool id here
ClientId : "(APP_CLIENT_ID)", // Your client id here
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username : document.getElementById("inputUsername").value,
Pool : userPool,
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log(JSON.stringify(result));
// var accessToken = result.getAccessToken().getJwtToken();
// console.log(accessToken);
},
onFailure: function(err) {
alert(err.message || JSON.stringify(err));
},
});
}
-- Contents of this video --
0:00 Intro
1:52 Configure Cognito
7:40 Create DynamoDB table
8:20 Create IAM role and permission
10:52 More Cognito configuration
16:02 Javascript and HTML code
22:41 Tests and final comments
Видео AWS: Frontend web application with Javascript, DynamoDB and Amazon Cognito канала Learn By Examples
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![AWS Lambda | API Gateway | DynamboDB | S3 | Develop & Deploy Interactive Dynamic Web App | Demo](https://i.ytimg.com/vi/95C9PkSwM1Q/default.jpg)
![AWS Cognito | Amazon Cognito | AWS Tutorial for Beginners | AWS Training | Edureka](https://i.ytimg.com/vi/jTu--LpjA18/default.jpg)
![Secure your API Gateway with Amazon Cognito User Pools | Step by Step AWS Tutorial](https://i.ytimg.com/vi/oFSU6rhFETk/default.jpg)
![AWS SDK for JavaScript v3 - The good and bad parts](https://i.ytimg.com/vi/YqfD0kcId10/default.jpg)
![Connecting Raspberry Pi to AWS Iot Core : Setup and code Using Python and AWS IOT](https://i.ytimg.com/vi/kPLafcrng-c/default.jpg)
![Advanced Data Access Patterns with GraphQL, Amazon DynamoDB, and AWS Amplify](https://i.ytimg.com/vi/VG2XWoD-rS0/default.jpg)
![Build a Harry Potter API with Node.js, Express.js, and Dynamo DB](https://i.ytimg.com/vi/JPQPPLQnyB4/default.jpg)
![How to Deploy AWS IoT Greengrass Using Docker Containers and Ubuntu Snap - AWS Online Tech Talks](https://i.ytimg.com/vi/wFeoKhVg-PM/default.jpg)
![Create Your First Table by Using the DynamoDB Console - AWS Virtual Workshop](https://i.ytimg.com/vi/soNG0n68spw/default.jpg)
![AWS Tutorial - Serverless Web Application in AWS Tutorial 2020](https://i.ytimg.com/vi/kF17Bwu276o/default.jpg)
![Create A Full Stack App With AWS Amplify UI In 15 Minutes!](https://i.ytimg.com/vi/Q70eWux2xpQ/default.jpg)
![Your First Web App in AWS - 30 min Tutorial - Amplify, React, Serverless](https://i.ytimg.com/vi/Xdx3t1HkJLY/default.jpg)
![Create Modern Serverless Web Applications in Minutes using the AWS Amplify Framework](https://i.ytimg.com/vi/SnqABG8e9Zk/default.jpg)
![AWS Tutorial - 04 - ECS - Elastic Container Service & Fargate | AWS Certification Series](https://i.ytimg.com/vi/JkrqEp0BPmY/default.jpg)
![AWS DynamoDB Tutorial | Amazon DynamoDB | AWS Tutorial for Beginners | Edureka](https://i.ytimg.com/vi/k0fcbRj_pZE/default.jpg)
![Setting up an AWS Server with Node-Red](https://i.ytimg.com/vi/T_Cfepvd2hw/default.jpg)
![AWS SAM Tutorial (with a Lambda Example!)](https://i.ytimg.com/vi/MipjLaTp5nA/default.jpg)
![Live Coding with AWS: API Authentication with Amazon Cognito](https://i.ytimg.com/vi/TowcW1aTDqE/default.jpg)
![Build a CRUD REST API for DynamoDB w/ AWS Lambda & API Gateway using Node.js AWS-SDK V3 & Serverless](https://i.ytimg.com/vi/hOcbHz4T0Eg/default.jpg)
![Authentication for Your Applications: Getting Started with Amazon Cognito - AWS Online Tech Talks](https://i.ytimg.com/vi/OAR4ZHP8DEg/default.jpg)