How to invoke AWS lambda while running EventGateway locally

301 views Asked by At

I am trying to invoke an AWS Lambda function from a locally running EventGateway (version: 0.9.1) instance. However, the subscription call is failing due to an "Event Type: http.request not found".

The lambda has been deployed independently using serverless framework, and the ARN has been injected in the registration call:

The lambda is just a hello world type of lambda listening for http request:

functions:
  hello-world:
    handler: bin/hello-serverless
    events:
    - http:
        path: /hello
        method: get

My function registration call looks like this:

curl --request POST \
  --url http://127.0.0.1:4001/v1/spaces/default/functions \
  --header 'content-type: application/json' \
  --data \
'{"functionId": "helloserverless", "type": "awslambda", "provider":{ "arn": "<lambda-arn>", "region": "ap-southeast-2", "accessKeyId": "<my-access-key>", "secretAccessKey": "<my-secret-key"}}'

Now, when I try to subscribe to an event:

  --url http://127.0.0.1:4001/v1/spaces/default/subscriptions \
  --header 'content-type: application/json' \
  --data '{"functionId": "helloserverless", "type": "sync", "path": "/hello", "method": "GET", "eventType": "http.request"}'

I get the following error:

{"errors":[{"message":"Event Type \"http.request\" not found."}]}

Any pointer to the right solution or working example is pretty much appreciated.

1

There are 1 answers

3
Cleriston On

If you want to call a function like an endpoint you need to have your application running. There is a plugin called serverless-offline to help you on this.

In case you want to call your function using serverless options, the command is called INVOKE. https://serverless.com/framework/docs/providers/aws/cli-reference/invoke-local/