pedrocosta.eu
pedrocosta.eu/shameless-promotion
π Last year of MIEIC at FEUP and currently at UPM in Madrid π Technical Researcher Internship, Amazon Web Services, Summer 2018
π AWS Certified Solutions Architect - Associate π Software Developer Internship, Bitmaker, Summer 2017 π Member of NIAEFEUP and treasurer of ENEI 2018 π Member of the Board of Regents of FEUP
β How many servers do we need β How much memory would we need β How much network bandwith do we need β What type and how much processing power β What happens if my servers fails
β Who has access to the servers
The essence of the serverless trend is the absence of the server concept during software development
... but there are still servers of course
Serverless = FaaS + BaaS
π Independent, server-side, logical functions
π Stateless
π Ephemeral
π Event-triggered
π Scalable by default
π Fully managed by a Cloud vendor
event β π
If __________________________
then __________________________
A new CSV file is saved in the object storage
Β
Β Β Β Process it and save it in the DB
HTTP request: GET /posts
Β
Retrieve posts from DB and return a JSON
It's 2 AM
Β
Scrape weather forecast for next days
exports.handler = async (event, context) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!')
};
return response;
};
from chalice import Chalice, Response
import boto3
import os
dynamodb = boto3.resource('dynamodb')
sid = shortid.ShortId()
app = Chalice(app_name='url-shortener')
@app.route('/{code}', cors = True)
def get_original_url(code):
table = dynamodb.Table('url-shortener')
try:
response = table.get_item(
Key={
'code': code
}
)
item = response['Item']
except Exception as e:
return Response(
body='',
status_code=302,
headers={
'Location': os.environ['BASE_URL']
}
)
return Response(
body='',
status_code=302,
headers={
'Location': response['Item']['originalUrl']
}
)
Serverless URL shortner: pedrocosta.eu/sinf
π Instantiate AWS clients and database clients outside the scope of the handler to take advantage of container re-use
β° Schedule with CloudWatch Events for warmth
import sys
import logging
import rds_config
import pymysql
rds_host = "rds-instance"
db_name = rds_config.db_name
try:
conn = pymysql.connect(...)
except:
logger.error("ERROR: ..")
def handler(event, context):
with conn.cursor() as cur:
cold start
π¨βπ» Focus on business logic, not on infrastructure
π Scales with usage, auto-scaling
π° Never pay for idle, pay as you go
π Built-in High-Availability and Disaster Recovery
π§ No live debbuging
π Lacking local development & testing tools
β Service/Functions orchestration
βοΈ Cold starts
The Seattle Times uses AWS Lambda to resize images for viewing on different devices such as desktop computers, tablets, and smartphones.
Localytics processes billions of data points in real-time, and uses Lambda to process historical and live data stored in S3 or streamed from Kinesis.
Zillow uses Lambda and Kinesis to track a subset of mobile metrics in realtime. With Kinesis and Lambda, we were able to develop and deploy a cost effective solution in two weeks.
You can build serverless backends using AWS Lambda to handle web, mobile, Internet of Things (IoT), and 3rd party API requests.
Bustle runs a serverless backend for its Bustle iOS app and websites using AWS Lambda and Amazon API Gateway. Serverless architectures allow Bustle to never have to deal with infrastructure management, so every engineer can focus on building out new features and innovating.
By combining AWS Lambda with other AWS services, developers can build powerful web applications that automatically scale up and down and run in a highly available configuration across multiple data centers β with zero administrative effort required for scalability, back-ups or multi-data center redundancy.
me@pedrocosta.eu