serverless: HTTP Events, cannot add methods for root `/`endpoint

Serverless Framework Version:

1.0.0-alpha.2

Operating System:

OSX 10.11.6

Expected Behavior:

I would expect that I would be able to somehow deploy a method against the root / endpoint. Seems like validations block this from happening? Either that or I missed in the docs how to handle this.

Actual Behavior:
functions:
  render:
    handler: handler.render
    timeout: 6
    events:
      - http:
          path: /
          method: get
♪ sls deploy
Serverless: Zipping service...
Serverless: Removing old service versions...
Serverless: Uploading .zip file to S3...
Serverless: Updating Stack...

  Validation Error ---------------------------------------

     Template format error: Unresolved resource dependencies
     [ResourceApigEvent] in the Resources block of the template

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 41 (10 by maintainers)

Commits related to this issue

Most upvoted comments

path: /

on four get, put , delete, post routes gives me

ServerlessError: Circular dependency between resources: [
ApiGatewayMethodPost, ApiGatewayMethodDelete, ApiGatewayResource, 
ApiGatewayMethodGet, ApiGatewayDeployment1473211661367, ApiGatewayMethodPut
]

So based on this from cloud formation:

Resource’s path part only allow a-zA-Z0-9._- and curly braces at the beginning and the end.

It appears it may not be possible to attach to the root path with cloud formation

Ah, gotcha. Sorry I thought this was a workaround for that bug! Thanks for confirming it’s still open.

@nathanlenz @jatsrt could you open a quick pull request to see your changes? This would make it easier to look into it and see what we can introduce or what other potential issues could lurk there.

Thanks for looking into this btw!

That’s only possible though a custom domain mapping

@bbilger, I’m trying with serverless v1.0.3 with the syntax you described but get the following error:

$ curl https://<snip>.execute-api.us-west-2.amazonaws.com/dev/
{"message":"Missing Authentication Token"}

My serverless.yml:

service: limn
provider:
  name: aws
  runtime: python2.7
  stage: dev
  region: us-west-2
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "ec2:DescribeInstances"
        - "ec2:DescribeTags"
      Resource: "*"
functions:
  describe:
    handler: limn.describe
    events:
      - http: ANY {proxy+}

Am I missing something obvious?

I met the same error and finally fixed by add an extra http api gateway trigger:

  api:
    handler: handler.api
    events:
      - http:
          path: api/
          method: ANY
          cors: true
      - http:
          path: api/{proxy+}
          method: ANY
          cors: true

https://github.com/Jeff-Tian/serverless-space/commit/c86fc59c9c04cd1625c37b4cb7849e2cb0a2dbfa

@bbilger, I’m trying with serverless v1.0.3 with the syntax you described but get the following error:

$ curl https://<snip>.execute-api.us-west-2.amazonaws.com/dev/
{"message":"Missing Authentication Token"}

My serverless.yml:

service: limn
provider:
  name: aws
  runtime: python2.7
  stage: dev
  region: us-west-2
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "ec2:DescribeInstances"
        - "ec2:DescribeTags"
      Resource: "*"
functions:
  describe:
    handler: limn.describe
    events:
      - http: ANY {proxy+}

Am I missing something obvious?

Following these instructions certainly works: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html#how-to-custom-domains-mapping-console

The result if you use an empty base path and specify the environment you are working with is that you get:

https://–hostname–/–endpointname–

which does not have the environment as part of the path. So, the pull request stripping the endpoint name along with following the Custom Domain Mapping guide should make root paths a reality!

I got it working also (sorta). Using your changes. Plus, I had to set the PathPart of the unused resource to something in order to get it to take. It creates the unneeded resource, but actually attaches the lambda function to the / GET.

screenshot 2016-08-05 14 30 36

it’s not pretty but it works

var methodTemplateJson = JSON.parse(methodTemplate);

          if (path === "/") {
            methodTemplateJson.Properties.ResourceId = {
              "Fn::GetAtt": ["RestApiApigEvent", "RootResourceId"]
            }
          }

screen shot 2016-08-05 at 2 27 59 pm This would have to be dynamic

For cases where path === ‘/’

You would have to instead use:

"ResourceId" : { "Fn::GetAtt": ["RestApiApigEvent", "RootResourceId"] },