我有一个CloudFormation堆栈,它使用API、Lambda和一个自定义域。当我完全拆下堆栈并重新部署它时,我常常会发现API处于一种状态,对于通过自定义域发出的每个API请求,它都返回"502坏网关“。
以下是其他一些意见:
我仍然可以使用标准的执行URL (e.g.<api-id>.execute-api.us-east-1.amazonaws.com)
F 212
这个“感觉就像”一个API网关缓存错误,它仍然试图将我的自定义域路由到旧的(自删除后) API实例(即使AWS控制台显示正确的值)。
知道是什么原因导致了这个问题,或者如何调试它吗?我看过的日志似乎毫无帮助,因为错误发生在我的API实际到达之前。
我的CloudFormation的相关部分如下所示:
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
...
ApiDomainName:
Type: AWS::ApiGatewayV2::DomainName
Properties:
DomainName: !Ref DomainName
DomainNameConfigurations:
- CertificateArn: !Ref CertificateArn
ApiMapping:
Type: AWS::ApiGatewayV2::ApiMapping
Properties:
ApiId: !Ref ServerlessHttpApi
DomainName: !Ref ApiDomainName
Stage: !Ref ServerlessHttpApiApiGatewayDefaultStage
DNSRecord:
Type: AWS::Route53::RecordSet
Properties:
Name: !Ref DomainName
Type: A
AliasTarget:
DNSName: !GetAtt ApiDomainName.RegionalDomainName
HostedZoneId: !GetAtt ApiDomainName.RegionalHostedZoneId
HostedZoneId: !Ref HostedZoneId> curl https://api.example.com
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
</body>
</html>
> curl https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com
{"message":"Hello World"}%交叉到aws论坛这里:https://forums.aws.amazon.com/thread.jspa?messageID=960826
发布于 2020-10-21 10:11:33
似乎您正在构建一个无服务器的应用程序。为此,我将使用无服务器应用程序模型(SAM):https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started.html
切换后,自定义域名的声明如下所示:
MyApi:
Type: AWS::Serverless::Api
Properties:
BinaryMediaTypes: [image~1jpg]
StageName: !Ref Stage
EndpointConfiguration: REGIONAL
Domain:
DomainName: api.example.com
CertificateArn: <ARN of the Certificate from ACM>
EndpointConfiguration: REGIONAL
Route53:
HostedZoneId: <Hosted zone id from route 53>发布于 2020-10-21 10:37:24
如果您使用的是RDS光环无服务器,在连续几分钟不活动后暂停计算能力,您可能会遇到这个问题。在等待2分钟并重试之后,
https://stackoverflow.com/questions/64450035
复制相似问题