AWS SDK to runtask on fargate throwing error on container override command

763 views Asked by At

I am developing an application using lambda and fargate AWS services. Base application is developed in NodeJS and docker image is created and push on AWS ECR to create ECS task.

Here, the fargate task is to be triggered using lambda function using AWS SDK API runtask. This runtask API have different params to be passed to run the fargate task. One of the params is container Overriders: command. Using this command, I am trying to invoke my node application which is running in task container.

Node application can only be invoked using command line (e.g., node app.js bulk-process [..args..]). So, when the container starts and when this given command is executed the application is throwing error as below.

internal/modules/cjs/loader.js:626
throw err;
^
Error: Cannot find module '/usr/src/app/node app.js bulk-process --filename=filename --clientId=1 --file_row_count=121 --emails="#####@gmail.com" --cluster=cluster --tagValue=tagValue'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
at Function.Module._load (internal/modules/cjs/loader.js:527:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

Note: 
a. node app.js bulk-process --filename=filename --clientId=1 --emails="####@gmail.com" --cluster=cluster --tagValue=tagValue is the command to invoke node application.
b. Also don't know why path '/usr/src/app' is prepended to the node command by container.

I believe the error is saying that node modules (packages) are missing in given path but when running the docker image separately on EC2 server to verify the Dockerfile executed commands then all the application files and npm packages are installed properly and even the application is executing properly when doing sh to docker image.

Please help as I am stuck in this issue for long time now and I am new to AWS ECS and docker services.

1

There are 1 answers

0
John B On

This might be because ECS task definition commands are split by commas. If you're using the ECS console, you will probably need to enter the command something like this:

 node,app.js,bulk-process,--filename=filename,...

If you're defining the task as JSON, then you just need to provide the command as a list. See also this answer to a related question for that case.

Incidentally, you can also test this locally (though without the ECS console's comma delimiters). Note the difference between these two commands:

$ docker run node:alpine echo hello world
  hello world

$ docker run node:alpine "echo hello world"
  node:internal/modules/cjs/loader:936
    throw err;
    ^

  Error: Cannot find module '/echo hello world'