SlideShare una empresa de Scribd logo
1 de 16
Typical Serverless Architecture
Copyright © 2016 classicprogrammerpaintings.com All Rights Reserved.
Agenda
• Frontend
• Add security with Cognito and Google Identity
Provider
• Store Data in Dynamo DB
• Build Microservice with Lambda
• Deploy source code into S3 Bucket
Frontend
https://www.thoughtworks.com/radar/languages-and-frameworks
Add security with Cognito and Google Identity Provider
1. Obtain Google IDP Client Id:
2. Update index.html with Google Client Id
3. Update Identity Pool config.json with Google
Client Id
4. Create a new Identity Pool
5. Update javascript config file(s) with
Identity Pool Id
variable "login_provider" {
default = "105303240909-am1nkfpr1fmo9d2bce5pbkv.apps.googleusercontent.com"
}
resource "template_file" "login_provider_config" {
template = "${file("${path.module}/../conf/cognito/config.json.tpl")}"
vars {
login_provider = "${var.login_provider}"
}
provisioner "local-exec" {
command ="echo "${self.rendered}" >
${path.module}/../conf/cognito/config.json"
}
}
Store Data in DynamoDB
saveAnswer: function(problemId, answer) {
return cognito.identity.then(function(identity) {
var db = new AWS.DynamoDB.DocumentClient();
var item = {
TableName: 'answers',
Item: {
userId: identity.id,
problemId: problemId,
answer: answer
}
};
return cognito.sendAwsRequest(db.put(item), function(){
return saveAnswer(problemId, answer);
})
})
}
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem",
"dynaeleteItem",
"dynamodb:modb:DGetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:UpdateItem"
],
"Resource": ["arn:aws:dynamodb:us-east-1:1111111111:table/problems"],
"Condition": {
"ForAllValues:StringEquals": {
"dynamodb:LeadingKeys": ["${cognito-identity.amazonaws.com:sub}"]}
}
}]
}
IAM Permission Policy
Build Microservice with Lambda
Frontend code
checkAnswer: function(problemId, answer) {
return cognito.identity.then(function(identity) {
var lambda = new AWS.Lambda();
var params = {
FunctionName: 'spa_checkAnswer',
Payload: JSON.stringify({ problemId: problemId, answer: answer })
};
return cognito.sendAwsRequest(lambda.invoke(params), function(){
return checkAnswer(problemId, answer);
})
})
}
Build Microservice with Lambda
Backend code
'use strict';
let doc = require('dynamodb-doc');
let dynamo = new doc.DynamoDB();
exports.handler = (event, context, callback) => {
let params = {
TableName : "problems",
KeyConditionExpression: "problemId = :problemId",
ExpressionAttributeValues: {
":problemId":event.problemId
}
};
dynamo.query(params, function(err, data) {
if (err) {
callback(Error("Unable to query: " + JSON.stringify(event) + " .Error:" +
JSON.stringify(err)));
} else {
if (data.Items.length > 0) {
let test = data.Items[0].Code.replace('__', event.answer) + '; problem();';
context.succeed(eval(test));
} else {
callback(Error("Problem not found"));
}
}
});
};
API Gateway
Copyright © 2016 Amazon Web Services All Rights Reserved.
Swagger definition
{
"swagger":
...
"paths":
{
"/get-tenants": {
"get": {
"responses": {
"200": {
"description": "List of tenants",
"schema": {"$ref": "#/definitions/Tenants" }
}}
"x-amazon-apigateway-integration": {
"type": "aws",
"uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-
31/functions/arn:aws:lambda:us-east-
1:111111111111:function:${func}/invocations",
"httpMethod": "POST",
"credentials":"arn:aws:iam::111111111111:role/${invoke-lambda}",
...
First Deployment
1. Deploy infrastructure
$ terraform apply
2. Deploy the content to s3 bucket
$ npm install
$ aws s3 sync app/ s3://s3-spa.demos3.com/ --acl public-read --profile spa
3. Import DynamoDB data
$ aws dynamodb batch-write-item --request-items file://conf/dynamodb/sampledata/Problems.json --profile spa
4. Enjoy http://s3-spa.demos3.com.s3-website-us-east-1.amazonaws.com
Alternatives
• Cloud Formation (CF stack)
• Boto3
• Troposphere
References
• Serverless Single Page Apps – Ben Rady
• AWS Lambda in Action - Danilo Poccia
• https://aws.amazon.com/documentation/
• https://www.terraform.io/
• https://github.com/yegor86/spa-aws
Questions

Más contenido relacionado

La actualidad más candente

Monitoring Weave Cloud with Prometheus
Monitoring Weave Cloud with PrometheusMonitoring Weave Cloud with Prometheus
Monitoring Weave Cloud with PrometheusWeaveworks
 
Serverless Reality
Serverless RealityServerless Reality
Serverless RealityLynn Langit
 
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017Codemotion
 
Enterprise level application in 5 min
Enterprise level application in 5 minEnterprise level application in 5 min
Enterprise level application in 5 minAustin Gil
 
AWS Community Day Bangkok 2019 - How AWS Parallel Cluster can accelerate high...
AWS Community Day Bangkok 2019 - How AWS Parallel Cluster can accelerate high...AWS Community Day Bangkok 2019 - How AWS Parallel Cluster can accelerate high...
AWS Community Day Bangkok 2019 - How AWS Parallel Cluster can accelerate high...AWS User Group - Thailand
 
Serverless with Google Cloud Functions
Serverless with Google Cloud FunctionsServerless with Google Cloud Functions
Serverless with Google Cloud FunctionsJerry Jalava
 
Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...
Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...
Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...Codemotion
 
gRPC @ Weaveworks
gRPC @ WeaveworksgRPC @ Weaveworks
gRPC @ WeaveworksWeaveworks
 
Things you wish you never knew about the Prometheus Remote Write API.
Things you wish you never knew about the Prometheus Remote Write API.Things you wish you never knew about the Prometheus Remote Write API.
Things you wish you never knew about the Prometheus Remote Write API.Kausal
 
Building a Serverless company with Node.js, React and the Serverless Framewor...
Building a Serverless company with Node.js, React and the Serverless Framewor...Building a Serverless company with Node.js, React and the Serverless Framewor...
Building a Serverless company with Node.js, React and the Serverless Framewor...Luciano Mammino
 
ApacheCon Testing Camel K with Cloud Native BDD
ApacheCon Testing Camel K with Cloud Native BDDApacheCon Testing Camel K with Cloud Native BDD
ApacheCon Testing Camel K with Cloud Native BDDchristophd
 
Building cloud native apps with .net core 3.0 and kubernetes
Building cloud native apps with .net core 3.0 and kubernetesBuilding cloud native apps with .net core 3.0 and kubernetes
Building cloud native apps with .net core 3.0 and kubernetesNilesh Gule
 
Fluent 2018: When third parties stop being polite... and start getting real
Fluent 2018: When third parties stop being polite... and start getting realFluent 2018: When third parties stop being polite... and start getting real
Fluent 2018: When third parties stop being polite... and start getting realAkamai Developers & Admins
 

La actualidad más candente (20)

Monitoring Weave Cloud with Prometheus
Monitoring Weave Cloud with PrometheusMonitoring Weave Cloud with Prometheus
Monitoring Weave Cloud with Prometheus
 
Firebase Code Lab - 2015 GDG Buffalo DevFest
Firebase Code Lab - 2015 GDG Buffalo DevFestFirebase Code Lab - 2015 GDG Buffalo DevFest
Firebase Code Lab - 2015 GDG Buffalo DevFest
 
Node withoutservers aws-lambda
Node withoutservers aws-lambdaNode withoutservers aws-lambda
Node withoutservers aws-lambda
 
Serverless Reality
Serverless RealityServerless Reality
Serverless Reality
 
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
 
Docker Serverless
Docker ServerlessDocker Serverless
Docker Serverless
 
Enterprise level application in 5 min
Enterprise level application in 5 minEnterprise level application in 5 min
Enterprise level application in 5 min
 
AWS Community Day Bangkok 2019 - How AWS Parallel Cluster can accelerate high...
AWS Community Day Bangkok 2019 - How AWS Parallel Cluster can accelerate high...AWS Community Day Bangkok 2019 - How AWS Parallel Cluster can accelerate high...
AWS Community Day Bangkok 2019 - How AWS Parallel Cluster can accelerate high...
 
Serverless with Google Cloud Functions
Serverless with Google Cloud FunctionsServerless with Google Cloud Functions
Serverless with Google Cloud Functions
 
Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...
Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...
Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...
 
gRPC @ Weaveworks
gRPC @ WeaveworksgRPC @ Weaveworks
gRPC @ Weaveworks
 
Serverless with Google Cloud
Serverless with Google CloudServerless with Google Cloud
Serverless with Google Cloud
 
Things you wish you never knew about the Prometheus Remote Write API.
Things you wish you never knew about the Prometheus Remote Write API.Things you wish you never knew about the Prometheus Remote Write API.
Things you wish you never knew about the Prometheus Remote Write API.
 
Building a Serverless company with Node.js, React and the Serverless Framewor...
Building a Serverless company with Node.js, React and the Serverless Framewor...Building a Serverless company with Node.js, React and the Serverless Framewor...
Building a Serverless company with Node.js, React and the Serverless Framewor...
 
Supercharge your app with Cloud Functions for Firebase
Supercharge your app with Cloud Functions for FirebaseSupercharge your app with Cloud Functions for Firebase
Supercharge your app with Cloud Functions for Firebase
 
ApacheCon Testing Camel K with Cloud Native BDD
ApacheCon Testing Camel K with Cloud Native BDDApacheCon Testing Camel K with Cloud Native BDD
ApacheCon Testing Camel K with Cloud Native BDD
 
Building cloud native apps with .net core 3.0 and kubernetes
Building cloud native apps with .net core 3.0 and kubernetesBuilding cloud native apps with .net core 3.0 and kubernetes
Building cloud native apps with .net core 3.0 and kubernetes
 
Where should I run my code? Serverless, Containers, Virtual Machines and more
Where should I run my code? Serverless, Containers, Virtual Machines and moreWhere should I run my code? Serverless, Containers, Virtual Machines and more
Where should I run my code? Serverless, Containers, Virtual Machines and more
 
Fluent 2018: When third parties stop being polite... and start getting real
Fluent 2018: When third parties stop being polite... and start getting realFluent 2018: When third parties stop being polite... and start getting real
Fluent 2018: When third parties stop being polite... and start getting real
 
OpenWhisk
OpenWhiskOpenWhisk
OpenWhisk
 

Destacado

詹姆士看天下 2016/11/07
詹姆士看天下 2016/11/07詹姆士看天下 2016/11/07
詹姆士看天下 2016/11/07ezfunds
 
Relazione Finanziaria Annuale al 31 dicembre 2015 del Gruppo Ferrovie dello S...
Relazione Finanziaria Annuale al 31 dicembre 2015 del Gruppo Ferrovie dello S...Relazione Finanziaria Annuale al 31 dicembre 2015 del Gruppo Ferrovie dello S...
Relazione Finanziaria Annuale al 31 dicembre 2015 del Gruppo Ferrovie dello S...FS Italiane
 
詹姆士看天下 2017/01/03
詹姆士看天下 2017/01/03詹姆士看天下 2017/01/03
詹姆士看天下 2017/01/03ezfunds
 
How IBM Watson will change content creation in the workplace forever
How IBM Watson will change content creation in the workplace foreverHow IBM Watson will change content creation in the workplace forever
How IBM Watson will change content creation in the workplace foreverLetsConnect
 

Destacado (12)

Fulvestrant β isomer
Fulvestrant β isomerFulvestrant β isomer
Fulvestrant β isomer
 
Usman final - Copy (1)
Usman final - Copy (1)Usman final - Copy (1)
Usman final - Copy (1)
 
詹姆士看天下 2016/11/07
詹姆士看天下 2016/11/07詹姆士看天下 2016/11/07
詹姆士看天下 2016/11/07
 
Unit iv
Unit ivUnit iv
Unit iv
 
Semillero de informática iee
Semillero de informática ieeSemillero de informática iee
Semillero de informática iee
 
01 модели школ
01 модели школ01 модели школ
01 модели школ
 
Achivos y sistemas de archivos
Achivos y sistemas de archivosAchivos y sistemas de archivos
Achivos y sistemas de archivos
 
Relazione Finanziaria Annuale al 31 dicembre 2015 del Gruppo Ferrovie dello S...
Relazione Finanziaria Annuale al 31 dicembre 2015 del Gruppo Ferrovie dello S...Relazione Finanziaria Annuale al 31 dicembre 2015 del Gruppo Ferrovie dello S...
Relazione Finanziaria Annuale al 31 dicembre 2015 del Gruppo Ferrovie dello S...
 
詹姆士看天下 2017/01/03
詹姆士看天下 2017/01/03詹姆士看天下 2017/01/03
詹姆士看天下 2017/01/03
 
Msds training
Msds trainingMsds training
Msds training
 
Ingles (15) copia
Ingles (15)   copiaIngles (15)   copia
Ingles (15) copia
 
How IBM Watson will change content creation in the workplace forever
How IBM Watson will change content creation in the workplace foreverHow IBM Watson will change content creation in the workplace forever
How IBM Watson will change content creation in the workplace forever
 

Similar a Serverless

VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primerBruce McPherson
 
Micro app-framework - NodeLive Boston
Micro app-framework - NodeLive BostonMicro app-framework - NodeLive Boston
Micro app-framework - NodeLive BostonMichael Dawson
 
IndexedDB and Push Notifications in Progressive Web Apps
IndexedDB and Push Notifications in Progressive Web AppsIndexedDB and Push Notifications in Progressive Web Apps
IndexedDB and Push Notifications in Progressive Web AppsAdégòkè Obasá
 
Serverless archtiectures
Serverless archtiecturesServerless archtiectures
Serverless archtiecturesIegor Fadieiev
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Python Ireland
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps OfflinePedro Morais
 
JavaScript & Cloud: the AWS JS SDK and how to work with cloud resources
JavaScript & Cloud: the AWS JS SDK and how to work with cloud resourcesJavaScript & Cloud: the AWS JS SDK and how to work with cloud resources
JavaScript & Cloud: the AWS JS SDK and how to work with cloud resourcesCorley S.r.l.
 
Building an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and FirebaseBuilding an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and FirebaseMarina Coelho
 
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxTrack 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxAmazon Web Services
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hacksteindistributed matters
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWAREFIWARE
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015NoSQLmatters
 
The Ring programming language version 1.10 book - Part 53 of 212
The Ring programming language version 1.10 book - Part 53 of 212The Ring programming language version 1.10 book - Part 53 of 212
The Ring programming language version 1.10 book - Part 53 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 53 of 184
The Ring programming language version 1.5.3 book - Part 53 of 184The Ring programming language version 1.5.3 book - Part 53 of 184
The Ring programming language version 1.5.3 book - Part 53 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184Mahmoud Samir Fayed
 
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!Sébastien Levert
 
APIs, APIs Everywhere!
APIs, APIs Everywhere!APIs, APIs Everywhere!
APIs, APIs Everywhere!BIWUG
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDmitriy Sobko
 

Similar a Serverless (20)

VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 
Micro app-framework - NodeLive Boston
Micro app-framework - NodeLive BostonMicro app-framework - NodeLive Boston
Micro app-framework - NodeLive Boston
 
Micro app-framework
Micro app-frameworkMicro app-framework
Micro app-framework
 
IndexedDB and Push Notifications in Progressive Web Apps
IndexedDB and Push Notifications in Progressive Web AppsIndexedDB and Push Notifications in Progressive Web Apps
IndexedDB and Push Notifications in Progressive Web Apps
 
Serverless archtiectures
Serverless archtiecturesServerless archtiectures
Serverless archtiectures
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
 
JavaScript & Cloud: the AWS JS SDK and how to work with cloud resources
JavaScript & Cloud: the AWS JS SDK and how to work with cloud resourcesJavaScript & Cloud: the AWS JS SDK and how to work with cloud resources
JavaScript & Cloud: the AWS JS SDK and how to work with cloud resources
 
Building an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and FirebaseBuilding an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and Firebase
 
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxTrack 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hackstein
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
 
The Ring programming language version 1.10 book - Part 53 of 212
The Ring programming language version 1.10 book - Part 53 of 212The Ring programming language version 1.10 book - Part 53 of 212
The Ring programming language version 1.10 book - Part 53 of 212
 
The Ring programming language version 1.5.3 book - Part 53 of 184
The Ring programming language version 1.5.3 book - Part 53 of 184The Ring programming language version 1.5.3 book - Part 53 of 184
The Ring programming language version 1.5.3 book - Part 53 of 184
 
The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184
 
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
 
APIs, APIs Everywhere!
APIs, APIs Everywhere!APIs, APIs Everywhere!
APIs, APIs Everywhere!
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 

Último

Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 

Último (20)

(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 

Serverless

  • 1.
  • 2. Typical Serverless Architecture Copyright © 2016 classicprogrammerpaintings.com All Rights Reserved.
  • 3. Agenda • Frontend • Add security with Cognito and Google Identity Provider • Store Data in Dynamo DB • Build Microservice with Lambda • Deploy source code into S3 Bucket
  • 5. Add security with Cognito and Google Identity Provider 1. Obtain Google IDP Client Id: 2. Update index.html with Google Client Id 3. Update Identity Pool config.json with Google Client Id 4. Create a new Identity Pool 5. Update javascript config file(s) with Identity Pool Id
  • 6. variable "login_provider" { default = "105303240909-am1nkfpr1fmo9d2bce5pbkv.apps.googleusercontent.com" } resource "template_file" "login_provider_config" { template = "${file("${path.module}/../conf/cognito/config.json.tpl")}" vars { login_provider = "${var.login_provider}" } provisioner "local-exec" { command ="echo "${self.rendered}" > ${path.module}/../conf/cognito/config.json" } }
  • 7. Store Data in DynamoDB saveAnswer: function(problemId, answer) { return cognito.identity.then(function(identity) { var db = new AWS.DynamoDB.DocumentClient(); var item = { TableName: 'answers', Item: { userId: identity.id, problemId: problemId, answer: answer } }; return cognito.sendAwsRequest(db.put(item), function(){ return saveAnswer(problemId, answer); }) }) }
  • 8. { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": [ "dynamodb:BatchGetItem", "dynamodb:BatchWriteItem", "dynaeleteItem", "dynamodb:modb:DGetItem", "dynamodb:PutItem", "dynamodb:Query", "dynamodb:UpdateItem" ], "Resource": ["arn:aws:dynamodb:us-east-1:1111111111:table/problems"], "Condition": { "ForAllValues:StringEquals": { "dynamodb:LeadingKeys": ["${cognito-identity.amazonaws.com:sub}"]} } }] } IAM Permission Policy
  • 9. Build Microservice with Lambda Frontend code checkAnswer: function(problemId, answer) { return cognito.identity.then(function(identity) { var lambda = new AWS.Lambda(); var params = { FunctionName: 'spa_checkAnswer', Payload: JSON.stringify({ problemId: problemId, answer: answer }) }; return cognito.sendAwsRequest(lambda.invoke(params), function(){ return checkAnswer(problemId, answer); }) }) }
  • 10. Build Microservice with Lambda Backend code 'use strict'; let doc = require('dynamodb-doc'); let dynamo = new doc.DynamoDB(); exports.handler = (event, context, callback) => { let params = { TableName : "problems", KeyConditionExpression: "problemId = :problemId", ExpressionAttributeValues: { ":problemId":event.problemId } }; dynamo.query(params, function(err, data) { if (err) { callback(Error("Unable to query: " + JSON.stringify(event) + " .Error:" + JSON.stringify(err))); } else { if (data.Items.length > 0) { let test = data.Items[0].Code.replace('__', event.answer) + '; problem();'; context.succeed(eval(test)); } else { callback(Error("Problem not found")); } } }); };
  • 11. API Gateway Copyright © 2016 Amazon Web Services All Rights Reserved.
  • 12. Swagger definition { "swagger": ... "paths": { "/get-tenants": { "get": { "responses": { "200": { "description": "List of tenants", "schema": {"$ref": "#/definitions/Tenants" } }} "x-amazon-apigateway-integration": { "type": "aws", "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03- 31/functions/arn:aws:lambda:us-east- 1:111111111111:function:${func}/invocations", "httpMethod": "POST", "credentials":"arn:aws:iam::111111111111:role/${invoke-lambda}", ...
  • 13. First Deployment 1. Deploy infrastructure $ terraform apply 2. Deploy the content to s3 bucket $ npm install $ aws s3 sync app/ s3://s3-spa.demos3.com/ --acl public-read --profile spa 3. Import DynamoDB data $ aws dynamodb batch-write-item --request-items file://conf/dynamodb/sampledata/Problems.json --profile spa 4. Enjoy http://s3-spa.demos3.com.s3-website-us-east-1.amazonaws.com
  • 14. Alternatives • Cloud Formation (CF stack) • Boto3 • Troposphere
  • 15. References • Serverless Single Page Apps – Ben Rady • AWS Lambda in Action - Danilo Poccia • https://aws.amazon.com/documentation/ • https://www.terraform.io/ • https://github.com/yegor86/spa-aws

Notas del editor

  1. AWS Lambda is arguably the most exciting service released in AWS since EC2. Lambda is a service that lets you run code on someone else’s machine, in this case EC2. All you need to do is pick the runtime your code can run in, and provide the code. Currently, the supported runtimes are: - Node.js: v0.10.36, v4.3.2 - Java: Java 8 - Python: Python 2.7 Developing applications using Lambda differs from the way we are typically used to, in terms of codebase management, tooling, frameworks, testing and deployment. On one hand, Lambda offers us the entire AWS ecosystem with simple configurations, and on the other, it requires us to rethink how we approach building even small applications. There aren’t yet enough success stories and best practices out there to give one the confidence to build large applications using Lambda, but there’s enough information to start farming out computation heavy processes to Lambda. Lambda especially shines because of its ability to scale along with its workload. API Gateway is another exciting service on AWS that aims to ease the task of creating APIs. You define your resources and their models, request transformations, locations where requests should be proxied to, response transformations; and you get a functioning API without deploying a single machine. An API Gateway endpoint can use a Lambda function as its backend, which is the sweet spot touted by serverless architecture advocates. I recently created a small project using Lambda and API Gateway. You can find the project source following the link: https://github.com/yegor86/spa-aws One major pain point of using Lambda and API Gateway is the difficulty of setting things up, so the project uses Terraform to ease that difficulty. Terraform is a tool that lets you define configurations, which it can run to provision resources on datacenters by providers such as AWS, Azure and Google Cloud. In this project, Terraform is used to provision the Lambda function and API Gateway resources. With Terraform installed, the project can be deployed by simply invoking: - terraform apply terraform destroy Like every system in its early life, API Gateway and Lambda have minor bugs and areas of improvement. Overall, the combination of these technologies is lethal, and I’m interested in seeing how functionality in existing applications can be chipped away to harness the strengths of these so-called serverless architectures.
  2. There is no standardized way to design server less applications. No 2-3-4-.. layers architecture either. All we know you have to govern a bunch of different components. You need to get something more than just building/configuration management tool to get the components together It is yet to understand how to design and develop such systems. And, what is most important, yet to prove whether these systems are production ready
  3. I will walk you through the steps of building and deploying a serverless web application
  4. Use you favorite Java script framework to build a frontend. I would recommend you to keep an eye on ThoughtWorks. ThoughtWorks publishes ‘hot’ technologies on regular basis I am using AngularJs now.
  5. Amazon Cognito lets you easily add user sign-in to your mobile and web apps. With Amazon Cognito, you can also authenticate users through social identity providers such as Facebook, Twitter, or Amazon, or by using your own identity solution. In our application we will do all the steps above using Terraform. Alternatively, you can do all this steps manually or using shell scripting intensively
  6. Terraform comes in play when you want to have Infrastructure as a code Automated integration of Amazon/Azure/Google Cloud services Put all necessary IDs, ARNs and other services/resource identifier into the right place in your source code Terraform enables us with ability to specify client id once within terraform. Then it renders config templates with the corresponding resource identifiers. With Terraform you can - Resolve all dependencies, - Quickly Undo/Redo changes - Avoid boilerplate code (using modules)
  7. This call is possible thanks to Fine-Grained Access Control for DynamoDB To implement this kind of fine-grained access control, you write an IAM permissions policy that specifies conditions for accessing database. 
  8. The permissions policy grants permissions that allow a set of DynamoDB actions on the problems table. It uses the dynamodb:LeadingKeys condition key to restrict access for unauthorized users. The Condition entry in this policy uses a substitution variable to grab the Cognito ID from the request. This ensures that only authenticated Cognito users can access the table, and that they only have access to the documents that they created. All you need is to attach this policy to Cognito IAM Role and you will be able to access DB from client’s code completely secure
  9. Sometimes you want to hide the logic from prying eyes for security reason or don’t want to share the code Lambda supports ES6 out of the box now. Don’t need to transpile the code anymore
  10. As we’ve seen, invoking Lambda functions via the AWS SDK with Cognito credentials can be a great way to integrate custom services into your applications, but what if you want to provide public access to a Lambda function? You can make these functions accessible via an unauthenticated HTTP request using the Amazon API gateway. The Amazon API Gateway maps APIs to Lambda functions through endpoints that you define with each function. 
  11. Aws added several Swagger extensions which help us to define API via Swagger. Swagger is a simple yet powerful representation of your RESTful API JSON and YAML are supported formats
  12. Boto3 worth looking at if you want to get find-grained control over your infrastructure. You will have to deal with plenty of python code then Troposphere is also written in python. Simplify usage of Cloud Formation