Загрузка страницы

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
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
19 марта 2021 г. 9:25:32
00:26:34
Другие видео канала
AWS Lambda | API Gateway | DynamboDB | S3 | Develop & Deploy Interactive Dynamic Web App | DemoAWS Lambda | API Gateway | DynamboDB | S3 | Develop & Deploy Interactive Dynamic Web App | DemoAWS Cognito | Amazon Cognito | AWS Tutorial for Beginners | AWS Training | EdurekaAWS Cognito | Amazon Cognito | AWS Tutorial for Beginners | AWS Training | EdurekaSecure your API Gateway with Amazon Cognito User Pools | Step by Step AWS TutorialSecure your API Gateway with Amazon Cognito User Pools | Step by Step AWS TutorialAWS SDK for JavaScript v3 - The good and bad partsAWS SDK for JavaScript v3 - The good and bad partsConnecting Raspberry Pi to AWS Iot Core : Setup and code Using Python and AWS IOTConnecting Raspberry Pi to AWS Iot Core : Setup and code Using Python and AWS IOTAdvanced Data Access Patterns with GraphQL, Amazon DynamoDB, and AWS AmplifyAdvanced Data Access Patterns with GraphQL, Amazon DynamoDB, and AWS AmplifyBuild a Harry Potter API with Node.js, Express.js, and Dynamo DBBuild a Harry Potter API with Node.js, Express.js, and Dynamo DBHow to Deploy AWS IoT Greengrass Using Docker Containers and Ubuntu Snap - AWS Online Tech TalksHow to Deploy AWS IoT Greengrass Using Docker Containers and Ubuntu Snap - AWS Online Tech TalksCreate Your First Table by Using the DynamoDB Console - AWS Virtual WorkshopCreate Your First Table by Using the DynamoDB Console - AWS Virtual WorkshopAWS Tutorial - Serverless Web Application in AWS Tutorial 2020AWS Tutorial - Serverless Web Application in AWS Tutorial 2020Create A Full Stack App With AWS Amplify UI In 15 Minutes!Create A Full Stack App With AWS Amplify UI In 15 Minutes!Your First Web App in AWS - 30 min Tutorial - Amplify, React, ServerlessYour First Web App in AWS - 30 min Tutorial - Amplify, React, ServerlessCreate Modern Serverless Web Applications in Minutes using the AWS Amplify FrameworkCreate Modern Serverless Web Applications in Minutes using the AWS Amplify FrameworkAWS Tutorial - 04 - ECS - Elastic Container Service & Fargate | AWS Certification SeriesAWS Tutorial - 04 - ECS - Elastic Container Service & Fargate | AWS Certification SeriesAWS DynamoDB Tutorial | Amazon DynamoDB | AWS Tutorial for Beginners | EdurekaAWS DynamoDB Tutorial | Amazon DynamoDB | AWS Tutorial for Beginners | EdurekaSetting up an AWS Server with Node-RedSetting up an AWS Server with Node-RedAWS SAM Tutorial (with a Lambda Example!)AWS SAM Tutorial (with a Lambda Example!)Live Coding with AWS: API Authentication with Amazon CognitoLive Coding with AWS: API Authentication with Amazon CognitoBuild a CRUD REST API for DynamoDB w/ AWS Lambda & API Gateway using Node.js AWS-SDK V3 & ServerlessBuild a CRUD REST API for DynamoDB w/ AWS Lambda & API Gateway using Node.js AWS-SDK V3 & ServerlessAuthentication for Your Applications: Getting Started with Amazon Cognito - AWS Online Tech TalksAuthentication for Your Applications: Getting Started with Amazon Cognito - AWS Online Tech Talks
Яндекс.Метрика