Search code examples
amazon-web-servicesserverless

Possible to have two post methods in the same app?


In my project i have the following function:

createSite:
    handler: CreateSite.main
    events:
      - http:
          path: sites
          method: post
          cors: true
          authorizer: aws_iam

but is it possible to have another post function directed at the same dynamodb but with different attributes etc. Because if I make another post method how do i specify which one to call?


Solution

  • Yes, you can have another post method directed at the same backend system with different attributes but you need to map that post method with a different http path. It will look something like this:

    createSite:
        handler: CreateSite.main
        events:
          - http:
              path: sites_v2
              method: post
              cors: true
              authorizer: aws_iam