The answer to Can I configure Linux swap space on AWS Elastic Beanstalk? (from 2016) shows how to configure Linux swap space for an AWS Elastic Beanstalk environment using .ebextensions
configuration files.
However, the AWS docs Customizing software on Linux servers has this note for the newer Amazon Linux 2 platforms:
On Amazon Linux 2 platforms, instead of providing files and commands in .ebextensions configuration files, we highly recommend that you use Buildfile. Procfile, and platform hooks whenever possible to configure and run custom code on your environment instances during instance provisioning.
How do I configure swap space using this more modern configuration approach?
Buildfile
and Procfile
are not suited for that. They serve different purposes - running short and long running commands.
I would use the platform hooks for that. Specifically, prebuild
:
Files here run after the Elastic Beanstalk platform engine downloads and extracts the application source bundle, and before it sets up and configures the application and web server.
The rationale is that it's better to create swap now, before the application starts configuring. If the swap creation operation fails, you get notified fast, rather then after you setup your application.
From the SO link, you could put 01_add-swap-space.sh
into .platform/hooks/prebuild/
folder. Please make sure that 01_add-swap-space.sh
is executable (chmod +x
) before you package your appliaction into a zip.