How to Create a AWS Lambda Layer of Your Gemfile / Ruby Gem Dependencies

10-Dec-2020 2112
If you use AWS SAM to build and deploy your serverless Ruby functions, it'll take care of building your dependencies on a function by function basis and package them up for deployment. Great!But if you don't want to use SAM, using gems with native dependencies (e.g. Nokogiri) is a nightmare! If you prefer to travel light (or, maybe, you like coding throwaway functions in the AWS console), you can instead build your dependencies into a Lambda Layer and then use that layer across whatever Lambda functions you like without worrying about dependencies again.But how? After an hour of trial and error plus a few tips from this neat article (though that one still used SAM), I figured out the magic spell required to locally build Ruby gems and their dependencies in a local Amazon Linux container and turn them into a layer.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle