Elastic Beanstalk: Log Task Customization on Amazon Linux 2 Platforms

Elastic Beanstalk: log task customization on Amazon Linux 2 platforms

Amazon has fixed this problem in version of the Elastic Beanstalk AL2 platforms released on 04-AUG-2020.

It has been fixed so that log task customization on AL2-based platforms now works the way it has always worked (i.e. on the prevision generation AL2018 platforms) and you can therefore follow the official documentation in order to make this happen.

Succesfully tested with platform "Docker running on 64bit Amazon Linux 2/3.1.0". If you (still) use "Docker running on 64bit Amazon Linux 2/3.0.x" then you must use the undocumented workaround described in Marcin's answer but you are probably better off by upgrading your platform version.

AWS Elastic Beanstalk Amazon Linux 2 - How to set a custom NodeCommand

you can use script option in your package.json. For example, if you start sample node.js application that EB provides, the file is:

package.json

{
"name": "Elastic-Beanstalk-Sample-App",
"version": "0.0.1",
"private": true,
"dependencies": {},
"scripts": {
"start": "node app.js"
}
}

Update

Docs have example how to use Procfile:

You can add a Procfile to your source bundle to specify the command that starts your application, as the following example shows. This feature replaces the legacy NodeCommand option in the aws:elasticbeanstalk:container:nodejs namespace.

web: node index.js

When you don't provide a Procfile, Elastic Beanstalk runs npm start if you provide a package.json file. If you don't provide that either, Elastic Beanstalk looks for the file app.js or server.js, in this order, and runs it.

Create systemd service in AWS Elastic Beanstalk on new Amazon Linux 2

systemd is not supported in Services. The only correct is sysvinit:

services:
sysvinit:
my_worker:
enabled: "true"
ensureRunning: "true"

But I don't think it will even work, as this is for Amazon Linux 1, not for Amazon Linux 2.

In Amazon Linux 2 you shouldn't be even using much of .ebextensions. AWS docs specifically write:

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.

Thus, you should consider using Procfile which does basically what you want to achieve:

Use a Procfile for long-running application processes that shouldn't exit. Elastic Beanstalk expects processes run from the Procfile to run continuously. Elastic Beanstalk monitors these processes and restarts any process that terminates. For short-running processes, use a Buildfile.

Alternative

Since you already have created a unit file /etc/systemd/system/my_worker.service for systemd, you can enable and start it yourself.

For this container_commands in .ebextensions can be used. For example:

container_commands:
10_enable_worker:
command: systemctl enable worker.service
20_start_worker:
command: systemctl start worker.service


Related Topics



Leave a reply



Submit