Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda Node 16 container image error ( Missing Runtime API Server configuration )

I wanted to create node16 container image for aws lambda. I have following Dockerfile and index.js for lambda function. Building image (docker build -t lambda-hello-world .) works fine but when I invoke( docker run --rm -p 8080:8080 lambda-hello-world ) lambda function it returns error. Could someone please suggest?

2022-05-07T15:56:51.182Z        undefined       INFO    Executing 'index.handler' in function directory '/'
/node_modules/aws-lambda-ric/lib/index.js:42
        throw new Error("Missing Runtime API Server configuration.");
        ^

Error: Missing Runtime API Server configuration.
    at Object.run (/node_modules/aws-lambda-ric/lib/index.js:42:15)
    at Object.<anonymous> (/node_modules/aws-lambda-ric/bin/index.js:14:8)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47```
    enter code here

Dockerfile

FROM node:16-alpine

# Bundle app source
COPY . .

RUN npm install

EXPOSE 8080

ENTRYPOINT ["npx", "aws-lambda-ric"]

CMD ["index.handler"]


index.js

exports.handler = async (event, context) => {
    return `Hello World form node version ${process.version}`;
}
like image 968
Nagesh Avatar asked Dec 30 '25 06:12

Nagesh


1 Answers

According to this issue, whenever your Docker image is invoked, whether in Lambda or on your local machine, you need an entry script that will help your use the RIE proxy when necessary (e.g., on our local machine).

entry.sh in root project:

#!/bin/sh
# Check if the AWS_LAMBDA_RUNTIME_API is not set. This environment
# variable is set when the image is running on Lambda.
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
  # We know the image is being run off of Lambda, so we need to use the RIE
  # to start the function.
  exec /usr/bin/aws-lambda-rie ./node_modules/.bin/aws-lambda-ric $1
else
  # We know the image is being run on Lambda so we don't need to use the RIE.
  exec ./node_modules/.bin/aws-lambda-ric $1
fi   

Your Dockerfile:

FROM node:16-alpine

# Bundle app source
COPY . .

RUN npm install

EXPOSE 8080

# Downloads the Lambda Runtime Interface Emulator (RIE)
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie

RUN chmod +x /usr/bin/aws-lambda-rie
RUN chmod +x entry.sh

ENTRYPOINT ["entry.sh"]

CMD ["index.handler"]
like image 173
hoangdv Avatar answered Jan 01 '26 12:01

hoangdv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!