SlideShare a Scribd company logo
1 of 24
Download to read offline
Piotr Wasiak XI 2022
AWS Lambda
How to upload and load gems fast
Agenda
AWS loading code and gems
• Short intro to AWS Lambda
• How to load gems
• Problem with native extensions
• What's the load time?
• Deploying layers with no downtime?
About.me/Piotr.Wasiak
Ruby (and Rails) developer
• I work currently in SpaceOS.io prop-tech startup
• lambda is used in production to sync sequentially data with external systems
AWS Lambda
What is the fuss about
• Reduced complexity. There’s a
fi
xed operating system,
fi
xed software
language, and a
fi
xed version.
• No infrastructure to manage. AWS owns and manages the infrastructure.
You only pay for the time your code runs.
• Implicit scaling. AWS will handle scaling, no matter how much you use your
functions.
AWS Lambda
function sca
ff
old
• We can trigger lambda function by:
• Amazon Simple Queue Service
• HTTP Request
• Other Amazon events
What about loading libraries
3 ways
• pushing gem sources with code (naive way)
• pushing gems as a layer (pack the sources as zip)
• bundle install --deployment
• zip -FSr gem_layer.zip ./ruby/
• aws lambda publish-layer-version ....
• dockerize lambda image (but hmm it should be without additional setup)
Can we use bundler for loading gems?
bundler is by default shiped with ruby
• yes, we can use Gem
fi
le for loading
• on lambda function start:
require 'bundler'
Bundler.require(:default)
• bundler will raise on start if some gem version is missing or wrong
• but you can always require 'gem_name' wherever do you want it
First problem with layers
What if we require gems
with native extensions?
dependency from Savon
• inside Nokogiri there is also racc
• so there are external libs per
architecture/distributions
Nokogiri
Solution
• use aws-lambda docker to generate libs
• bundle con
fi
g set --local clean 'true'
• zip & push it as layer
Nokogiri depedency
Second problem with ruby
What is really the load time
of lambda function
Before adding native extentions
Loading time ~ 1050 ms
After adding native extentions
Loading time ~ 1550 ms
Our Gemfile right now
> bundle install --without test
(...)
Using activesupport 7.0.4
Using nokogiri 1.13.9 (arm64-darwin)
Using aws-sdk-core 3.166.0
Using faraday 2.6.0
Using graphql 2.0.15
Using savon 2.13.1
(...)
Using sentry-lambda 0.2.1
Using warning 1.3.0
Using zeitwerk 2.6.4
Bundle complete! 14 Gem
fi
le dependencies, 38 gems now installed.
Gems in the group 'test' were not installed.
Autoloader to load only required files
Zeitwerk Solution
• Convention to store required classes in proper folders
• load on usage and don't load twice (even if it has di
ff
erent require path)
After adding Zeitwerk (code autoloader)
Loading time ~ 1350 ms
Load gems only if needed
Solution
• skip requiring Nokogiri and GraphQL in Gem
fi
le (on boot)
• manual require in service
fi
les
With autoloader skipping Savon, GraphQL
Loading time ~ 820 ms Faster than 6 month ago :O
Third problem with layers
How to ensure no downtime
with releasing new libs and code
How to release new layer with code
Solutions
1. Combine together previous layer with new one and ship combined layer
fi
rst
• can be incompatible with API changes (test it
fi
rst)
• no downtime at all
• have to use bundler (require does not know which gem version should be loaded)
2. Push new layer
and switch it just before pushing the new function code
• there is no way to push the code and switch to new layer in one transaction
• very small downtime (already started functions will be
fi
ne during that change)
3. Use lambda function versions and just switch event trigger to new code version with layer
Take aways
• Lambda loading time
for ruby is more 0,5 sec
• Loading gems with layers
provides some challenges
• If you have complex app
then go with lambda docker
Sources
• https://stackify.com/aws-lambda-with-ruby-getting-started-guide
• https://docs.aws.amazon.com/lambda/latest/dg/lambda-ruby.html
• github.com aws-lambda developer-guide/sample-ruby
• https://github.com/fxn/zeitwerk#awards
• https://bundler.io
Thanks for listening

More Related Content

Similar to AWS Lambda How to upload and load gems fast

Matt Chung (Independent) - Serverless application with AWS Lambda
Matt Chung (Independent) - Serverless application with AWS Lambda Matt Chung (Independent) - Serverless application with AWS Lambda
Matt Chung (Independent) - Serverless application with AWS Lambda Outlyer
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
 
aws lambda & api gateway
aws lambda & api gatewayaws lambda & api gateway
aws lambda & api gatewayfumihiko hata
 
Java to scala
Java to scalaJava to scala
Java to scalaGiltTech
 
Dockerize the World
Dockerize the WorldDockerize the World
Dockerize the Worlddamovsky
 
Fast Deployments to Multiple Golang Lambda Functions
Fast Deployments to Multiple Golang Lambda FunctionsFast Deployments to Multiple Golang Lambda Functions
Fast Deployments to Multiple Golang Lambda FunctionsKp Krishnamoorthy
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Hosting a Rails App
Hosting a Rails AppHosting a Rails App
Hosting a Rails AppJosh Schramm
 
Serverless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloadsServerless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloadsTensult
 
Lightweight Virtualization Docker in Practice
Lightweight Virtualization Docker in PracticeLightweight Virtualization Docker in Practice
Lightweight Virtualization Docker in PracticeDocker, Inc.
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Railselliando dias
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLMario-Leander Reimer
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureQAware GmbH
 
Scala Native: Ahead of Time
Scala Native: Ahead of TimeScala Native: Ahead of Time
Scala Native: Ahead of TimeNadav Wiener
 
MariaDB on Docker
MariaDB on DockerMariaDB on Docker
MariaDB on DockerMariaDB plc
 
Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Ryan Cuprak
 
Docker for the Rubyist
Docker for the RubyistDocker for the Rubyist
Docker for the RubyistBrian DeHamer
 
Cloud Foundry 百日行 振り返り
Cloud Foundry 百日行 振り返りCloud Foundry 百日行 振り返り
Cloud Foundry 百日行 振り返りnota-ja
 

Similar to AWS Lambda How to upload and load gems fast (20)

Matt Chung (Independent) - Serverless application with AWS Lambda
Matt Chung (Independent) - Serverless application with AWS Lambda Matt Chung (Independent) - Serverless application with AWS Lambda
Matt Chung (Independent) - Serverless application with AWS Lambda
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
aws lambda & api gateway
aws lambda & api gatewayaws lambda & api gateway
aws lambda & api gateway
 
Java to scala
Java to scalaJava to scala
Java to scala
 
Symfony aws
Symfony awsSymfony aws
Symfony aws
 
Dockerize the World
Dockerize the WorldDockerize the World
Dockerize the World
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Fast Deployments to Multiple Golang Lambda Functions
Fast Deployments to Multiple Golang Lambda FunctionsFast Deployments to Multiple Golang Lambda Functions
Fast Deployments to Multiple Golang Lambda Functions
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Hosting a Rails App
Hosting a Rails AppHosting a Rails App
Hosting a Rails App
 
Serverless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloadsServerless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloads
 
Lightweight Virtualization Docker in Practice
Lightweight Virtualization Docker in PracticeLightweight Virtualization Docker in Practice
Lightweight Virtualization Docker in Practice
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Rails
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
 
Scala Native: Ahead of Time
Scala Native: Ahead of TimeScala Native: Ahead of Time
Scala Native: Ahead of Time
 
MariaDB on Docker
MariaDB on DockerMariaDB on Docker
MariaDB on Docker
 
Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]
 
Docker for the Rubyist
Docker for the RubyistDocker for the Rubyist
Docker for the Rubyist
 
Cloud Foundry 百日行 振り返り
Cloud Foundry 百日行 振り返りCloud Foundry 百日行 振り返り
Cloud Foundry 百日行 振り返り
 

Recently uploaded

The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...Roi Lipman
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Lovely Professional University
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxCHAIRMAN M
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsMathias Magdowski
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.MdManikurRahman
 
Online book store management system project.pdf
Online book store management system project.pdfOnline book store management system project.pdf
Online book store management system project.pdfKamal Acharya
 
Quiz application system project report..pdf
Quiz application system project report..pdfQuiz application system project report..pdf
Quiz application system project report..pdfKamal Acharya
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5T.D. Shashikala
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGKOUSTAV SARKAR
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...archanaece3
 
How to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdfHow to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdftawat puangthong
 
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...ShivamTiwari995432
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxKarpagam Institute of Teechnology
 
Multivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptxMultivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptxalijaker017
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfJNTUA
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdfKamal Acharya
 
Lesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxLesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxmichaelprrior
 
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Prakhyath Rai
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfJNTUA
 

Recently uploaded (20)

The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
Online book store management system project.pdf
Online book store management system project.pdfOnline book store management system project.pdf
Online book store management system project.pdf
 
Quiz application system project report..pdf
Quiz application system project report..pdfQuiz application system project report..pdf
Quiz application system project report..pdf
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
How to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdfHow to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdf
 
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Multivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptxMultivibrator and its types defination and usges.pptx
Multivibrator and its types defination and usges.pptx
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdf
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdf
 
Lesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxLesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsx
 
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 

AWS Lambda How to upload and load gems fast

  • 1. Piotr Wasiak XI 2022 AWS Lambda How to upload and load gems fast
  • 2. Agenda AWS loading code and gems • Short intro to AWS Lambda • How to load gems • Problem with native extensions • What's the load time? • Deploying layers with no downtime?
  • 3. About.me/Piotr.Wasiak Ruby (and Rails) developer • I work currently in SpaceOS.io prop-tech startup • lambda is used in production to sync sequentially data with external systems
  • 4. AWS Lambda What is the fuss about • Reduced complexity. There’s a fi xed operating system, fi xed software language, and a fi xed version. • No infrastructure to manage. AWS owns and manages the infrastructure. You only pay for the time your code runs. • Implicit scaling. AWS will handle scaling, no matter how much you use your functions.
  • 5. AWS Lambda function sca ff old • We can trigger lambda function by: • Amazon Simple Queue Service • HTTP Request • Other Amazon events
  • 6. What about loading libraries 3 ways • pushing gem sources with code (naive way) • pushing gems as a layer (pack the sources as zip) • bundle install --deployment • zip -FSr gem_layer.zip ./ruby/ • aws lambda publish-layer-version .... • dockerize lambda image (but hmm it should be without additional setup)
  • 7. Can we use bundler for loading gems? bundler is by default shiped with ruby • yes, we can use Gem fi le for loading • on lambda function start: require 'bundler' Bundler.require(:default) • bundler will raise on start if some gem version is missing or wrong • but you can always require 'gem_name' wherever do you want it
  • 8.
  • 9. First problem with layers What if we require gems with native extensions?
  • 10. dependency from Savon • inside Nokogiri there is also racc • so there are external libs per architecture/distributions Nokogiri
  • 11. Solution • use aws-lambda docker to generate libs • bundle con fi g set --local clean 'true' • zip & push it as layer Nokogiri depedency
  • 12. Second problem with ruby What is really the load time of lambda function
  • 13. Before adding native extentions Loading time ~ 1050 ms
  • 14. After adding native extentions Loading time ~ 1550 ms
  • 15. Our Gemfile right now > bundle install --without test (...) Using activesupport 7.0.4 Using nokogiri 1.13.9 (arm64-darwin) Using aws-sdk-core 3.166.0 Using faraday 2.6.0 Using graphql 2.0.15 Using savon 2.13.1 (...) Using sentry-lambda 0.2.1 Using warning 1.3.0 Using zeitwerk 2.6.4 Bundle complete! 14 Gem fi le dependencies, 38 gems now installed. Gems in the group 'test' were not installed.
  • 16. Autoloader to load only required files Zeitwerk Solution • Convention to store required classes in proper folders • load on usage and don't load twice (even if it has di ff erent require path)
  • 17. After adding Zeitwerk (code autoloader) Loading time ~ 1350 ms
  • 18. Load gems only if needed Solution • skip requiring Nokogiri and GraphQL in Gem fi le (on boot) • manual require in service fi les
  • 19. With autoloader skipping Savon, GraphQL Loading time ~ 820 ms Faster than 6 month ago :O
  • 20. Third problem with layers How to ensure no downtime with releasing new libs and code
  • 21. How to release new layer with code Solutions 1. Combine together previous layer with new one and ship combined layer fi rst • can be incompatible with API changes (test it fi rst) • no downtime at all • have to use bundler (require does not know which gem version should be loaded) 2. Push new layer and switch it just before pushing the new function code • there is no way to push the code and switch to new layer in one transaction • very small downtime (already started functions will be fi ne during that change) 3. Use lambda function versions and just switch event trigger to new code version with layer
  • 22. Take aways • Lambda loading time for ruby is more 0,5 sec • Loading gems with layers provides some challenges • If you have complex app then go with lambda docker
  • 23. Sources • https://stackify.com/aws-lambda-with-ruby-getting-started-guide • https://docs.aws.amazon.com/lambda/latest/dg/lambda-ruby.html • github.com aws-lambda developer-guide/sample-ruby • https://github.com/fxn/zeitwerk#awards • https://bundler.io