10

I am learning AWS, and was deep diving into API Gateway. But what is not clear to me is the difference between resource and method in API Gateway. I got the idea that methods are a part of resource, and they are client facing. Whereas resources, are a broader category, that involves more. Would appreciate if someone, could help me identify the difference between them in a more easier and intuitive way. I have gone through the docs, and a few youtube videos on my end.

muditrustagii
  • 743
  • 6
  • 17

2 Answers2

12
  • Method is a GET, POST, DELETE, etc.
  • Resource is actual path of the url

Lets take a simple example:

  • GET /pet/{petId}
  • DELETE /pet/{petId}
  • PUT /pet/{petId}
  • POST /pet/{petId}
  • GET /pet/getAll

we need 3 resources

  1. /pet
  2. /pet/{petId}
  3. /pet/getAll

When defining them in Api Gateway, second and third resource goes underneath first resource as they are prefexed with /pet

and methods under each resource.

  1. /pet > No methods underneath
  2. /pet/{petId} > GET, POST, PUT, DELETE methods
  3. /pet/getAll > GET method

Will look something like this:

enter image description here

Balu Vyamajala
  • 9,287
  • 1
  • 20
  • 42
  • When connecting AWS Lambda, the Lambda can deal with all methods and paths. If you are organising your code that way there's no need for more than one connection. You can use the `ANY` method, but tutorials always instruct to create a single resource. Is it possible to connect without creating any resources and just have the `ANY` method, or even omit methods and just have a direct connection for all requests to the Lambda without worrying about resources or methods specified? – NeilG Aug 17 '23 at 01:17
  • @NeilG Yes. you can do that by setting up a [Proxy](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html). This will route any paths to single lambda. – Balu Vyamajala Aug 17 '23 at 14:08
  • Thanks @Balu. So it seems you either use a proxy or an API Gateway. I was just trying to cut down on resources. I didn't want to just swap the API Gateway for a proxy. I'd rather use an API Gateway, as there are some features we might use in future and that seems to be the way AWS expect / have designed it to be used. – NeilG Aug 17 '23 at 23:31
3
  • Resource - the actual endpoints which we are creating excluding the default url
  • Method - HTTP methods (GET, PUT, POST, DELETE) inside the resource(Endpoints)

The hierarchy can be like

enter image description here

enter image description here

In this image black box are resource and red are methods

Hari Prasath
  • 246
  • 4
  • 6