question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@aws-cdk/aws-apigatewayv2] Httpapi not deploying when new stack created when using custom domain

See original GitHub issue

Httpapi not deploying when new stack created when using custom domain, and not accepting base path of ‘/’

I tried to follow the description of how to setup a base path mapping here:

https://docs.aws.amazon.com/cdk/api/latest/docs/aws-apigatewayv2-readme.html#custom-domain

My actual code was:

const domainName = "test.testdomain.com";

const dn = new apigw.DomainName(this, "DN", {
  domainName,
  certificate: certificate,
});

const httpApi = new apigw.HttpApi(this, "HttpApi", {
  defaultDomainMapping: {
    domainName: dn,
    mappingKey: "hello",
  },
});

When I run this with a stack that has never been deployed before, I get the following error:

Invalid stage identifier specified (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException;

Secondly if I try to change mappingKey to ‘/’ I get the following:

An ApiMapping key may contain only letters, numbers and one of $-_.+!*'(), (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException;

Any help you can give is really appreciated, as this is such a great feature, and when it’s possible to get authentication in there too, that will be icing on the cake!

Error Log

Environment

  • CLI Version :
  • Framework Version:
  • Node.js Version:
  • OS :
  • Language (Version):

Other


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kay-iscommented, Oct 21, 2020

This is the best I could get going:

const proxy = new apigatewayv2.HttpApi(this, "DemoProxy", {
  defaultDomainMapping: { domainName, mappingKey: "graphql" },
});

const integration = new apigatewayv2.HttpProxyIntegration({ url: api.graphqlUrl });

proxy.addRoutes({ path: "/", methods: [apigateway.HttpMethod.POST], integration });

mappingKey could neither be "" nor "/".

path couldn’t be empty, so the "/" at the end of the URL is required now.

I have the feeling this should work better, but don’t know how.

1reaction
pahudcommented, Jul 22, 2020

The following mapping works for me now:

defaultDomainMapping: {
     domainName: domainName,
     mappingKey: 'v1'
}

But how would I add an empty mappingKey? Both ‘/’ and ‘’ don’t work.

Hi

At this moment, custom domain only allows to create root base path mapping when there is only one api mapping for this domain. Starting from v1.54.0 in AWS CDK, simply leave the mappingKey undefined and behind the scene an api mapping with empty api mapping key will be created.

However, please note if you create a root path mapping, you can’t create any more api mapping key. This is what we can do with current apigateway v2 custom domain now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting up custom domain names for REST APIs
You can use API Gateway Version 2 APIs to create and manage Regional custom domain names for REST APIs. Custom domain names are...
Read more >
AWS CDK HttpApi, Custom Domain and lambda alias
The code will deploy to one of the stages, but when I go to push to the next stage I get a failure...
Read more >
Error creating custom domain - Serverless Forums
Hello, I am trying to add a custom domain to my otherwise working CloudFormation stack deployed using serverless framework.
Read more >
How to add a custom domain to a serverless API - SST.Dev
It'll bootstrap your AWS environment to use CDK. Deploy a debug stack to power the Live Lambda Development environment. Deploy your app, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found