amplify-education / serverless-domain-manager

Serverless plugin for managing custom domains with API Gateways.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No base path mapping is being set

mrw opened this issue · comments

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!

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.

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!

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.

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

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.

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": []
}

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?

@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": []
}

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?

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

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

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"}}

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?

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

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.

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

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.

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'

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

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.

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

+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

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

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

+1 I have the same issue.

Same thing is happening to me

+1 Encountering the same issue.

+1 same issue.

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

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.

+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