1

Migrating your Elastic Beanstalk Linux application to Amazon Linux 2 - AWS Elastic Beanstalk

According to the docs, the aws:elasticbeanstalk:container:nodejs namespace is no longer supported and the new way to set NodeCommand is to "Use a Procfile or the scripts keyword in a package.json file to specify the start script.".

I've never dealt with Procfiles and the part "the scripts keyword in a package.json file" isn't very clear, are they going to execute the scripts in order, until something sticks or what?

Did anyone figure out how exactly to set a custom NodeCommand in Amazon Linux 2?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Buzzkill
  • 68
  • 2
  • 8
  • For anyone using Amazon's sample node app as a reference, it still contains references to the out-dated documentation, which you should ignore. – eppineda Mar 25 '21 at 01:43

1 Answers1

3

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.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Yes, but is there a way to tell it to use something different than `npm start`? Like I mentioned, in the original Amazon Linux, you could use `aws:elasticbeanstalk:container:nodejs` namespace and set `NodeCommand` or change it from the config dashboard (Configuration -> Software -> Node command). – Buzzkill Sep 26 '20 at 05:26
  • @Buzzkill Yo can use `Procfile`, if yo don't want `package.json`. I updated an answer – Marcin Sep 26 '20 at 06:18