aws-greengrass / aws-greengrass-docker

Example Dockerfile to run AWS IoT Greengrass in a Docker container
MIT No Attribution
42 stars 36 forks source link

Unable to launch nodejs lambdas (could not read process state file) #28

Closed jayfry1077 closed 2 years ago

jayfry1077 commented 2 years ago

Describe the bug Python lambdas work just fine. However whenever I'm using a nodejs lambda I get the following error.

`2022-06-23T02:51:03.346Z [INFO] (Copier) smarthub-greengrass-nodejs: Startup script exited. {exitCode=1, serviceInstance=1, serviceName=smarthub-greengrass-nodejs, currentState=STARTING}

2022-06-23T02:51:03.352Z [INFO] (pool-2-thread-16) smarthub-greengrass-nodejs: shell-runner-start. {scriptName=services.smarthub-greengrass-nodejs.lifecycle.shutdown.script, serviceInstance=1, serviceName=smarthub-greengrass-nodejs, currentState=BROKEN, command=["/greengrass/v2/packages/artifacts/aws.greengrass.LambdaLauncher/2.0.10/lambda-..."]}

2022-06-23T02:51:03.387Z [WARN] (Copier) smarthub-greengrass-nodejs: stderr. 2022/06/23 02:51:03 could not read process state file /greengrass/v2/work/smarthub-greengrass-nodejs/work/worker/P7QmJu--20Asa2ep8zLcZYL4TPTGKRFtbfWy1UYUcsM/state.json: open /greengrass/v2/work/smarthub-greengrass-nodejs/work/worker/P7QmJu--20Asa2ep8zLcZYL4TPTGKRFtbfWy1UYUcsM/state.json: no such file or directory. {scriptName=services.smarthub-greengrass-nodejs.lifecycle.shutdown.script, serviceInstance=1, serviceName=smarthub-greengrass-nodejs, currentState=BROKEN} `

To Reproduce Follow these steps to launch greengrass via docker (https://docs.aws.amazon.com/greengrass/v2/developerguide/run-greengrass-docker-automatic-provisioning.html)

Once you have the docker container running from the docker-compose file provision a nodejs12.x lambda component.

{ "lambdaExecutionParameters": { "EnvironmentVariables": {} }, "containerParams": { "memorySize": 16000, "mountROSysfs": false, "volumes": {}, "devices": {} }, "containerMode": "NoContainer", "timeoutInSeconds": 3, "maxInstancesCount": 100, "inputPayloadEncodingType": "json", "maxQueueSize": 1000, "pinned": false, "maxIdleTimeInSeconds": 60, "statusTimeoutInSeconds": 60, "pubsubTopics": { "0": { "topic": "cloud", "type": "IOT_CORE" } } }

Send a message to the topic

Get error.

Expected behavior lambda should run

Actual behavior lambda fails to run with error posted above.

Environment GREENGRASS_RELEASE_VERSION=2.5.3

jayfry1077 commented 2 years ago

So I noticed that here

https://docs.aws.amazon.com/greengrass/v2/developerguide/migrate-from-v1.html?icmpid=docs_gg_console

The AWS IoT Device SDK for JavaScript V2 doesn't currently support AWS IoT Greengrass V2. If your V1 applications use either of these features and the AWS IoT Greengrass Core SDK for Node.js, you can't run them on V2 yet.

It doesn't look like V2 Supports nodejs? Is that right?

That is super surprising if so, considering this seems to have come out 2 years ago now.

MikeDombo commented 2 years ago

Hello Jonathan,

NodeJS lambdas are absolutely supported. The most likely cause for your issue is a misconfiguration of cgroups.

What is the full log file showing, Specifically prior to 2022-06-23T02:51:03.346Z where it says exitCode 1?

Our Docker image does not include NodeJS. So did you install it yourself in your own Docker image?

jayfry1077 commented 2 years ago

Super happy to hear its supported. Here is a full log file of me getting the issue.

smarthub-greengrass-nodejs.log

Adding some photos

image

image

MikeDombo commented 2 years ago

So the error is cannot find executable nodejs12.x under any of the provided paths [/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /greengrass/v2/work/smarthub-greengrass-nodejs/work/worker/P7QmJu--20Asa2ep8zLcZYL4TPTGKRFtbfWy1UYUcsM/lambda /usr/bin /usr/local/bin].

You have to install NodeJS by building your own Docker container. The Greengrass Docker container does not come with NodeJS installed.

jayfry1077 commented 2 years ago

So the error is cannot find executable nodejs12.x under any of the provided paths [/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /greengrass/v2/work/smarthub-greengrass-nodejs/work/worker/P7QmJu--20Asa2ep8zLcZYL4TPTGKRFtbfWy1UYUcsM/lambda /usr/bin /usr/local/bin].

You have to install NodeJS by building your own Docker container. The Greengrass Docker container does not come with NodeJS installed.

Got it. Can you point me to some instructions for how to do this? I did try installing nodejs 12.x but still got the same error, so I think I'm missing a step.

MikeDombo commented 2 years ago

https://github.com/aws-greengrass/aws-greengrass-docker#step-1-build-the-aws-iot-greengrass-docker-image

After downloading this repository, you must edit the Dockerfile: https://github.com/aws-greengrass/aws-greengrass-docker/blob/main/Dockerfile#L45 to install NodeJS. Link the installed binary to be called "nodejs12.x": sudo ln <nodejs binary path> /usr/bin/nodejs12.x. Then continue with the building instructions.

jayfry1077 commented 2 years ago

https://github.com/aws-greengrass/aws-greengrass-docker#step-1-build-the-aws-iot-greengrass-docker-image

After downloading this repository, you must edit the Dockerfile: https://github.com/aws-greengrass/aws-greengrass-docker/blob/main/Dockerfile#L45 to install NodeJS. Link the installed binary to be called "nodejs12.x": sudo ln <nodejs binary path> /usr/bin/nodejs12.x. Then continue with the building instructions.

Okay I will try this out and let you know if i'm successful. Thanks for letting me know its possible, makes it easier to keep trying.

MikeDombo commented 2 years ago

Verify that your changes will work without needing to run Greengrass by trying to run /usr/bin/nodejs12.x -v in the container after building it. If you can run it and see the version output, then it will work when Greengrass tries to run Node.

Closing this issue as there is no problem with Greengrass or this repository.

jayfry1077 commented 2 years ago

Awesome, so adding this line resolves the issue. Thank you for your patience. I'm super happy to get going with greengrass.

curl -sL https://rpm.nodesource.com/setup_12.x | bash - && yum install -y nodejs && ln /usr/bin/node /usr/bin/nodejs12.x