【问题标题】:Issues consuming AWS API Gateway API使用 AWS API Gateway API 的问题
【发布时间】:2020-07-28 13:15:01
【问题描述】:

我有一个使用 AWS API Gateway 创建的简单 HTTP API,它使用 lambda 集成来返回一些数据。 我还使用 route53 (CNAME) 为它配置了自定义 DN

最近我在调用端点时遇到以下错误

Error: Hostname/IP does not match certificate's altnames: Host: xxxxxx. is not in the 
cert's altnames:DNS:*.execute-api.eu-west-2.amazonaws.com

谁能帮忙解释为什么会这样?我也使用 AWS 证书管理器为我的自定义域设置了一个证书,所以它的所有 AWS 服务,但由于某种原因它刚刚停止工作?

谢谢 安德鲁


编辑:我奇怪地间歇性地遇到这个问题,当我在浏览器中调用 API 时,我收到以下错误:

This server could not prove that it is api.xxxx.co.uk; 
its security certificate is from *.execute-api.eu-west-2.amazonaws.com. 
This may be caused by a misconfiguration or an attacker 
intercepting your connection.

然后它消失了,它又可以工作了吗?嗯?有什么想法吗?

【问题讨论】:

  • 您的证书应用在哪里?当您说您设置了证书时,您具体将该证书安装/应用到什么?
  • 嗨,托德,感谢您的帮助。所以我为我的子域(即 api.xxx.com)设置了一个亚马逊颁发的 SSL 证书。然后在 AWS Gateway API 中我添加了一个新的自定义域名(区域端点类型)并设置了这个子域 api.xxx.com 并在给定的搜索框中选择了证书。
  • 您在调用端点时使用的是该子域?
  • 嗨,托德。是的,正确,当我进行 API 调用(例如来自 PostMan)时,我使用 api.xxx.com 进行调用并收到错误消息。但是 API 本身很好,因为如果我使用原始 AWS 生成的域,那么在我的域中使用 CNAME 的那个域它可以正常工作。
  • 可能您正在访问带有 www 的 url,其中只有 domain.com 在 ACM 中注册而没有 www?

标签: amazon-web-services aws-lambda aws-api-gateway


【解决方案1】:

好的,感谢following post,我找到了问题所在

如果您查看底部原始帖子下的 cmets,则作者已经解决了问题,但尚未将其作为帖子的答案,因此您需要通读所有内容才能找到答案。

问题是,您需要确保在 route53 中正确设置了 DNS。 我最初是从我的自定义 DN 创建一个 CNAME 到 API 的调用 URL。

您需要做的是创建一条 ALIAS A 记录,从您的自定义 DN 到您的区域 API 的 DN(前缀为 d-*)

注意:这与您的调用 URL 不同

进行此更改后,我的所有问题都消失了。

对于在 Terraform 中执行此操作的任何人,这就是您所需要的

//HTTP API using quick create (regional)
resource "aws_apigatewayv2_api" "qc_technical_test" {
  name          = "qc_technical_test"
  protocol_type = "HTTP"
  target        = aws_lambda_function.tt_lambda.arn
  route_key = "GET /persons/address"
}

//custom domain name for API (regional)
resource "aws_apigatewayv2_domain_name" "qc_tt_custom_domain" {
  domain_name = "api.${aws_route53_zone.quadcorps.name}"

  domain_name_configuration {
    certificate_arn = aws_acm_certificate.tt_acm.arn
    endpoint_type   = "REGIONAL"
    security_policy = "TLS_1_2"
  }
}

//route53 alias a record to api
resource "aws_route53_record" "tt_api" {
  zone_id = aws_route53_zone.quadcorps.zone_id
  name = aws_apigatewayv2_domain_name.qc_tt_custom_domain.domain_name
  type = "A"

  alias {
    name = aws_apigatewayv2_domain_name.qc_tt_custom_domain.domain_name_configuration.0.target_domain_name
    zone_id = aws_apigatewayv2_domain_name.qc_tt_custom_domain.domain_name_configuration.0.hosted_zone_id
    evaluate_target_health = false
  }
}

希望这可以在将来为某人节省大量时间。

【讨论】:

  • 谢谢。我不能说它为我节省了很多时间,但它使我免于从桥上跳下。
  • 对于其他研究这个问题的人——我需要做的就是使用以“d-”为前缀的 API 网关 URL。我为此使用了 CNAME 记录,不需要使用 A 记录。
猜你喜欢
  • 2018-01-13
  • 1970-01-01
  • 2018-08-21
  • 2020-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多