SlideShare une entreprise Scribd logo
1  sur  51
Amazon Web Services.
From infrastructure
to platform Roman Gomolko
rg@audienceproject.com
AudienceProject
• Developing products that allow to learn digital audiences
• Started using AWS more than 5 years ago
• Fully migrated to AWS more than 2 years ago
• Processing 4 billions requests monthly
• Generating reports based on 8 billions of requests with batched reports
• Online reports on 300 millions of records
• Used ~40% of services provided by AWS
• Totally happy regarding using AWS
Why cloud?
VS
Amazon provides Infrastructure as a Services
• Virtual server (EC2) with operating system preinstalled
- Wide choice of instance types optimized for CPU, RAM or I/O
- Preinstalled operating systems or custom images
- Pay per hour of use
• Magnetic or SSD drives
- attach to running instances
- provisioned or size-dependent IOPs
- up to 64 Tb (SSD)
- backups
• Networking & Firewall
- Easy IP management
- Load balancers
- VPN & VPC
Development and deployment
Today’s agenda
YA.LS
* yet another link shortener
*
http://ya.ls/dx9 ↣ http://buildstuff.com.ua/
Add packages
{
"name": "yals",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"private": true,
"dependencies": {
"body-parser": "^1.14.1",
"express": "^4.13.3",
"node-localstorage": "^0.6.0",
"short-hash": "^1.0.0"
}
}
Bootstrap your application
var express = require('express');
var bodyParser = require('body-parser');
var shortHash = require('short-hash');
var LocalStorage = LocalStorage;
var storage = new (require('node-localstorage').LocalStorage)('./storage');
var app = express();
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.get('/', function (req, res) {
res.render('index.html')
});
Add your shorten logic
app.post('/shorten', function (req, res) {
var url = req.body && req.body.url;
if (!url) {
return res.status(400).json({message: 'no URL'}).end();
} else {
var hash = shortHash(url);
storage.setItem(hash, url);
res.json({
hash: hash,
shortUrl: process.env.HOST + hash,
targetUrl: url});
}
})
Add your redirection logic
app.get('/:key', function (req, res) {
var url = storage.getItem(req.params.key);
if (url) {
res.redirect(302, url);
} else {
res.status(404).send('Sorry, link not found');
}
});
var server = app.listen(process.env.PORT || 8888);
<form method="post" onsubmit="shorten(); return false;">
<input type="url"
id="url"
placeholder="Paste your URL here"/>
<input type="submit" value="Shorten">
<div id="recent-links"></div>
</form>
Create fancy UI
window.shorten = function () {
fetch('/shorten', {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({url: document.getElementById('url').value})
}).then(function (response) {
var url = response.json().shortUrl;
var msg = url ? '<a href="' + url + '">' + url + '</a>' : response.message;
document.getElementById('recent-links').innerHTML = msg;
});
};
Create modern JavaScript frontend
PORT=8000
HOST=http://localhost:8000/
npm run start
Launch your application
Deploy your application to the AWS
Elastic Beanstalk
• Quick deployment and management of Web application
• PHP, ASP.NET, Python, NodeJS, Docker etc
• No need to setup infrastructure
• Performance metrics
• Scale up and scale down
• Rolling updates
Deploy your application
eb init shortener --region eu-west-1 --platform "node.js"
eb create demo
eb setenv HOST=http://ya.ls/
eb deploy
eb open
Your Beanstalk control panel
Near real-time metrics of your application
Your Beanstalk control panel
Elastic Beanstalk - scaled setup
Traditional SQL databases hosteb my Amazon - RDS
• Fully managed traditional SQL servers
- MySQL
- MS SQL
- PostgreSQL
- Oracle
• Variety of server sizes
• Licenses included into price
• Automated backups
• Restore to point at a time
• Document DB
• No limits on size
• Provisioned throughput
• Differents attribute types including Lists and JSON
DynamoDB
Get DynamoDB high level API
npm install aws-sdk --save
var AWS = require("aws-sdk");
AWS.config.update({region: 'eu-west-1'});
var db = new AWS.DynamoDB.DocumentClient(); // <!-- high level SDK
Put hash to DynamoDB
app.post('/shorten', function (req, res) {
var url = req.body && req.body.url;
…
var hash = shortHash(url);
db.put({
TableName: "short_links",
Item: {"hash": hash, targetUrl: url}
}, function () {
storage.setItem(hash, url);
res.json(...);
})
…
Get from DynamoDB
var hash = req.params.key;
var url = storage.getItem(hash);
if (url) {
return go(res, url);
}
db.get(
{TableName: "short_links", Key: {"hash": hash}},
function (err, record) {
url = record.targetUrl;
url && storage.setItem(hash, url); //local cache
go(res, url);
});
Security considerations - IAM
• Identity and Access Management
• Generate policies that describes
- what operations
- are allowed or denied
- to what AWS resources
- (in what circumstances)
• Apply policy to:
- IAM User identified by Access Key and Secret key
- EC2 instance
• vim ~/.aws/credentials
[dev]
aws_access_key_id = AKIA....
aws_secret_access_key = PQC+9o…
• AWS_PROFIEL=dev PORT=8000 HOST=http://localhost:8000/ npm run start
Horizontal scalability achieved
Adding screenshot functionality
var webshot = require('webshot');
webshot(targetUrl, hash + '.png', function(err) {
// Screenshot is ready. Where I should save it?
});
S3
• Virtually unlimited storage
• Reliable
• Fast
• Secure
• Accessible from Internet
Making screenshot
function makeScreenshot(url, hash, callback) {
var fileName = hash + '.png';
webshot(url, fileName, function (err) {
if (err) { return callback(err); }
var stream = fs.createReadStream(fileName)
s3.upload({
Bucket: 'yals-screenshots',
Key: fileName,
ACL: "public-read",
ContentType: "image/png",
Body: stream
}, callback);
});
}
Using queues for storing screenshotting commands - SQS
• Simple Queue System
- Send
- Receive
- Delete
• Cheap: $0.5 for 1M requests
• Reliable
• Durable
• Fast
Making screenshots using SQS to control flow
Screenshotting is just a function. Lambda in on the stage
• Invoke code in response to events
- File uploads to S3
- DynamoDB table changes
- SNS notifications
- HTTP requests
- Scheduled executions
• Just bring your code
- Node.JS
- Python 2.7
- Java 8
• Pay per invokations and computation power
- making 5M screenshots will cost you ~$42*
* 512 Mb RAM, 2 minutes timeout
Screenshotting function with writing results to DynamoDB
exports.handler = function (data, context) {
var hash = …;
var targetUrl = …;
makeScreenshot(hash, targetUrl, function(err, r) {
if (err) {return context.fail(err)};
db.put({
TableName: "short_links",
Item: {"hash": hash, screenshotUrl: r.Location}
}, context.done);
})
};
Hookup Lambda to new shorten links. DynamoDB streams is on the stage
Ordered stream of changes happened to DynamoDB table
• Any change in table is recorded
• Old record and new record can be stored together with change
• Multiple applications processing stream
• Lambda can be easily attached
Fine tuning screenshotting Lambda
exports.handler = function (data, context) {
var item = data.Records[0].dynamodb.NewImage;
var hash = item.hash.S;
var targetUrl = item.targetUrl.S;
var screenshotUrl = item.screenshotUrl.S;
if (screenshotUrl){
return context.success("Screenshot already taken");
}
makeScreenshot(hash, targetUrl, function(err, r) {
...
Architecture with screenshotting functionality
Static content delivery - CloudFront
• CDN for static and dynamic content
• Web and Streaming distributions
• Seamless integration with S3
• Own SSL certificates, free for SNI
• Requests logging and delivery to S3
• Serving dynamic content from Beanstalk, Load balancers and own servers
• Device detection
• Cost effective
Application architecture with CDN
Need to collect click statistic
Storage for statistics - DynamoDB
link_click_statistic
hash (key) date (sort key) desktop mobile tablet other
ddd79ad9 2015-11-22 1050 110 99 4
ddd79ad9 2015-11-23 1301 123 51 1
aa4cbddf 2015-11-22 1513 13 6 2
Click stream storage - Kinesis
• Ordered events stream
• Reliable
• Scalable
• High performance
• Multiple consumers
Processing stream
• Kinesis Client Library (Java)
• Kinesis Multilanguage Daemon (any platform)
• Lambda
Send to Kinesis
function go(req, res, hash, url) {
if (url) {
var kinesis = new AWS.Kinesis();
var params = {
Data: JSON.stringify({"hash": hash, "userAgent": req.header('user-
agent')}),
PartitionKey: "hash",
StreamName: 'yals_clicks'
};
kinesis.putRecord(params);
Lambda skeleton
• Configure batch size (e.g. 1000)
• Group batch to collection of structures
- hash
- date
- desktop
- mobile
- tablet
- other
• Perform DynamoDB update...
Aggregation function
exports.handler = function(data, context){
rows = ...;
// Agg
var params = {
TableName: "link_click_statistic",
Key: {
"hash": row.hash,
"date": row.date
},
UpdateExpression: "ADD desktop :d, mobile :m, ...";
ExpressionAttributeValues: {":d": row.desktop, ":m": row.mobile...};
};
dynamo.updateItem(params, send_next_item);
}
Aggregation architecture
Too many setup were done manually
CloudFormation
• describe services you need
• specify policies
• use configuration variable
• and let Amazon handle it
Quick recap
• Beanstalk - websites hostings
• RDS - hosted relational DB
• DynamoDB - document DB with cool features
• SQS - simple queue service
• S3 - infinite file storage
• CloudFront - static and dynamic content delivery
• Lambda - running code in response to event
• Kinesis - operate with data streams as wizard
• IAM - security in cloud
• CloudFormation - automated cloud resources provisioning
Thank you
Checkout sources https://github.com/romanych/yals
Further watching
• https://www.youtube.com/watch?v=KmHGrONoif4
• https://www.youtube.com/watch?v=8u9wIC1xNt8
• https://www.youtube.com/watch?v=pBLdMCksM3A
• https://www.youtube.com/watch?v=ZBxWZ9bgd44
• https://www.youtube.com/watch?v=TnfqJYPjD9I
• https://www.youtube.com/watch?v=6R44BADNJA8

Contenu connexe

Tendances

Scaling on AWS for the First 10 Million Users
Scaling on AWS for the First 10 Million UsersScaling on AWS for the First 10 Million Users
Scaling on AWS for the First 10 Million UsersAmazon Web Services
 
Scale Your Application while Improving Performance and Lowering Costs (SVC203...
Scale Your Application while Improving Performance and Lowering Costs (SVC203...Scale Your Application while Improving Performance and Lowering Costs (SVC203...
Scale Your Application while Improving Performance and Lowering Costs (SVC203...Amazon Web Services
 
Hosting Drupal on Amazon EC2
Hosting Drupal on Amazon EC2Hosting Drupal on Amazon EC2
Hosting Drupal on Amazon EC2Kornel Lugosi
 
AWS re:Invent 2016: Taking DevOps to the AWS Edge (CTD302)
AWS re:Invent 2016: Taking DevOps to the AWS Edge (CTD302)AWS re:Invent 2016: Taking DevOps to the AWS Edge (CTD302)
AWS re:Invent 2016: Taking DevOps to the AWS Edge (CTD302)Amazon Web Services
 
AutoScaling and Drupal
AutoScaling and DrupalAutoScaling and Drupal
AutoScaling and DrupalPromet Source
 
AWS re:Invent 2016: 5 Security Automation Improvements You Can Make by Using ...
AWS re:Invent 2016: 5 Security Automation Improvements You Can Make by Using ...AWS re:Invent 2016: 5 Security Automation Improvements You Can Make by Using ...
AWS re:Invent 2016: 5 Security Automation Improvements You Can Make by Using ...Amazon Web Services
 
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...Amazon Web Services
 
Deep Learning with AWS (November 2016)
Deep Learning with AWS (November 2016)Deep Learning with AWS (November 2016)
Deep Learning with AWS (November 2016)Julien SIMON
 
Scaling on AWS for the First 10 Million Users
Scaling on AWS for the First 10 Million UsersScaling on AWS for the First 10 Million Users
Scaling on AWS for the First 10 Million UsersAmazon Web Services
 
Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)Julien SIMON
 
Stacktician - CloudStack Collab Conference 2014
Stacktician - CloudStack Collab Conference 2014Stacktician - CloudStack Collab Conference 2014
Stacktician - CloudStack Collab Conference 2014amoghvk
 
Infrastructure as Code for Beginners
Infrastructure as Code for BeginnersInfrastructure as Code for Beginners
Infrastructure as Code for BeginnersDavid Völkel
 
Running High Availability Websites with Acquia and AWS
Running High Availability Websites with Acquia and AWSRunning High Availability Websites with Acquia and AWS
Running High Availability Websites with Acquia and AWSAcquia
 
SMC303 Real-time Data Processing Using AWS Lambda
SMC303 Real-time Data Processing Using AWS LambdaSMC303 Real-time Data Processing Using AWS Lambda
SMC303 Real-time Data Processing Using AWS LambdaAmazon Web Services
 
Utah Codecamp Cloud Computing
Utah Codecamp Cloud ComputingUtah Codecamp Cloud Computing
Utah Codecamp Cloud ComputingTom Creighton
 
Best Practices for Genomic and Bioinformatics Analysis Pipelines on AWS
Best Practices for Genomic and Bioinformatics Analysis Pipelines on AWS Best Practices for Genomic and Bioinformatics Analysis Pipelines on AWS
Best Practices for Genomic and Bioinformatics Analysis Pipelines on AWS Amazon Web Services
 
So you think you are an aws ninja dean samuels
So you think you are an aws ninja   dean samuelsSo you think you are an aws ninja   dean samuels
So you think you are an aws ninja dean samuelsAmazon Web Services
 

Tendances (20)

Scaling on AWS for the First 10 Million Users
Scaling on AWS for the First 10 Million UsersScaling on AWS for the First 10 Million Users
Scaling on AWS for the First 10 Million Users
 
Scale Your Application while Improving Performance and Lowering Costs (SVC203...
Scale Your Application while Improving Performance and Lowering Costs (SVC203...Scale Your Application while Improving Performance and Lowering Costs (SVC203...
Scale Your Application while Improving Performance and Lowering Costs (SVC203...
 
Hosting Drupal on Amazon EC2
Hosting Drupal on Amazon EC2Hosting Drupal on Amazon EC2
Hosting Drupal on Amazon EC2
 
AWS re:Invent 2016: Taking DevOps to the AWS Edge (CTD302)
AWS re:Invent 2016: Taking DevOps to the AWS Edge (CTD302)AWS re:Invent 2016: Taking DevOps to the AWS Edge (CTD302)
AWS re:Invent 2016: Taking DevOps to the AWS Edge (CTD302)
 
AWS Black Belt Tips
AWS Black Belt TipsAWS Black Belt Tips
AWS Black Belt Tips
 
AutoScaling and Drupal
AutoScaling and DrupalAutoScaling and Drupal
AutoScaling and Drupal
 
AWS re:Invent 2016: 5 Security Automation Improvements You Can Make by Using ...
AWS re:Invent 2016: 5 Security Automation Improvements You Can Make by Using ...AWS re:Invent 2016: 5 Security Automation Improvements You Can Make by Using ...
AWS re:Invent 2016: 5 Security Automation Improvements You Can Make by Using ...
 
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
 
Deep Learning with AWS (November 2016)
Deep Learning with AWS (November 2016)Deep Learning with AWS (November 2016)
Deep Learning with AWS (November 2016)
 
Scaling on AWS for the First 10 Million Users
Scaling on AWS for the First 10 Million UsersScaling on AWS for the First 10 Million Users
Scaling on AWS for the First 10 Million Users
 
Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)
 
Stacktician - CloudStack Collab Conference 2014
Stacktician - CloudStack Collab Conference 2014Stacktician - CloudStack Collab Conference 2014
Stacktician - CloudStack Collab Conference 2014
 
IaaS azure_vs_amazon
IaaS azure_vs_amazonIaaS azure_vs_amazon
IaaS azure_vs_amazon
 
Infrastructure as Code for Beginners
Infrastructure as Code for BeginnersInfrastructure as Code for Beginners
Infrastructure as Code for Beginners
 
Running High Availability Websites with Acquia and AWS
Running High Availability Websites with Acquia and AWSRunning High Availability Websites with Acquia and AWS
Running High Availability Websites with Acquia and AWS
 
SMC303 Real-time Data Processing Using AWS Lambda
SMC303 Real-time Data Processing Using AWS LambdaSMC303 Real-time Data Processing Using AWS Lambda
SMC303 Real-time Data Processing Using AWS Lambda
 
Utah Codecamp Cloud Computing
Utah Codecamp Cloud ComputingUtah Codecamp Cloud Computing
Utah Codecamp Cloud Computing
 
AWS Webcast - Website Hosting
AWS Webcast - Website HostingAWS Webcast - Website Hosting
AWS Webcast - Website Hosting
 
Best Practices for Genomic and Bioinformatics Analysis Pipelines on AWS
Best Practices for Genomic and Bioinformatics Analysis Pipelines on AWS Best Practices for Genomic and Bioinformatics Analysis Pipelines on AWS
Best Practices for Genomic and Bioinformatics Analysis Pipelines on AWS
 
So you think you are an aws ninja dean samuels
So you think you are an aws ninja   dean samuelsSo you think you are an aws ninja   dean samuels
So you think you are an aws ninja dean samuels
 

Similaire à AWS Services for Building and Scaling a Link Shortening Application

Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Emerson Eduardo Rodrigues Von Staffen
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...Amazon Web Services
 
AWS Webcast - Website Hosting in the Cloud
AWS Webcast - Website Hosting in the CloudAWS Webcast - Website Hosting in the Cloud
AWS Webcast - Website Hosting in the CloudAmazon Web Services
 
Increase Speed and Agility with Amazon Web Services
Increase Speed and Agility with Amazon Web ServicesIncrease Speed and Agility with Amazon Web Services
Increase Speed and Agility with Amazon Web ServicesAmazon Web Services
 
Increase Speed and Agility with Amazon Web Services
Increase Speed and Agility with Amazon Web ServicesIncrease Speed and Agility with Amazon Web Services
Increase Speed and Agility with Amazon Web ServicesAmazon Web Services
 
Application Lifecycle Management on AWS
Application Lifecycle Management on AWSApplication Lifecycle Management on AWS
Application Lifecycle Management on AWSDavid Mat
 
Running your First Application on AWS
Running your First Application on AWSRunning your First Application on AWS
Running your First Application on AWSAmazon Web Services
 
Building a Just-in-Time Application Stack for Analysts
Building a Just-in-Time Application Stack for AnalystsBuilding a Just-in-Time Application Stack for Analysts
Building a Just-in-Time Application Stack for AnalystsAvere Systems
 
AWS Summit Auckland 2014 | Running your First Application on AWS
AWS Summit Auckland 2014 | Running your First Application on AWSAWS Summit Auckland 2014 | Running your First Application on AWS
AWS Summit Auckland 2014 | Running your First Application on AWSAmazon Web Services
 
Automating Security in your IaC Pipeline
Automating Security in your IaC PipelineAutomating Security in your IaC Pipeline
Automating Security in your IaC PipelineAmazon Web Services
 
AWS re:Invent 2016: Deep-Dive: Native, Hybrid and Web patterns with Serverles...
AWS re:Invent 2016: Deep-Dive: Native, Hybrid and Web patterns with Serverles...AWS re:Invent 2016: Deep-Dive: Native, Hybrid and Web patterns with Serverles...
AWS re:Invent 2016: Deep-Dive: Native, Hybrid and Web patterns with Serverles...Amazon Web Services
 
Running your First Application on AWS
Running your First Application on AWS Running your First Application on AWS
Running your First Application on AWS Amazon Web Services
 
Migrating enterprise workloads to AWS
Migrating enterprise workloads to AWS Migrating enterprise workloads to AWS
Migrating enterprise workloads to AWS Tom Laszewski
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without serversAmazon Web Services
 
Migrating enterprise workloads to AWS
Migrating enterprise workloads to AWSMigrating enterprise workloads to AWS
Migrating enterprise workloads to AWSTom Laszewski
 
Aws-What You Need to Know_Simon Elisha
Aws-What You Need to Know_Simon ElishaAws-What You Need to Know_Simon Elisha
Aws-What You Need to Know_Simon ElishaHelen Rogers
 
AWS September Webinar Series - Visual Effects Rendering in the AWS Cloud with...
AWS September Webinar Series - Visual Effects Rendering in the AWS Cloud with...AWS September Webinar Series - Visual Effects Rendering in the AWS Cloud with...
AWS September Webinar Series - Visual Effects Rendering in the AWS Cloud with...Amazon Web Services
 

Similaire à AWS Services for Building and Scaling a Link Shortening Application (20)

Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 
AWS Webcast - Website Hosting in the Cloud
AWS Webcast - Website Hosting in the CloudAWS Webcast - Website Hosting in the Cloud
AWS Webcast - Website Hosting in the Cloud
 
Increase Speed and Agility with Amazon Web Services
Increase Speed and Agility with Amazon Web ServicesIncrease Speed and Agility with Amazon Web Services
Increase Speed and Agility with Amazon Web Services
 
Increase Speed and Agility with Amazon Web Services
Increase Speed and Agility with Amazon Web ServicesIncrease Speed and Agility with Amazon Web Services
Increase Speed and Agility with Amazon Web Services
 
Application Lifecycle Management on AWS
Application Lifecycle Management on AWSApplication Lifecycle Management on AWS
Application Lifecycle Management on AWS
 
Running your First Application on AWS
Running your First Application on AWSRunning your First Application on AWS
Running your First Application on AWS
 
Building a Just-in-Time Application Stack for Analysts
Building a Just-in-Time Application Stack for AnalystsBuilding a Just-in-Time Application Stack for Analysts
Building a Just-in-Time Application Stack for Analysts
 
AWS Summit Auckland 2014 | Running your First Application on AWS
AWS Summit Auckland 2014 | Running your First Application on AWSAWS Summit Auckland 2014 | Running your First Application on AWS
AWS Summit Auckland 2014 | Running your First Application on AWS
 
Introduction to DevOps on AWS
Introduction to DevOps on AWSIntroduction to DevOps on AWS
Introduction to DevOps on AWS
 
Automating Security in your IaC Pipeline
Automating Security in your IaC PipelineAutomating Security in your IaC Pipeline
Automating Security in your IaC Pipeline
 
AWS re:Invent 2016: Deep-Dive: Native, Hybrid and Web patterns with Serverles...
AWS re:Invent 2016: Deep-Dive: Native, Hybrid and Web patterns with Serverles...AWS re:Invent 2016: Deep-Dive: Native, Hybrid and Web patterns with Serverles...
AWS re:Invent 2016: Deep-Dive: Native, Hybrid and Web patterns with Serverles...
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
 
Running your First Application on AWS
Running your First Application on AWS Running your First Application on AWS
Running your First Application on AWS
 
Migrating enterprise workloads to AWS
Migrating enterprise workloads to AWS Migrating enterprise workloads to AWS
Migrating enterprise workloads to AWS
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
DW on AWS
DW on AWSDW on AWS
DW on AWS
 
Migrating enterprise workloads to AWS
Migrating enterprise workloads to AWSMigrating enterprise workloads to AWS
Migrating enterprise workloads to AWS
 
Aws-What You Need to Know_Simon Elisha
Aws-What You Need to Know_Simon ElishaAws-What You Need to Know_Simon Elisha
Aws-What You Need to Know_Simon Elisha
 
AWS September Webinar Series - Visual Effects Rendering in the AWS Cloud with...
AWS September Webinar Series - Visual Effects Rendering in the AWS Cloud with...AWS September Webinar Series - Visual Effects Rendering in the AWS Cloud with...
AWS September Webinar Series - Visual Effects Rendering in the AWS Cloud with...
 

Dernier

High Class Escort Service in Marina +971509430017 Marina Escorts Service
High Class Escort Service in Marina +971509430017 Marina Escorts ServiceHigh Class Escort Service in Marina +971509430017 Marina Escorts Service
High Class Escort Service in Marina +971509430017 Marina Escorts Servicetajaga2345
 
NO1 Certified Love specialist peer baba in MULTAN , SIALKOT +923253991734
NO1 Certified Love specialist peer baba in MULTAN , SIALKOT +923253991734NO1 Certified Love specialist peer baba in MULTAN , SIALKOT +923253991734
NO1 Certified Love specialist peer baba in MULTAN , SIALKOT +923253991734onlinewirker
 
Call Girls In Noida Sector 15 Metro꧁❤ 8800357707 ❤꧂Escorts Service
Call Girls In Noida Sector 15 Metro꧁❤ 8800357707 ❤꧂Escorts ServiceCall Girls In Noida Sector 15 Metro꧁❤ 8800357707 ❤꧂Escorts Service
Call Girls In Noida Sector 15 Metro꧁❤ 8800357707 ❤꧂Escorts Servicemonikaservice1
 
(VAPT) Vulnerability Assessment And Penetration Testing
(VAPT) Vulnerability Assessment And Penetration Testing(VAPT) Vulnerability Assessment And Penetration Testing
(VAPT) Vulnerability Assessment And Penetration TestingBluechip Gulf IT Services
 
Call Girls In Sarita Vihar Delhi 9911107661 Escorts Provide In Delhi
Call Girls In Sarita Vihar Delhi 9911107661 Escorts Provide In DelhiCall Girls In Sarita Vihar Delhi 9911107661 Escorts Provide In Delhi
Call Girls In Sarita Vihar Delhi 9911107661 Escorts Provide In Delhisafdarjungdelhi1
 
kreativan technology is a best IT company
kreativan technology is a best IT companykreativan technology is a best IT company
kreativan technology is a best IT companyKreativan Technologies
 
Book Call Girls In Gurgaon Sector 29 Call 8800357707 Escorts Service
Book Call Girls In Gurgaon Sector 29 Call 8800357707 Escorts ServiceBook Call Girls In Gurgaon Sector 29 Call 8800357707 Escorts Service
Book Call Girls In Gurgaon Sector 29 Call 8800357707 Escorts Servicemonikaservice1
 
Call Girls In Connaught Place꧁❤ 8800357707 ❤꧂Top Quality Escorts Service Delhi
Call Girls In Connaught Place꧁❤ 8800357707 ❤꧂Top Quality Escorts Service DelhiCall Girls In Connaught Place꧁❤ 8800357707 ❤꧂Top Quality Escorts Service Delhi
Call Girls In Connaught Place꧁❤ 8800357707 ❤꧂Top Quality Escorts Service Delhimonikaservice1
 
Justdial Call Girls In Moolchand Metro Delhi 9911191017 Escorts Service
Justdial Call Girls In Moolchand Metro Delhi 9911191017 Escorts ServiceJustdial Call Girls In Moolchand Metro Delhi 9911191017 Escorts Service
Justdial Call Girls In Moolchand Metro Delhi 9911191017 Escorts Servicesafdarjungdelhi1
 
Balancing Sexual Desires for a Happier Relationship_ An Astrological Perspect...
Balancing Sexual Desires for a Happier Relationship_ An Astrological Perspect...Balancing Sexual Desires for a Happier Relationship_ An Astrological Perspect...
Balancing Sexual Desires for a Happier Relationship_ An Astrological Perspect...shubhamaapkikismat
 
WHATSAPP CALL - 9540619990 RUSSIAN CALL GIRLS GHAZIABAD
WHATSAPP CALL - 9540619990 RUSSIAN CALL GIRLS GHAZIABADWHATSAPP CALL - 9540619990 RUSSIAN CALL GIRLS GHAZIABAD
WHATSAPP CALL - 9540619990 RUSSIAN CALL GIRLS GHAZIABADmalikasharmakk1
 
KREATIVAN TECHNOLOGY IS THE BEST DIGITAL COMPANY IN CHANDIGARH
KREATIVAN TECHNOLOGY IS THE BEST DIGITAL COMPANY IN CHANDIGARHKREATIVAN TECHNOLOGY IS THE BEST DIGITAL COMPANY IN CHANDIGARH
KREATIVAN TECHNOLOGY IS THE BEST DIGITAL COMPANY IN CHANDIGARHKreativan Technologies
 
▶ ●─Hookup Call Girls In Noida Sector 137 (Noida) ⎝9667422720⎠ Delhi Female E...
▶ ●─Hookup Call Girls In Noida Sector 137 (Noida) ⎝9667422720⎠ Delhi Female E...▶ ●─Hookup Call Girls In Noida Sector 137 (Noida) ⎝9667422720⎠ Delhi Female E...
▶ ●─Hookup Call Girls In Noida Sector 137 (Noida) ⎝9667422720⎠ Delhi Female E...Lipikasharma29
 
Pros and Cons of Being a Fashion Designer.pdf
Pros and Cons of Being a Fashion Designer.pdfPros and Cons of Being a Fashion Designer.pdf
Pros and Cons of Being a Fashion Designer.pdfEdumystic Institiute
 
Protecting your business: staying compliant with NFPA codes
Protecting your business: staying compliant with NFPA codesProtecting your business: staying compliant with NFPA codes
Protecting your business: staying compliant with NFPA codesStartech Engineering
 
EDITAL DE PROCESSO SELETIVO 001-2024.pdf
EDITAL DE PROCESSO SELETIVO 001-2024.pdfEDITAL DE PROCESSO SELETIVO 001-2024.pdf
EDITAL DE PROCESSO SELETIVO 001-2024.pdfJessicaRosso2
 
Understanding QuickBooks Reconciliation Discrepancy
Understanding QuickBooks Reconciliation DiscrepancyUnderstanding QuickBooks Reconciliation Discrepancy
Understanding QuickBooks Reconciliation Discrepancykatejenifer990
 
High Class Escort Service in Ajman +971509430017 Ajman Escorts Service
High Class Escort Service in Ajman +971509430017 Ajman Escorts ServiceHigh Class Escort Service in Ajman +971509430017 Ajman Escorts Service
High Class Escort Service in Ajman +971509430017 Ajman Escorts Servicetajaga2345
 
Trusted Call~Girls In Rohini Delhi꧁❤ 9667422720 ❤꧂Escorts
Trusted Call~Girls In Rohini Delhi꧁❤ 9667422720 ❤꧂EscortsTrusted Call~Girls In Rohini Delhi꧁❤ 9667422720 ❤꧂Escorts
Trusted Call~Girls In Rohini Delhi꧁❤ 9667422720 ❤꧂EscortsLipikasharma29
 

Dernier (20)

High Class Escort Service in Marina +971509430017 Marina Escorts Service
High Class Escort Service in Marina +971509430017 Marina Escorts ServiceHigh Class Escort Service in Marina +971509430017 Marina Escorts Service
High Class Escort Service in Marina +971509430017 Marina Escorts Service
 
NO1 Certified Love specialist peer baba in MULTAN , SIALKOT +923253991734
NO1 Certified Love specialist peer baba in MULTAN , SIALKOT +923253991734NO1 Certified Love specialist peer baba in MULTAN , SIALKOT +923253991734
NO1 Certified Love specialist peer baba in MULTAN , SIALKOT +923253991734
 
How to Get into the NUS MBA Program? Explore
How to Get into the NUS MBA Program? ExploreHow to Get into the NUS MBA Program? Explore
How to Get into the NUS MBA Program? Explore
 
Call Girls In Noida Sector 15 Metro꧁❤ 8800357707 ❤꧂Escorts Service
Call Girls In Noida Sector 15 Metro꧁❤ 8800357707 ❤꧂Escorts ServiceCall Girls In Noida Sector 15 Metro꧁❤ 8800357707 ❤꧂Escorts Service
Call Girls In Noida Sector 15 Metro꧁❤ 8800357707 ❤꧂Escorts Service
 
(VAPT) Vulnerability Assessment And Penetration Testing
(VAPT) Vulnerability Assessment And Penetration Testing(VAPT) Vulnerability Assessment And Penetration Testing
(VAPT) Vulnerability Assessment And Penetration Testing
 
Call Girls In Sarita Vihar Delhi 9911107661 Escorts Provide In Delhi
Call Girls In Sarita Vihar Delhi 9911107661 Escorts Provide In DelhiCall Girls In Sarita Vihar Delhi 9911107661 Escorts Provide In Delhi
Call Girls In Sarita Vihar Delhi 9911107661 Escorts Provide In Delhi
 
kreativan technology is a best IT company
kreativan technology is a best IT companykreativan technology is a best IT company
kreativan technology is a best IT company
 
Book Call Girls In Gurgaon Sector 29 Call 8800357707 Escorts Service
Book Call Girls In Gurgaon Sector 29 Call 8800357707 Escorts ServiceBook Call Girls In Gurgaon Sector 29 Call 8800357707 Escorts Service
Book Call Girls In Gurgaon Sector 29 Call 8800357707 Escorts Service
 
Call Girls In Connaught Place꧁❤ 8800357707 ❤꧂Top Quality Escorts Service Delhi
Call Girls In Connaught Place꧁❤ 8800357707 ❤꧂Top Quality Escorts Service DelhiCall Girls In Connaught Place꧁❤ 8800357707 ❤꧂Top Quality Escorts Service Delhi
Call Girls In Connaught Place꧁❤ 8800357707 ❤꧂Top Quality Escorts Service Delhi
 
Justdial Call Girls In Moolchand Metro Delhi 9911191017 Escorts Service
Justdial Call Girls In Moolchand Metro Delhi 9911191017 Escorts ServiceJustdial Call Girls In Moolchand Metro Delhi 9911191017 Escorts Service
Justdial Call Girls In Moolchand Metro Delhi 9911191017 Escorts Service
 
Balancing Sexual Desires for a Happier Relationship_ An Astrological Perspect...
Balancing Sexual Desires for a Happier Relationship_ An Astrological Perspect...Balancing Sexual Desires for a Happier Relationship_ An Astrological Perspect...
Balancing Sexual Desires for a Happier Relationship_ An Astrological Perspect...
 
WHATSAPP CALL - 9540619990 RUSSIAN CALL GIRLS GHAZIABAD
WHATSAPP CALL - 9540619990 RUSSIAN CALL GIRLS GHAZIABADWHATSAPP CALL - 9540619990 RUSSIAN CALL GIRLS GHAZIABAD
WHATSAPP CALL - 9540619990 RUSSIAN CALL GIRLS GHAZIABAD
 
KREATIVAN TECHNOLOGY IS THE BEST DIGITAL COMPANY IN CHANDIGARH
KREATIVAN TECHNOLOGY IS THE BEST DIGITAL COMPANY IN CHANDIGARHKREATIVAN TECHNOLOGY IS THE BEST DIGITAL COMPANY IN CHANDIGARH
KREATIVAN TECHNOLOGY IS THE BEST DIGITAL COMPANY IN CHANDIGARH
 
▶ ●─Hookup Call Girls In Noida Sector 137 (Noida) ⎝9667422720⎠ Delhi Female E...
▶ ●─Hookup Call Girls In Noida Sector 137 (Noida) ⎝9667422720⎠ Delhi Female E...▶ ●─Hookup Call Girls In Noida Sector 137 (Noida) ⎝9667422720⎠ Delhi Female E...
▶ ●─Hookup Call Girls In Noida Sector 137 (Noida) ⎝9667422720⎠ Delhi Female E...
 
Pros and Cons of Being a Fashion Designer.pdf
Pros and Cons of Being a Fashion Designer.pdfPros and Cons of Being a Fashion Designer.pdf
Pros and Cons of Being a Fashion Designer.pdf
 
Protecting your business: staying compliant with NFPA codes
Protecting your business: staying compliant with NFPA codesProtecting your business: staying compliant with NFPA codes
Protecting your business: staying compliant with NFPA codes
 
EDITAL DE PROCESSO SELETIVO 001-2024.pdf
EDITAL DE PROCESSO SELETIVO 001-2024.pdfEDITAL DE PROCESSO SELETIVO 001-2024.pdf
EDITAL DE PROCESSO SELETIVO 001-2024.pdf
 
Understanding QuickBooks Reconciliation Discrepancy
Understanding QuickBooks Reconciliation DiscrepancyUnderstanding QuickBooks Reconciliation Discrepancy
Understanding QuickBooks Reconciliation Discrepancy
 
High Class Escort Service in Ajman +971509430017 Ajman Escorts Service
High Class Escort Service in Ajman +971509430017 Ajman Escorts ServiceHigh Class Escort Service in Ajman +971509430017 Ajman Escorts Service
High Class Escort Service in Ajman +971509430017 Ajman Escorts Service
 
Trusted Call~Girls In Rohini Delhi꧁❤ 9667422720 ❤꧂Escorts
Trusted Call~Girls In Rohini Delhi꧁❤ 9667422720 ❤꧂EscortsTrusted Call~Girls In Rohini Delhi꧁❤ 9667422720 ❤꧂Escorts
Trusted Call~Girls In Rohini Delhi꧁❤ 9667422720 ❤꧂Escorts
 

AWS Services for Building and Scaling a Link Shortening Application

  • 1. Amazon Web Services. From infrastructure to platform Roman Gomolko rg@audienceproject.com
  • 2. AudienceProject • Developing products that allow to learn digital audiences • Started using AWS more than 5 years ago • Fully migrated to AWS more than 2 years ago • Processing 4 billions requests monthly • Generating reports based on 8 billions of requests with batched reports • Online reports on 300 millions of records • Used ~40% of services provided by AWS • Totally happy regarding using AWS
  • 4. Amazon provides Infrastructure as a Services • Virtual server (EC2) with operating system preinstalled - Wide choice of instance types optimized for CPU, RAM or I/O - Preinstalled operating systems or custom images - Pay per hour of use • Magnetic or SSD drives - attach to running instances - provisioned or size-dependent IOPs - up to 64 Tb (SSD) - backups • Networking & Firewall - Easy IP management - Load balancers - VPN & VPC
  • 5.
  • 7. Today’s agenda YA.LS * yet another link shortener * http://ya.ls/dx9 ↣ http://buildstuff.com.ua/
  • 8. Add packages { "name": "yals", "main": "index.js", "scripts": { "start": "node index.js" }, "private": true, "dependencies": { "body-parser": "^1.14.1", "express": "^4.13.3", "node-localstorage": "^0.6.0", "short-hash": "^1.0.0" } }
  • 9. Bootstrap your application var express = require('express'); var bodyParser = require('body-parser'); var shortHash = require('short-hash'); var LocalStorage = LocalStorage; var storage = new (require('node-localstorage').LocalStorage)('./storage'); var app = express(); app.use(express.static(__dirname + '/public')); app.use(bodyParser.json()); app.get('/', function (req, res) { res.render('index.html') });
  • 10. Add your shorten logic app.post('/shorten', function (req, res) { var url = req.body && req.body.url; if (!url) { return res.status(400).json({message: 'no URL'}).end(); } else { var hash = shortHash(url); storage.setItem(hash, url); res.json({ hash: hash, shortUrl: process.env.HOST + hash, targetUrl: url}); } })
  • 11. Add your redirection logic app.get('/:key', function (req, res) { var url = storage.getItem(req.params.key); if (url) { res.redirect(302, url); } else { res.status(404).send('Sorry, link not found'); } }); var server = app.listen(process.env.PORT || 8888);
  • 12. <form method="post" onsubmit="shorten(); return false;"> <input type="url" id="url" placeholder="Paste your URL here"/> <input type="submit" value="Shorten"> <div id="recent-links"></div> </form> Create fancy UI
  • 13. window.shorten = function () { fetch('/shorten', { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({url: document.getElementById('url').value}) }).then(function (response) { var url = response.json().shortUrl; var msg = url ? '<a href="' + url + '">' + url + '</a>' : response.message; document.getElementById('recent-links').innerHTML = msg; }); }; Create modern JavaScript frontend
  • 16. Elastic Beanstalk • Quick deployment and management of Web application • PHP, ASP.NET, Python, NodeJS, Docker etc • No need to setup infrastructure • Performance metrics • Scale up and scale down • Rolling updates
  • 17. Deploy your application eb init shortener --region eu-west-1 --platform "node.js" eb create demo eb setenv HOST=http://ya.ls/ eb deploy eb open
  • 19. Near real-time metrics of your application
  • 21. Elastic Beanstalk - scaled setup
  • 22. Traditional SQL databases hosteb my Amazon - RDS • Fully managed traditional SQL servers - MySQL - MS SQL - PostgreSQL - Oracle • Variety of server sizes • Licenses included into price • Automated backups • Restore to point at a time
  • 23. • Document DB • No limits on size • Provisioned throughput • Differents attribute types including Lists and JSON DynamoDB
  • 24. Get DynamoDB high level API npm install aws-sdk --save var AWS = require("aws-sdk"); AWS.config.update({region: 'eu-west-1'}); var db = new AWS.DynamoDB.DocumentClient(); // <!-- high level SDK
  • 25. Put hash to DynamoDB app.post('/shorten', function (req, res) { var url = req.body && req.body.url; … var hash = shortHash(url); db.put({ TableName: "short_links", Item: {"hash": hash, targetUrl: url} }, function () { storage.setItem(hash, url); res.json(...); }) …
  • 26. Get from DynamoDB var hash = req.params.key; var url = storage.getItem(hash); if (url) { return go(res, url); } db.get( {TableName: "short_links", Key: {"hash": hash}}, function (err, record) { url = record.targetUrl; url && storage.setItem(hash, url); //local cache go(res, url); });
  • 27. Security considerations - IAM • Identity and Access Management • Generate policies that describes - what operations - are allowed or denied - to what AWS resources - (in what circumstances) • Apply policy to: - IAM User identified by Access Key and Secret key - EC2 instance • vim ~/.aws/credentials [dev] aws_access_key_id = AKIA.... aws_secret_access_key = PQC+9o… • AWS_PROFIEL=dev PORT=8000 HOST=http://localhost:8000/ npm run start
  • 29. Adding screenshot functionality var webshot = require('webshot'); webshot(targetUrl, hash + '.png', function(err) { // Screenshot is ready. Where I should save it? });
  • 30. S3 • Virtually unlimited storage • Reliable • Fast • Secure • Accessible from Internet
  • 31. Making screenshot function makeScreenshot(url, hash, callback) { var fileName = hash + '.png'; webshot(url, fileName, function (err) { if (err) { return callback(err); } var stream = fs.createReadStream(fileName) s3.upload({ Bucket: 'yals-screenshots', Key: fileName, ACL: "public-read", ContentType: "image/png", Body: stream }, callback); }); }
  • 32. Using queues for storing screenshotting commands - SQS • Simple Queue System - Send - Receive - Delete • Cheap: $0.5 for 1M requests • Reliable • Durable • Fast
  • 33. Making screenshots using SQS to control flow
  • 34. Screenshotting is just a function. Lambda in on the stage • Invoke code in response to events - File uploads to S3 - DynamoDB table changes - SNS notifications - HTTP requests - Scheduled executions • Just bring your code - Node.JS - Python 2.7 - Java 8 • Pay per invokations and computation power - making 5M screenshots will cost you ~$42* * 512 Mb RAM, 2 minutes timeout
  • 35. Screenshotting function with writing results to DynamoDB exports.handler = function (data, context) { var hash = …; var targetUrl = …; makeScreenshot(hash, targetUrl, function(err, r) { if (err) {return context.fail(err)}; db.put({ TableName: "short_links", Item: {"hash": hash, screenshotUrl: r.Location} }, context.done); }) };
  • 36. Hookup Lambda to new shorten links. DynamoDB streams is on the stage Ordered stream of changes happened to DynamoDB table • Any change in table is recorded • Old record and new record can be stored together with change • Multiple applications processing stream • Lambda can be easily attached
  • 37. Fine tuning screenshotting Lambda exports.handler = function (data, context) { var item = data.Records[0].dynamodb.NewImage; var hash = item.hash.S; var targetUrl = item.targetUrl.S; var screenshotUrl = item.screenshotUrl.S; if (screenshotUrl){ return context.success("Screenshot already taken"); } makeScreenshot(hash, targetUrl, function(err, r) { ...
  • 39. Static content delivery - CloudFront • CDN for static and dynamic content • Web and Streaming distributions • Seamless integration with S3 • Own SSL certificates, free for SNI • Requests logging and delivery to S3 • Serving dynamic content from Beanstalk, Load balancers and own servers • Device detection • Cost effective
  • 41. Need to collect click statistic
  • 42. Storage for statistics - DynamoDB link_click_statistic hash (key) date (sort key) desktop mobile tablet other ddd79ad9 2015-11-22 1050 110 99 4 ddd79ad9 2015-11-23 1301 123 51 1 aa4cbddf 2015-11-22 1513 13 6 2
  • 43. Click stream storage - Kinesis • Ordered events stream • Reliable • Scalable • High performance • Multiple consumers Processing stream • Kinesis Client Library (Java) • Kinesis Multilanguage Daemon (any platform) • Lambda
  • 44. Send to Kinesis function go(req, res, hash, url) { if (url) { var kinesis = new AWS.Kinesis(); var params = { Data: JSON.stringify({"hash": hash, "userAgent": req.header('user- agent')}), PartitionKey: "hash", StreamName: 'yals_clicks' }; kinesis.putRecord(params);
  • 45. Lambda skeleton • Configure batch size (e.g. 1000) • Group batch to collection of structures - hash - date - desktop - mobile - tablet - other • Perform DynamoDB update...
  • 46. Aggregation function exports.handler = function(data, context){ rows = ...; // Agg var params = { TableName: "link_click_statistic", Key: { "hash": row.hash, "date": row.date }, UpdateExpression: "ADD desktop :d, mobile :m, ..."; ExpressionAttributeValues: {":d": row.desktop, ":m": row.mobile...}; }; dynamo.updateItem(params, send_next_item); }
  • 48. Too many setup were done manually CloudFormation • describe services you need • specify policies • use configuration variable • and let Amazon handle it
  • 49. Quick recap • Beanstalk - websites hostings • RDS - hosted relational DB • DynamoDB - document DB with cool features • SQS - simple queue service • S3 - infinite file storage • CloudFront - static and dynamic content delivery • Lambda - running code in response to event • Kinesis - operate with data streams as wizard • IAM - security in cloud • CloudFormation - automated cloud resources provisioning
  • 50. Thank you Checkout sources https://github.com/romanych/yals
  • 51. Further watching • https://www.youtube.com/watch?v=KmHGrONoif4 • https://www.youtube.com/watch?v=8u9wIC1xNt8 • https://www.youtube.com/watch?v=pBLdMCksM3A • https://www.youtube.com/watch?v=ZBxWZ9bgd44 • https://www.youtube.com/watch?v=TnfqJYPjD9I • https://www.youtube.com/watch?v=6R44BADNJA8