Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Unable to run lambda via lambci #60

Closed
zacbarton opened this issue Jun 17, 2021 · 3 comments · Fixed by #62
Closed

Unable to run lambda via lambci #60

zacbarton opened this issue Jun 17, 2021 · 3 comments · Fixed by #62
Labels
bug Something isn't working

Comments

@zacbarton
Copy link

I saw in #26 some work was done to allow local development but I cant seem to get this working.

The error I'm getting is;

 init.lua:286 [aws-lambda] /usr/local/share/lua/5.1/kong/plugins/aws-lambda/v4.lua:118: attempt to concatenate local 'region' (a nil value), client: 192.168.128.1, server: kong, request: "POST /lambda1 HTTP/1.1", host: "localhost:8000"

I'm testing with this kong.yml file (partial)

routes:
- name: lambda1
  paths: [ "/lambda1" ]

plugins:
- route: lambda1
  name: aws-lambda
  config:
    port: 9001
    host: host.docker.internal
    aws_key: abc
    aws_secret: abc
    function_name: order

And have lambci running locally and can invoke my local lambda like;

curl --location --request POST 'http://localhost:9001/2015-03-31/functions/order/invocations' \
--header 'Content-Type: application/json' \
--data-raw '{
    "path": "/api/order/13984e49-f798-40a3-a015-b798cdf9d157",
    "httpMethod": "GET"
}'

Another thing to note is that the local lambda service only runs on http and not https of which I dont see a setting to enable/force such a scheme.

@gszr
Copy link
Member

gszr commented Jun 23, 2021

Hey @zacbarton,

Thanks for opening this issue.

Could you provide us with more info on how to test against lambci? I can see in the code why this is occurring, but want to properly test with lambci.

Thanks!

@gszr gszr added the bug Something isn't working label Jun 23, 2021
@zacbarton
Copy link
Author

Hopefully this will help.

docker-compose.yml

version: "3.7"

services:
  kong:
    image: kong:latest
    volumes:
      - ./kong.yml:/usr/local/kong/declarative/kong.yml
    environment:
      - KONG_DATABASE=off
      - KONG_DECLARATIVE_CONFIG=/usr/local/kong/declarative/kong.yml
      - KONG_PROXY_ACCESS_LOG=/dev/stdout
      - KONG_ADMIN_ACCESS_LOG=/dev/stdout
      - KONG_PROXY_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl
    ports:
      - "8000:8000"
      - "8443:8443"
      - "127.0.0.1:8001:8001"
      - "127.0.0.1:8444:8444"

  simple:
    image: lambci/lambda:nodejs12.x
    container_name: simple
    command: index.handler
    volumes:
      - .:/var/task:ro,delegated
    ports:
      - '9001:9001'
    environment:
      - DOCKER_LAMBDA_WATCH=1
      - DOCKER_LAMBDA_STAY_OPEN=1

kong.yml

_format_version: "2.1"

routes:
- name: lambda
  paths: [ "/lambda" ]

plugins:
- route: lambda
  name: aws-lambda
  config:
    port: 9001
    host: host.docker.internal # note im suppling host and not region as per docs
    aws_key: abc
    aws_secret: abc
    function_name: simple

index.js

module.exports.handler = (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: `Hello, the current time is ${new Date().toTimeString()}.`,
    }),
  };

  callback(null, response);
};

Direct request to lambci;

curl --location --request POST 'http://localhost:9001/2015-03-31/functions/simple/invocations' \
--header 'Content-Type: application/json' \
--data-raw '{}'
# {
#    "statusCode": 200,
#    "body": "{\"message\":\"Hello, the current time is 03:17:48 GMT+0000 (Coordinated Universal Time).\"}"
# }

Request via kong;

curl --location --request POST 'http://localhost:8000/lambda' \
--header 'Content-Type: application/json' \
--data-raw '{}'
# kong_1  | 2021/06/24 03:19:50 [error] 28#0: *2259 [kong] init.lua:286 [aws-lambda] /usr/local/share/lua/5.1/kong/plugins/aws-lambda/v4.lua:118: attempt to concatenate local 'region' (a nil value), client: 192.168.208.1, server: kong, request: "POST /lambda HTTP/1.1", host: "localhost:8000"
# kong_1  | 192.168.208.1 - - [24/Jun/2021:03:19:50 +0000] "POST /lambda HTTP/1.1" 500 42 "-" "curl/7.64.1"

Note that lambci only runs via http and not https.

@Tieske
Copy link
Member

Tieske commented Jun 24, 2021

Not sure about this.

The plan was to refactor this plugin, so it can us the new lua-resty-http 0.16 version (waiting for Kong to update that depedency) and then to rip out the AWS specific stuff and replace it with the generic AWS SDK. That should make this plugin far better maintianable, but might come at the cost of not supporting lambci.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants