SlideShare a Scribd company logo
Building a serverless
company on AWS
Padraig O'Brien @Podgeypoos79
Luciano Mammino @loige
What we will cover
- Planet 9 Energy and the problem we are solving
- What is serverless?
- Our technology stack
- How our code is organised
- Path to production
- Gotchas and things we learned
- The Future
Who are we?
{
“name”: “Padraig”,
“job”: “engineer”,
“twitter”: “@Podgeypoos79”,
“extra”: [
“NodeSchool organiser”,
“LeanCoffee organiser”,
“Serverlesslab.com founder”
]
}
{
“name”: “Luciano”,
“job”: “engineer”,
“twitter”: “@loige”,
“Website”: “loige.co”
“side-projects”: [
“Node.js Design Patterns”,
“Fullstack Bulletin”,
“Serverlesslab.com founder”
]
}
Electricity suppliers:
Do you trust them?
Technology adoption by industry
Source: BCG, Boston Consulting Group, 2016
The numbers
● 17520 half hours in a year.
● 30 line items per half hour.
● 6 revisions of that data.
● ~ 3 million data points
(year × meter point)
See your bill down to
the half hour
Automated Energy Trading
Planet9Energy
● ESB funded startup (25 people)
● UK energy supplier.
● Focus on I & C customers.
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
Fully transparent
digital bill
What is
serverless?
- We are lazy
- We want as little manual
operational work
- We are full stack engineers with
T/E profiles
AS engineers
Building a serverless company on AWS lambda and Serverless framework
What is a Lambda?
- Function as a service (FAAS) in AWS
- Pay for invocation / processing time
- Virtually “infinite” auto-scaling
- Focus on business logic, not on servers
Daaa!
Lambdas as
micro-services
- Events are first-class
citizens
- Every lambda scales
independently
- Agility (develop features
quick and in an isolated
fashion)
Classic micro-services
concerns
- Granularity (how to
separate features? BDD?
Bounded Contexts?)
- Orchestration
(dependencies between
lambdas, service
discovery…)
Anatomy of a Lambda in Node.js
Some use cases
- REST over HTTP (API Gateway)
- SNS messages, react to a generic message
- Schedule/Cron
- DynamoDB, react to data changes
- S3, react to files changes
- IoT
HTTP REQUEST - API Call
POST /path/to/resource?foo=bar
{
“test”: “body”
}
Enter the
Serverless
Framework
Anatomy of
Serverless.yml
Serverless.yml (1/2)
Environment configuration
Anatomy of
Serverless.yml
Serverless.yml (2/2)
Defining functions and events
Tech stack
Initial stack
Iteration 1 Review
- Dynamodb - low ops overhead but only good for simple
read patterns and no good backup solution.
- Redshift - epic at aggregation but limited to 50 or so
connections.
- JAWS - 1.x was completely different so we had to
re-write (almost) everything
Iteration 2
Iteration 2 Review
● Cassandra replaced redshift.
● Postgres RDS is a lot more flexible than dynamoDB
● Ansible is very good for provisioning VMs.
● Rundeck was used for runbook automation for deploying
Lambdas.
Current iteration
Current iteration
● Defined custom VPC, Yay we are (more) secure.
● Dropped Cassandra.
● Dropped Rundeck, replaced it with parameter store and Jenkins.
● Started using Terraform.
Typical
enterprise
serverless
architecture
parameters
storage
KMS
How our services
are organised
● A function (not a service) is the natural
level of granularity!
● How to identify and structure services?
● How to connect services?
● How many repositories?
● How to deploy?
● Versioning?
● When and how to share code?
Iteration 1
● Proper service design using
methodologies like Domain
Driven Design
● Find the bounded context of
each service
● Integration through message
passing (events / APIs)
● Put everything related to a
service into one repo
Service 2 Service 3
Service 1
Iteration 2
● Terraform code: define infrastructure needed by the
service (VPC, database, keys, S3 buckets, etc.)
● Database code: Migrations and seeds (Using knex.js)
● Application code: A Serverless framework project
defining Lambdas and events needed by the service
Current code layout
The path to
production
Develop locally
● Develop locally on our laptops.
● PostgreSQL on docker.
● Plugins from Serverless to “mimic” API Gateway etc.
● Git commit all the things to branch.
● Pull request.
● Integrate to master.
● Jenkins takes care of everything else (more or less).
Our CI (Jenkins):
● Run tests
● Build the project
● Updates the infrastructure (Terraform)
● Updates the database (Knex)
● Deploy lambdas (Serverless framework)
● We have a stop-gate with manual approval before it goes to production
We we integrate to master
Building a serverless company on AWS lambda and Serverless framework
Things we
learned
Lots of code is repeated in every lambda
(event, context, callback) => {
// decrypt environment variables with KMS
// deserialize the content of the event
// validate input, authentication, authorization
// REAL BUSINESS LOGIC (process input, generate output)
// validate output
// serialize response
// handle errors
}
BOILERPLATE
CODE
BOILERPLATE
CODE
middy.js.org
The stylish Node.js middleware engine for AWS Lambda
const middy = require('middy')
const { middleware1, middleware2, middleware3 } = require('middy/middlewares')
const originalHandler = (event, context, callback) => {
/* your pure business logic */
}
const handler = middy(originalHandler)
handler
.use(middleware1())
.use(middleware2())
.use(middleware3())
module.exports = { handler }
● Business logic code is isolated:
Easier to understand and test
● Boilerplate code is written as
middlewares:
○ Reusable
○ Testable
○ Easier to keep it up to date
Large services
● serverless-plugin-split-stacks
○ migrates the RestApi resource to a
nested stack
● Template format error: Number
of resources, 214, is greater
than the maximum allowed, 200
API Gateway & Lambda size limits
● 128 K payload for async event
invocation
● 10 MB payload for response
● Don’t find these limits when
using sls webpack serve
API Gateways events
const handler = (event, context, callback) {
console.log(event.queryStringParameters.name)
// …
}
It will output "me"
https://myapi.me?name=me
{
"requestContext": { … },
"queryStringParameters": {
"name": "me"
},
"headers": { … }
}
API Gateways events
const handler = (event, context, callback) {
console.log(event.queryStringParameters.name)
// …
}
https://myapi.me
(no query string!)
{
"requestContext": { … },
"headers": { … }
}
(no queryStringParameters key!)
TypeError: Cannot read property 'name' of undefined
undefined
API Gateways events
const handler = (event, context, callback) {
if (event.queryStringParameters) {
console.log(event.queryStringParameters.name)
}
// or
console.log(event.queryStringParameters ?
event.queryStringParameters.name : undefined
}
Api Gateway proxy event normalizer middleware is coming to Middy!
MOAR
boilerplate!
API Gateways custom domain.
● Serverless does not provide
custom domain name mapping
● Has to be done in cloudformation
● There is a plugin.
Serverless-plugin-custom-domain
Serverless-domain-manager
Disk usage matters
● 50 MB if deploying directly.
● 250 if going from S3.
● We use Node.js, Webpack and tree
shaking help us (serverless webpack
plugin)
● 75GB for entire region, covers all
lambdas and versions of lambdas, you
might need a janitor lambda...
Node.js Event loop
● We use postgres and connection pooling
● Event loop will never become empty
● Use Middy! :)
const middy = require('middy')
const {doNotWaitForEmptyEventLoop} = require('middy/middlewares')
const handler = middy((event, context, cb) => {
// ...
}).use(doNotWaitForEmptyEventLoop())
S3 events: filename encoding
Space replaced with "+" & URL encodeds3://podge-toys
Podge's Unicorn.png
{
"Records": [{
"s3": {
"object": {
"key": "Podge%27s+Unicorn.png"
}
}
}]
}
const middy = require('middy')
const { s3KeyNormalizer } = require('middy/middlewares')
middy((event, context, cb) => {
console.log(event.Records[0].s3.object.key) // Podge's Unicorn
}).use(s3KeyNormalizer())
Building a serverless company on AWS lambda and Serverless framework
Serverless Aurora
Building a serverless company on AWS lambda
https://aws.amazon.com/rds/aurora/serverless/
Blue Green Deploys
Building a serverless company on AWS lambda
http://docs.aws.amazon.com/lambda/latest/dg/automating-updates-to-serverless-apps.html
A retrospective
2 years after...
● Learning how to do serverless
right took a while
(as learning any other new tech)
● We never received a call at 2AM!
● Our tech bill is extremely small
(apart for RDS!)
● We definitely don't regret the
choice :)
Recap
Building a serverless company on AWS lambda
We are hiring!
@loige @Podgeypoos79
Thank you

More Related Content

PDF
Building a Serverless company with Node.js, React and the Serverless Framewor...
ODP
Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platf...
PDF
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
PDF
Node.js Enterprise Middleware
PDF
Securing Microservices using Play and Akka HTTP
PDF
Lessons learned from writing over 300,000 lines of infrastructure code
PDF
Aws Lambda in Swift - NSLondon - 3rd December 2020
PDF
Containment without Containers: Running Windows Microservices on Nomad
Building a Serverless company with Node.js, React and the Serverless Framewor...
Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platf...
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Node.js Enterprise Middleware
Securing Microservices using Play and Akka HTTP
Lessons learned from writing over 300,000 lines of infrastructure code
Aws Lambda in Swift - NSLondon - 3rd December 2020
Containment without Containers: Running Windows Microservices on Nomad

What's hot (20)

PDF
Microservices and modularity with java
PPTX
MongoDB World 2019: Distributed Transactions: With Great Power Comes Great Re...
PDF
DevOps Days Tel Aviv - Serverless Architecture
PDF
NodeJS: the good parts? A skeptic’s view (devnexus2014)
PDF
React Development with the MERN Stack
PPTX
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
PDF
JavaDay Lviv: Serverless Archtiectures
PDF
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
PDF
Microservices in Scala: Play Framework
PDF
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
PDF
How to improve ELK log pipeline performance
PDF
Bulding a reactive game engine with Spring 5 & Couchbase
ODP
Asynchronous I/O in NodeJS - new standard or challenges?
PDF
Secrets in Kubernetes
PDF
Altitude SF 2017: Logging at the edge
PDF
Writing RESTful web services using Node.js
PDF
Long running aws lambda - Joel Schuweiler, Minneapolis
PDF
Infrastructure-as-code: bridging the gap between Devs and Ops
PPTX
Node.js Workshop - Sela SDP 2015
PDF
Pulsar Architectural Patterns for CI/CD Automation and Self-Service_Devin Bost
Microservices and modularity with java
MongoDB World 2019: Distributed Transactions: With Great Power Comes Great Re...
DevOps Days Tel Aviv - Serverless Architecture
NodeJS: the good parts? A skeptic’s view (devnexus2014)
React Development with the MERN Stack
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
JavaDay Lviv: Serverless Archtiectures
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
Microservices in Scala: Play Framework
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
How to improve ELK log pipeline performance
Bulding a reactive game engine with Spring 5 & Couchbase
Asynchronous I/O in NodeJS - new standard or challenges?
Secrets in Kubernetes
Altitude SF 2017: Logging at the edge
Writing RESTful web services using Node.js
Long running aws lambda - Joel Schuweiler, Minneapolis
Infrastructure-as-code: bridging the gap between Devs and Ops
Node.js Workshop - Sela SDP 2015
Pulsar Architectural Patterns for CI/CD Automation and Self-Service_Devin Bost
Ad

Similar to Building a serverless company on AWS lambda and Serverless framework (20)

PDF
Serverless Architectural Patterns & Best Practices
PPTX
AWS Webinar 23 - Getting Started with AWS - Understanding total cost of owner...
PDF
Middy.js - A powerful Node.js middleware framework for your lambdas​
PDF
SamzaSQL QCon'16 presentation
PDF
Apache Samza 1.0 - What's New, What's Next
PDF
Big Data Tools in AWS
PDF
Apache Druid Auto Scale-out/in for Streaming Data Ingestion on Kubernetes
PDF
Logisland "Event Mining at scale"
PDF
Node.js for enterprise - JS Conference
PDF
Altitude SF 2017: Nomad and next-gen application architectures
PDF
Top conf serverlezz
PDF
Lightbend Lagom: Microservices Just Right
PDF
Riga DevDays 2017 - Efficient AWS Lambda
PPTX
Machine learning at scale with aws sage maker
PDF
Phil Basford - machine learning at scale with aws sage maker
PDF
Tweaking performance on high-load projects
PDF
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
PDF
Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski
PDF
Incrementalism: An Industrial Strategy For Adopting Modern Automation
PPTX
Node Summit 2018 - Optimize your Lambda functions
Serverless Architectural Patterns & Best Practices
AWS Webinar 23 - Getting Started with AWS - Understanding total cost of owner...
Middy.js - A powerful Node.js middleware framework for your lambdas​
SamzaSQL QCon'16 presentation
Apache Samza 1.0 - What's New, What's Next
Big Data Tools in AWS
Apache Druid Auto Scale-out/in for Streaming Data Ingestion on Kubernetes
Logisland "Event Mining at scale"
Node.js for enterprise - JS Conference
Altitude SF 2017: Nomad and next-gen application architectures
Top conf serverlezz
Lightbend Lagom: Microservices Just Right
Riga DevDays 2017 - Efficient AWS Lambda
Machine learning at scale with aws sage maker
Phil Basford - machine learning at scale with aws sage maker
Tweaking performance on high-load projects
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski
Incrementalism: An Industrial Strategy For Adopting Modern Automation
Node Summit 2018 - Optimize your Lambda functions
Ad

More from Luciano Mammino (20)

PDF
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the ben...
PDF
Did you know JavaScript has iterators? DublinJS
PDF
What I learned by solving 50 Advent of Code challenges in Rust - RustNation U...
PDF
Building an invite-only microsite with Next.js & Airtable - ReactJS Milano
PDF
From Node.js to Design Patterns - BuildPiper
PDF
Let's build a 0-cost invite-only website with Next.js and Airtable!
PDF
Everything I know about S3 pre-signed URLs
PDF
Serverless for High Performance Computing
PDF
Serverless for High Performance Computing
PDF
JavaScript Iteration Protocols - Workshop NodeConf EU 2022
PDF
Building an invite-only microsite with Next.js & Airtable
PDF
Let's take the monolith to the cloud 🚀
PDF
A look inside the European Covid Green Certificate - Rust Dublin
PDF
Monoliths to the cloud!
PDF
The senior dev
PDF
Node.js: scalability tips - Azure Dev Community Vijayawada
PDF
A look inside the European Covid Green Certificate (Codemotion 2021)
PDF
AWS Observability Made Simple
PDF
Semplificare l'observability per progetti Serverless
PDF
Finding a lost song with Node.js and async iterators - NodeConf Remote 2021
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the ben...
Did you know JavaScript has iterators? DublinJS
What I learned by solving 50 Advent of Code challenges in Rust - RustNation U...
Building an invite-only microsite with Next.js & Airtable - ReactJS Milano
From Node.js to Design Patterns - BuildPiper
Let's build a 0-cost invite-only website with Next.js and Airtable!
Everything I know about S3 pre-signed URLs
Serverless for High Performance Computing
Serverless for High Performance Computing
JavaScript Iteration Protocols - Workshop NodeConf EU 2022
Building an invite-only microsite with Next.js & Airtable
Let's take the monolith to the cloud 🚀
A look inside the European Covid Green Certificate - Rust Dublin
Monoliths to the cloud!
The senior dev
Node.js: scalability tips - Azure Dev Community Vijayawada
A look inside the European Covid Green Certificate (Codemotion 2021)
AWS Observability Made Simple
Semplificare l'observability per progetti Serverless
Finding a lost song with Node.js and async iterators - NodeConf Remote 2021

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
A Presentation on Artificial Intelligence
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
Big Data Technologies - Introduction.pptx
NewMind AI Monthly Chronicles - July 2025
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
A Presentation on Artificial Intelligence
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction

Building a serverless company on AWS lambda and Serverless framework

  • 1. Building a serverless company on AWS Padraig O'Brien @Podgeypoos79 Luciano Mammino @loige
  • 2. What we will cover - Planet 9 Energy and the problem we are solving - What is serverless? - Our technology stack - How our code is organised - Path to production - Gotchas and things we learned - The Future
  • 4. { “name”: “Padraig”, “job”: “engineer”, “twitter”: “@Podgeypoos79”, “extra”: [ “NodeSchool organiser”, “LeanCoffee organiser”, “Serverlesslab.com founder” ] }
  • 5. { “name”: “Luciano”, “job”: “engineer”, “twitter”: “@loige”, “Website”: “loige.co” “side-projects”: [ “Node.js Design Patterns”, “Fullstack Bulletin”, “Serverlesslab.com founder” ] }
  • 7. Technology adoption by industry Source: BCG, Boston Consulting Group, 2016
  • 8. The numbers ● 17520 half hours in a year. ● 30 line items per half hour. ● 6 revisions of that data. ● ~ 3 million data points (year × meter point)
  • 9. See your bill down to the half hour
  • 11. Planet9Energy ● ESB funded startup (25 people) ● UK energy supplier. ● Focus on I & C customers.
  • 16. - We are lazy - We want as little manual operational work - We are full stack engineers with T/E profiles AS engineers
  • 18. What is a Lambda? - Function as a service (FAAS) in AWS - Pay for invocation / processing time - Virtually “infinite” auto-scaling - Focus on business logic, not on servers Daaa!
  • 19. Lambdas as micro-services - Events are first-class citizens - Every lambda scales independently - Agility (develop features quick and in an isolated fashion) Classic micro-services concerns - Granularity (how to separate features? BDD? Bounded Contexts?) - Orchestration (dependencies between lambdas, service discovery…)
  • 20. Anatomy of a Lambda in Node.js
  • 21. Some use cases - REST over HTTP (API Gateway) - SNS messages, react to a generic message - Schedule/Cron - DynamoDB, react to data changes - S3, react to files changes - IoT
  • 22. HTTP REQUEST - API Call POST /path/to/resource?foo=bar { “test”: “body” }
  • 28. Iteration 1 Review - Dynamodb - low ops overhead but only good for simple read patterns and no good backup solution. - Redshift - epic at aggregation but limited to 50 or so connections. - JAWS - 1.x was completely different so we had to re-write (almost) everything
  • 30. Iteration 2 Review ● Cassandra replaced redshift. ● Postgres RDS is a lot more flexible than dynamoDB ● Ansible is very good for provisioning VMs. ● Rundeck was used for runbook automation for deploying Lambdas.
  • 32. Current iteration ● Defined custom VPC, Yay we are (more) secure. ● Dropped Cassandra. ● Dropped Rundeck, replaced it with parameter store and Jenkins. ● Started using Terraform.
  • 34. How our services are organised
  • 35. ● A function (not a service) is the natural level of granularity! ● How to identify and structure services? ● How to connect services? ● How many repositories? ● How to deploy? ● Versioning? ● When and how to share code? Iteration 1
  • 36. ● Proper service design using methodologies like Domain Driven Design ● Find the bounded context of each service ● Integration through message passing (events / APIs) ● Put everything related to a service into one repo Service 2 Service 3 Service 1 Iteration 2
  • 37. ● Terraform code: define infrastructure needed by the service (VPC, database, keys, S3 buckets, etc.) ● Database code: Migrations and seeds (Using knex.js) ● Application code: A Serverless framework project defining Lambdas and events needed by the service Current code layout
  • 39. Develop locally ● Develop locally on our laptops. ● PostgreSQL on docker. ● Plugins from Serverless to “mimic” API Gateway etc. ● Git commit all the things to branch. ● Pull request. ● Integrate to master. ● Jenkins takes care of everything else (more or less).
  • 40. Our CI (Jenkins): ● Run tests ● Build the project ● Updates the infrastructure (Terraform) ● Updates the database (Knex) ● Deploy lambdas (Serverless framework) ● We have a stop-gate with manual approval before it goes to production We we integrate to master
  • 43. Lots of code is repeated in every lambda (event, context, callback) => { // decrypt environment variables with KMS // deserialize the content of the event // validate input, authentication, authorization // REAL BUSINESS LOGIC (process input, generate output) // validate output // serialize response // handle errors } BOILERPLATE CODE BOILERPLATE CODE
  • 44. middy.js.org The stylish Node.js middleware engine for AWS Lambda
  • 45. const middy = require('middy') const { middleware1, middleware2, middleware3 } = require('middy/middlewares') const originalHandler = (event, context, callback) => { /* your pure business logic */ } const handler = middy(originalHandler) handler .use(middleware1()) .use(middleware2()) .use(middleware3()) module.exports = { handler } ● Business logic code is isolated: Easier to understand and test ● Boilerplate code is written as middlewares: ○ Reusable ○ Testable ○ Easier to keep it up to date
  • 46. Large services ● serverless-plugin-split-stacks ○ migrates the RestApi resource to a nested stack ● Template format error: Number of resources, 214, is greater than the maximum allowed, 200
  • 47. API Gateway & Lambda size limits ● 128 K payload for async event invocation ● 10 MB payload for response ● Don’t find these limits when using sls webpack serve
  • 48. API Gateways events const handler = (event, context, callback) { console.log(event.queryStringParameters.name) // … } It will output "me" https://myapi.me?name=me { "requestContext": { … }, "queryStringParameters": { "name": "me" }, "headers": { … } }
  • 49. API Gateways events const handler = (event, context, callback) { console.log(event.queryStringParameters.name) // … } https://myapi.me (no query string!) { "requestContext": { … }, "headers": { … } } (no queryStringParameters key!) TypeError: Cannot read property 'name' of undefined undefined
  • 50. API Gateways events const handler = (event, context, callback) { if (event.queryStringParameters) { console.log(event.queryStringParameters.name) } // or console.log(event.queryStringParameters ? event.queryStringParameters.name : undefined } Api Gateway proxy event normalizer middleware is coming to Middy! MOAR boilerplate!
  • 51. API Gateways custom domain. ● Serverless does not provide custom domain name mapping ● Has to be done in cloudformation ● There is a plugin. Serverless-plugin-custom-domain Serverless-domain-manager
  • 52. Disk usage matters ● 50 MB if deploying directly. ● 250 if going from S3. ● We use Node.js, Webpack and tree shaking help us (serverless webpack plugin) ● 75GB for entire region, covers all lambdas and versions of lambdas, you might need a janitor lambda...
  • 53. Node.js Event loop ● We use postgres and connection pooling ● Event loop will never become empty ● Use Middy! :) const middy = require('middy') const {doNotWaitForEmptyEventLoop} = require('middy/middlewares') const handler = middy((event, context, cb) => { // ... }).use(doNotWaitForEmptyEventLoop())
  • 54. S3 events: filename encoding Space replaced with "+" & URL encodeds3://podge-toys Podge's Unicorn.png { "Records": [{ "s3": { "object": { "key": "Podge%27s+Unicorn.png" } } }] } const middy = require('middy') const { s3KeyNormalizer } = require('middy/middlewares') middy((event, context, cb) => { console.log(event.Records[0].s3.object.key) // Podge's Unicorn }).use(s3KeyNormalizer())
  • 56. Serverless Aurora Building a serverless company on AWS lambda https://aws.amazon.com/rds/aurora/serverless/
  • 57. Blue Green Deploys Building a serverless company on AWS lambda http://docs.aws.amazon.com/lambda/latest/dg/automating-updates-to-serverless-apps.html
  • 58. A retrospective 2 years after... ● Learning how to do serverless right took a while (as learning any other new tech) ● We never received a call at 2AM! ● Our tech bill is extremely small (apart for RDS!) ● We definitely don't regret the choice :)
  • 59. Recap Building a serverless company on AWS lambda We are hiring! @loige @Podgeypoos79 Thank you