aws / aws-lambda-nodejs-runtime-interface-client

Apache License 2.0
180 stars 56 forks source link

Missing Runtime API Server configuration Error while deploying to docker #15

Closed vigneshtdev closed 11 months ago

vigneshtdev commented 3 years ago

Here's my docker file

FROM node:14.16.0-buster as build-image

  # Include global arg in this stage of the build

  # Install aws-lambda-cpp build dependencies
  RUN apt-get update && \
      apt-get install -y \
      g++ \
      make \
      cmake \
      unzip \
      libcurl4-openssl-dev

  RUN apt-get install -y libwoff1 \
                           libopus0 \
                           libwebp6 \
                           libwebpdemux2 \
                           libenchant1c2a \
                           libgudev-1.0-0 \
                           libsecret-1-0 \
                           libhyphen0 \
                           libgdk-pixbuf2.0-0 \
                           libegl1 \
                           libnotify4 \
                           libxslt1.1 \
                           libevent-2.1-6 \
                           libgles2 \
                           libgl1 \
                           libvpx5 \
                           # for chromium
                           libnss3 \
                           libxss1 \
                           libasound2 \
                           # for firefox
                           libdbus-glib-1-2 \
                           libxt6

  COPY app.js package.json /var/task/

  WORKDIR /var/task

  RUN npm install

  ENTRYPOINT ["/usr/local/bin/npx", "aws-lambda-ric"]
  CMD [ "app.handler" ]

app.js

"use strict";

  const { firefox } = require('playwright-firefox');

  const run = async () => {
      const browser = await firefox.launch({headless: true},);
      console.log(browser.version);
      const page = await browser.newPage();
      await page.goto('https://google.com/');
      //new S3().upload(await page.screenshot({ path: `example.png` }));
      await browser.close();
  }

  exports.handler = async (event, context) => {
      console.log(event);

      console.log(process.platform);
      await run();
      return "Success";
  };
carlzogh commented 3 years ago

Hey @vigneshtdev - I believe you are referring to local testing of the RIC not working and this would be because of a missing Runtime API Server when you're trying to run the function. For local testing scenarios, I'd recommend having a look at the AWS Documentation on Testing Lambda container images locally with the Runtime Interface Emulator.

Does the image run successfully when invoked within Lambda?

alexey2baranov commented 2 years ago

I wonder if someone can understand Runtime - Runtime API - Runtime API Emulator - RIC - etc combination AWS Lambda very easy to understand in promo but very hard to work :( Im trying to test very simple task last three days. Without AWS Lambda I can do this in a few minutes.

@carlzogh Maybe you can give me a peace of advice how to do this shortly?

umarta85 commented 2 years ago

@vigneshtdev @carlzogh @alexey2baranov anybody managed to solve this? Facing the same problem

alexey2baranov commented 2 years ago

@umarta85 no :(

uavdrip commented 2 years ago

@alexey2baranov Sad to hear that..

fcoury commented 2 years ago

Facing the same issue

aceberle commented 2 years ago

I just hit this too. Looking at the code, it appears that it is expected for you to define an environment variable called "AWS_LAMBDA_RUNTIME_API" for the npm library:

https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/c31c41ffe5f2f03ae9e8589b96f3b005e2bb8a4a/src/index.ts#L28-L30

These lines have been in the code for over 2 years, yet the examples in the README don't show this value being set in either the Dockerfile or specified in the example for running the image locally, so perhaps those instructions need an update.

This env var is mentioned on the following page for "Using AWS Lambda environment variables" as meaning "The host and port of the runtime API": https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html

I haven't quite figured out what the expectation is here, but will update if I figure something out...

jlarmstrongiv commented 2 years ago

These examples helped me a lot:

andclt commented 11 months ago

Hi, In our README we have a section about local testing.

There are multiple ways to test a Lambda container image locally. They are described in more detail here: https://docs.aws.amazon.com/lambda/latest/dg/images-test.html#images-test-alternative