0

How can I attach the PUT and DELETE method on an API Gateway resource using AWS_PROXY integration?

The PUT method is getting overridden by the DELETE method in lambda triggers.

Is there a way to have both the methods? enter image description here

/subs
OPTIONS
PUT
DELETE

2 Answers 2

1

Following example in terraform registry documentation, define multiple aws_api_gateway_method resources for the same aws_api_gateway_resource resource:

resource "aws_api_gateway_rest_api" "api" {
  name        = "MyAPI"
  description = "This is my API"
}

resource "aws_api_gateway_resource" "subs" {
  rest_api_id = aws_api_gateway_rest_api.api.id
  parent_id   = aws_api_gateway_rest_api.api.root_resource_id
  path_part   = "subs"
}

resource "aws_api_gateway_method" "methods" {
  for_each      = toset(["OPTIONS", "PUT", "DELETE"])

  rest_api_id   = aws_api_gateway_rest_api.api.id
  resource_id   = aws_api_gateway_resource.subs.id
  http_method   = each.key
  authorization = "CUSTOM"
}

Sign up to request clarification or add additional context in comments.

2 Comments

The original question was using a Proxy - this does not actually set up a proxy, but individual methods for each one. its a subtle difference, but there are advantages to using a proxy - the lack of need for each path_part to be defined for instance (as the path is included in the event sent to the lambda attached to the proxy)
I undertood how to implement multiple methods. If the original question is only about creating a proxy and and api gateway, it is a duplicate of this stackoverflow.com/a/45105470/14105382, isn't it?
1

As you are using a proxy method, it sends a ton of information to the lambda. Change the proxy method to "ANY" and then in your lambda, check against the event.HttpMethod - and only process based on the ones you want to allow, returning an error message otherwise.

If you dont want to do this, then you need to stop using a proxy method and instead set up an actual resource + each method. THey can connect to the same lambda or different ones, but you can't use proxy to define just two types - its 1 or all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.