Reputation: 171
I'm trying to build an API with AWS API Gateway and AWS Lambda that has one resource, but multiple actions that can be taken on that resource via POST, similar to how Google has built its Natural Language API, e.g:
POST https://language.googleapis.com/v1/documents:analyzeEntities
POST https://language.googleapis.com/v1/documents:analyzeEntitySentiment
POST https://language.googleapis.com/v1/documents:analyzeSentiment
...
I want to link each POST method to a different Lambda function. I've looked through the developer documentation but haven't found anything that addresses this type of use case. Does anyone know if AWS supports this and how to go about implementing it?
Upvotes: 1
Views: 5400
Reputation: 3550
It depends on how important it is for you to follow the scheme you describe in your question. The key problem is that API Gateway doesn't let you use a colon :
in your resource name.
Consider making your API scheme more RESTful.
Perhaps instead of performing an analyzeEntities
action on documents
, consider that your requests to analyze the documents are themselves resources which can be created...
e.g:
POST /documents/analyzeRequest[s]
(where body describes the type of request)
or
POST /documents/analyzeEntitiesRequest[s]
These would allow you to add GETs later on to list previous/current requests
So, specifying a :
in your resource path results in the error:
Resource's path part only allow a-zA-Z0-9._- and curly braces at the beginning and the end.
The workaround to this is to create a new resource and check the Configure as proxy resource
box.
Creating a proxy resource allows you to defer routing decision making to a lambda function, for any path which matches the rule.
e.g. ANY /{proxy+}
would match all requests.
Note: If you then added a separate resource GET /foo
, your proxy resource would not handle GET /foo
, since a more specific rule now exists.
So, with a proxy resource set up, you would need to write a lambda that invokes the appropriate lambda function, based on your routing rules.
Upvotes: 1