如何将 Route53 A 记录定位到 ApiGateway v2

How to target Route53 A record to ApiGateway v2

A​​piGateway 1 有一个别名,但它的接口不符合 V2:

这里是domainName

  const domainName = new apigw2.DomainName(config.scope, config.id + 'DomainName', {
    domainName: config.domainName,
    certificate: config.certificate,
  });
  

aws-route53-targets 软件包似乎还不支持 apigatewayv2。同时,您可以像这样将 v2 对象包装在 v1 接口中:

new route53.ARecord(config.scope, config.id + "AliasRecord", {
  recordName: config.domainName,
  target: route53.RecordTarget.fromAlias(
    new route53targets.ApiGatewayDomain({
      ...domainName,
      domainNameAliasDomainName: domainName.regionalDomainName,
      domainNameAliasHostedZoneId: domainName.regionalHostedZoneId
    })
  ),
  zone: config.hostedZone
});

您可以按照 Custom Domain

文档中描述的方式进行尝试
const certArn = 'arn:aws:acm:us-east-1:111111111111:certificate';
const domainName = 'example.com';

const dn = new DomainName(stack, 'DN', {
  domainName,
  certificate: acm.Certificate.fromCertificateArn(stack, 'cert', certArn),
});
const api = new HttpApi(stack, 'HttpProxyProdApi', {
  defaultIntegration: new LambdaProxyIntegration({ handler }),
  // https://${dn.domainName}/foo goes to prodApi $default stage
  defaultDomainMapping: {
    domainName: dn,
    mappingKey: 'foo',
  },
});

Custom Domain 的文档是起点。但是默认不会在Route53中生成任何记录。

要为 ApiGatewayV2 排序:

  1. 按照上述文档中的步骤操作并设置您的 API 网关。
  2. 您需要使用 @aws-cdk/aws-route53@aws-cdk/aws-route53-targets 以及提到 API 网关 V2.[=27 的 example =]

这样:

// From the API Gateway setup (step 1)
const apiProdDomain = new DomainName(this, '...', {...})
...  

new r53.ARecord(this, 'YourDomainAliasRecord', {
   zone: yourDomainHostedZone,
   recordName: yourDomainPrefix, // i.e 'api' for api.xxx.com
   target: r53.RecordTarget.fromAlias(new ApiGatewayv2DomainProperties(apiProdDomain.regionalDomainName, apiProdDomain.regionalHostedZoneId)
 })

就是这样。