Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to specify more than one method for an API Gateway -> Lambda mapping?

I am currently using Serveless Framework to create a new application and was wanting to map the same lambda function to multiple HTTP methods (say, GET and POST) in my API gateway and I have gotten stuck on how to do this.

Here is what Serverless Framework generated in awsm.json for my default resource/action endpoint for the apiGateway configuration:

"apiGateway": {
"deploy": false,
"cloudFormation": {
  "Type": "AWS",
  "Path": "notify/event",
  "Method": "POST",
  "AuthorizationType": "none",
  "ApiKeyRequired": false,
  "RequestTemplates": {},
  "RequestParameters": {},
  "Responses": {
    "400": {
      "statusCode": "400"
    },
    "default": {
      "statusCode": "200",
      "responseParameters": {},
      "responseModels": {},
      "responseTemplates": {
        "application/json": ""
      }
    }
  }
}

}

So this allows my endpoint to accept a POST request, but how do I change this file to have this lambda also accept GET requests? I have tried the following:

"cloudFormation": {
  ...
  "Method": [ "POST", "GET" ],
  ...
}

and

"cloudFormation": {
  ...
  "Method": "POST,GET",
  ...
}
like image 204
Dijital Munky Avatar asked Nov 10 '22 01:11

Dijital Munky


1 Answers

This is not currently supported (as of v1.4). It is a known issue that is being discussed (https://github.com/jaws-framework/JAWS/issues/295) and something similar is in the roadmap.

For now you will have to create a separate .awsm for each route & method

like image 120
DarylChymko Avatar answered Dec 20 '22 23:12

DarylChymko