fusebit / everynode

Run every Node.js version in AWS Lambda
MIT License
113 stars 5 forks source link

Documentation on working with other layers #6

Open cjlludwig opened 2 years ago

cjlludwig commented 2 years ago

While attempting to test this repo I encountered a couple of hiccups. First, I wasn't seeing the node version updated when checking inside my Lambda runtime. After some testing I realized that my runtime in my Lambda template was still set to "nodejs14.x" which was overriding any changes the Lambda made. This setting would be useful to highlight in the readMe.

Second, I'm having issues getting other layers to work when using in conjunction with this repo. For my use case it seems that using a node shebang declaration in my other layer fails. This layer works when using AWS node runtimes so it seems that the layer has changed other parts of the environment outside of node version. This likely just requires some tweaking on my end but it would be helpful to include some documentation on how running an everynode layer differs from the standard AWS node runtime.

#!/usr/bin/env node

/usr/bin/env: node: No such file or directory

Appreciate the work here. Very interesting feature!

tjanczuk commented 2 years ago

@cjlludwig When using the everynode Lambda layers, the standard Node.js runtimes from AWS are not used at all. You will notice that the instructions in the readme use the provided runtime as opposed to nodejs14.x:

aws lambda create-function --function-name hello17 \
  --layers $LAYER \
  --region us-west-1 \
  --zip-file fileb://function.zip \
  --handler function.handler \
  --runtime provided \
  --role {iam-role-arn}

The implication is that the Node.js executable normally provided by the AWS runtime is absent. Instead, the executable of the selected version of Node.js is placed in /opt/node/bin/node by the layer.

One thing you can try to make the composition with other layers work is to provide a PATH environment variable when creating your Lambda function that will include the /opt/node/bin directory -- I have not tested it though.

jlarmstrongiv commented 2 years ago

I have many scripts starting with #!/usr/bin/env node, so having node in the path by default would be nice

tjanczuk commented 2 years ago

@jlarmstrongiv How are you launching those scripts from your code? The custom runtime bundled in the layer sets the process.env.PATH to include the location of the node executable (https://github.com/fusebit/everynode/blob/main/src/bootstrap#L1-L3). As long as you launch the script in a way that passes process.env as the environment, your shebang should work