Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No base path mapping is being set #57

Closed
mrw opened this issue Nov 16, 2017 · 31 comments · Fixed by #181
Closed

No base path mapping is being set #57

mrw opened this issue Nov 16, 2017 · 31 comments · Fixed by #181

Comments

@mrw
Copy link

mrw commented Nov 16, 2017

Hello,

First, thanks for your great work on this! It makes a custom domain much easier.

I'm having a problem I can't figure out. No matter what I put into basePath and stage, no path mapping are showing in the API Gateway custom domain configuration in AWS (and so all requests to the custom domain get 403s).

My configuration is:

custom:
  customDomain:
    domainName: sub.domain.com
    certificateName: domain.com
    basePath: ''
    stage: production
    createRoute53Record: true

The custom domain and route53 dns record properly get made. The only thing is the "base path mappings" are totally blank. I tried putting anything into basePath, such as 'test', but still nothing. If I manually create it in AWS then everything works properly but obviously I don't want to have to do that.

I'm sorry if I'm missing something obvious and this isn't urgent. But let me know how I can help debug. And thanks again for sharing this with the community!

@majones-amplify
Copy link
Contributor

Are you able to deploy endpoints normally without a base path? I haven't played much with the base path configuration but I'll take a look at it later when I get the chance.

@mrw
Copy link
Author

mrw commented Nov 16, 2017

Yep! Using the regular API gateway random URL works properly. Handler setup is here:

functions:
  redirect:
    handler: handler.redirect
    events:
      - http:
          path: /
          method: get
      - http:
          path: /{proxy+}
          method: get
      - schedule: rate(10 minutes)

Thanks again. As I said, it's not urgent because I can just set it manually for now. But let me know what else I can provide!

@majones-amplify
Copy link
Contributor

Hey @mrw, I'm unable to reproduce this error, the basePath seems to be configuring correctly when I create the domain. Could you provide the output of aws apigateway get-base-path-mappings --domain-name sub.domain.com after creating the domain name?

Two things that come to mind to check: The base path must be set when the domain is created, it can't be changed on deploy, and also your internal routing for the API must be aware of the base path as well. For example, setting the basePath in both the plugin configuration and the swagger file.

@amsross
Copy link

amsross commented Dec 13, 2017

I can second this issue. This is the custom domain name that was created by sls create_domain (it didn't exist before):
screen shot 2017-12-13 at 3 10 51 pm

custom:
  customDomain:
    domainName: "my.custom.domain.name"
    basePath: ""
    stage: ${opt:stage, 'dev'}
    createRoute53Record: true

edit: manually creating a path that maps to my service/api at a specific stage gets everything working properly

@amsross
Copy link

amsross commented Dec 13, 2017

To add to the above, if I set basePath: "something-else", then I can access my api at https://my.custom.domain.name/something-else.

I guess the confusing thing here is that if you manually create base path mapping, you can set it to be empty. If you set basePath: "", however, no base path mapping is created. My expectation is that both cases would have the same result.

@amsross
Copy link

amsross commented Dec 13, 2017

One more update and then I'll see if I can't find the source of the problem and hopefully open a PR...

If I change the config to have basePath: "(none)", then I get the expected base path mapping. You can see this both in the UI and the CLI response:

➔ aws apigateway get-base-path-mappings --domain-name my.custom.domain.name
{
    "items": [
        {
            "basePath": "(none)",
            "restApiId": "nuocg6brkg",
            "stage": "dev"
        }
    ]
}

When the config contained basePath: "" the CLI response was:

{
    "items": []
}

@majones-amplify
Copy link
Contributor

The plugin adds "(none") as the basePath value if it's unspecified or set to an empty string --> index.js L154

The basePath is added to the CloudFormation template on deploy, so aws apigateway get-base-path-mappings won't return anything until the lambda is actually deployed.

Given this config:

custom:
  customDomain:
    domainName: "my.custom.domain.name"
    basePath: ""
    stage: ${opt:stage, 'dev'}
    createRoute53Record: true

The base path is going to be set to none.. is that not what you're expecting?

@amsross
Copy link

amsross commented Dec 13, 2017

@majones-amplify So let me first say that I think I was too hasty when I said that setting basePath to "(none)" manually was a workable solution. I'm not able to reproduce that, so I probably missed something I did in between.

More to the point, though, when I deploy a Cloud Formation Template that contains basePath: "(none)" (regardless of whether that is manually entered or is defaulted to), the desired base path mapping is not created.

The steps I'm performing are:

  • sls create_domain
  • sls deploy -v
  • aws apigateway get-base-path-mappings --domain-name my.custom.domain.name

The result of the final command (and in the web UI) is consistently the same:

{
    "items": []
}

@majones-amplify
Copy link
Contributor

majones-amplify commented Dec 13, 2017

Ahh alright ok I see what you mean. Can you take a peek in the cloudformation-template-update-stack.json and post what's being created under the "pathmapping" section?

@amsross
Copy link

amsross commented Dec 13, 2017

I'm thinking now that I would classify this as either an AWS issue or user error.

After running the necessary commands so many times, it seems to me that if the resulting cloud formation template has no visible changes, then nothing is altered.

Consider the following steps:

  1. sls create_domain
  2. sls deploy
  3. delete the base path mapping (assuming there is one?)
  4. sls create_domain
  5. sls deploy

After following these steps, you can observe that:

  • there is no base path mapping defined
  • the following deploy stages were never executed:
CloudFormation - UPDATE_IN_PROGRESS - AWS::ApiGateway::BasePathMapping - pathmapping
CloudFormation - UPDATE_IN_PROGRESS - AWS::ApiGateway::BasePathMapping - pathmapping
CloudFormation - UPDATE_COMPLETE - AWS::ApiGateway::BasePathMapping - pathmapping
CloudFormation - DELETE_IN_PROGRESS - AWS::ApiGateway::BasePathMapping - pathmapping
CloudFormation - DELETE_COMPLETE - AWS::ApiGateway::BasePathMapping - pathmapping

@amsross
Copy link

amsross commented Dec 13, 2017

My takeaway is that if I'm using serverless to deploy, I should basically just stay out of the aws console.

@amsross
Copy link

amsross commented Dec 13, 2017

Also, the stack json looks just like what I would expect it to

"pathmapping":{"Type":"AWS::ApiGateway::BasePathMapping","DependsOn":["ApiGatewayDeploymentXXXXXXXXXX"],"Properties":{"BasePath":"(none)","DomainName":"my.api.com","RestApiId":{"Ref":"ApiGatewayRestApi"},"Stage":"dev"}}

@majones-amplify
Copy link
Contributor

I'm a little confused here. So the base path is being created but then you're trying to change it?

  1. delete the base path mapping (assuming there is one?)

I'm curious as to why/how you're doing this?

@majones-amplify
Copy link
Contributor

Also, in our experience it's best never to go behind CloudFormation's back.. as more often than not it won't realize that changes have been made. If you do need to change the base path, I'd recommend removing it with sls remove

@amsross
Copy link

amsross commented Dec 14, 2017

I was trying to get started with this plugin while also doing a considerable amount of manual configuration in the AWS console around Route53, API Gateway, and CloudFront<->S3 setup.

I can't point to a specific time or reason why I would have manually changed the API Gateway config in the console, but after trying to reproduce the issue in a number of different scenarios, I can only assume that that must have been what happened. That was the only way I could reproduce the issue.

@majones-amplify
Copy link
Contributor

Ah gotcha, well if you do find anything, let us know!

@thedreamspider
Copy link

I'm encountering this issue as well. Did a serverless create_domain, checked in the config and deployed. No basepath seems to be set in the config. Wondering if the deploy came too soon before the domain was fully configured. Can't seem to figure out how to fix, going to try and remove the config, clean it up and try again. Will reach out if still stuck.

@thedreamspider
Copy link

thedreamspider commented Dec 14, 2017

Yeah, a bit confused. I do serverless create_domain, I wait. I then deploy with serverless deploy and when I go into the console and look at the base path mappings, I don't see anything there. Using Serverless v 1.10. Not sure if that matters for this or not.

As far as I can tell, no basepath is getting added to my CF template during the serverless deploy. I have the following configuration, the names have been modified. The create_domain command worked fine. Like I said running with ServerLess 1.10.0, let me know if you can replicate or if anything in this setup jumps out at you.

Thanks.

=======

domains:
dev: 'foo.dev.fooservice.net'
test: 'foo.test.fooservice.net'
stage: 'foo-stage.fooservice.net'
prod: 'foo.fooservice.net'
customDomain:
domainName: ${self:custom.domains.${self:provider.stage}}
basePath: 'labor'
stage: ${self:provider.stage}
createRoute53Record: true
certificateName: '*.fooservice.net'

@superandrew213
Copy link

I'm seeing this issue too on v2.2.2. Have to manually add base path mapping.

customDomain:
    domainName: api.example.com
    stage: dev
    basePath: dev
    certificateName: '*.example.com'
    createRoute53Record: true
    endpointType: edge

@Rapol
Copy link

Rapol commented Mar 27, 2018

I just encountered this problem in v2.5.6, but it seems that its caused by the cloudformation not doing a deploy when it doesn't detect a change. After changing the basePath to a random string, I was able to see the change. I then changed it back to the variable configuration and the plugin set it to the correct base path.

@szebarjadi
Copy link

+1 on this issue; been encountering the same thing and no basePath configuration actually being applied.

@uscheller
Copy link

+1
In order to make it work I first have to

  1. set a base path mapping to "anything"
  2. deploy
  3. manually delete base path mapping on the web
  4. set base path mapping to ""
  5. deploy again

Only then it works

@Rapol
Copy link

Rapol commented Apr 11, 2018

The thing is that (if i remember correctly) the updated cloudformation (cloudformation-template-update-stack.json) has always the correct path mapping in the pathmapping resource but after deploying it doesnt reflect the change

@uscheller
Copy link

I tried several times, but could not find it anywhere in my update-stack.json

  • set basePath to "asdf"
  • sls deploy (will return: An error occurred: pathmapping - Only one base path mapping is allowed if the base path is empty)
  • When searching for "asdf" in update-stack.json it is not found

@cetauri
Copy link

cetauri commented Jun 19, 2018

+1 I have the same issue.

@cwardcode
Copy link

cwardcode commented Jul 10, 2018

Same thing is happening to me

@eyadmin
Copy link

eyadmin commented Aug 27, 2018

+1 Encountering the same issue.

@rachelrobynslater
Copy link

+1 same issue.

@benji
Copy link

benji commented Sep 9, 2018

+1 same here.
Just adding /v1 or anything as long as it's not empty is a simple workaround.

@captainsidd
Copy link
Contributor

I've been able to replicate this issue per doing the following:

sls create_domain
sls deploy
sls delete_domain
sls create_domain
sls deploy

Now, this only happens if there have been no code changes to the lambda being deployed.

@luisamador
Copy link

luisamador commented Jan 3, 2019

+1 Here,

A Base Path Mapping requires a Path, a Destination and a {Stage}.

Having to add the Base Path Mapping manually is a pain.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.