Amazon web services AWS CloudFormation:路径映射-指定的阶段标识符无效
我正在通过CloudFormation部署Lambdas(和APIGateway配置),最终使用Amazon web services AWS CloudFormation:路径映射-指定的阶段标识符无效,amazon-web-services,amazon-cloudformation,serverless-framework,Amazon Web Services,Amazon Cloudformation,Serverless Framework,我正在通过CloudFormation部署Lambdas(和APIGateway配置),最终使用 CloudFormation template update stack.json中生成的CloudFormationpathmapping部分如下所示: "pathmapping": { "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "BasePath": "demolambda",
CloudFormation template update stack.json
中生成的CloudFormationpathmapping
部分如下所示:
"pathmapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"BasePath": "demolambda",
"DomainName": "staging-api.<REDACTED>",
"RestApiId": {
"Ref": "ApiGatewayRestApi"
},
"Stage": "staging"
}
}
我不太清楚这是什么意思。堆栈被上传到S3,一切看起来都很好,但是,无论我如何处理它,我都会继续得到这个消息
好奇是否有人想到了这是什么原因或如何修复它?当我运行堆栈时,我将部署的API stageName与BasePathMapping stageName保持一致,并能够成功创建映射。此外,在创建过程中,我还提供了域的特定证书
ApiGatewayDomainName:
Type: AWS::ApiGateway::DomainName
Properties:
CertificateArn:
Fn::ImportValue: !Sub "mycertificates-UserCertificateArn"
DomainName:
Ref: ApiDomainName
ApiGatewayBasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
Properties:
DomainName:
Ref: ApiDomainName
RestApiId:
Ref: ApiGatewayRestApi
Stage: !Sub "${EnvironmentName}"
DependsOn: ApiGatewayDomainName
首先,您需要一个资源
AWS::ApiGateway::Stage
。此资源取决于AWS::ApiGateway::Deployment
然后根据AWS::ApiGateway::Stage将AWS::ApiGateway::BasePathMapping
设置为:
这是我经过测试的解决方案:
Resources:
apiDomainName:
Type: "AWS::ApiGateway::DomainName"
Properties:
CertificateArn: <CertificateArn>
DomainName: <DomainName>
SecurityPolicy: 'TLS_1_2'
EndpointConfiguration:
Types:
- EDGE
apiGateway:
Type: 'AWS::ApiGateway::RestApi'
...
apiGatewayDeployment:
Type: 'AWS::ApiGateway::Deployment'
Properties:
RestApiId: !Ref apiGateway
apiGatewayStage:
Type: "AWS::ApiGateway::Stage"
Properties:
DeploymentId: !Ref apiGatewayDeployment
RestApiId: !Ref apiGateway
StageName: <stage>
...
apiGatewayMapping:
Type: "AWS::ApiGateway::BasePathMapping"
DependsOn:
- apiGatewayStage
Properties:
BasePath: <path>
DomainName: <DomainName>
RestApiId: !Ref apiGateway
Stage: <stage>
资源:
apiDomainName:
类型:“AWS::ApiGateway::DomainName”
特性:
证书学习:
域名:
安全政策:“TLS_1_2”
端点配置:
类型:
-边缘
apiGateway:
类型:“AWS::ApiGateway::RestApi”
...
apiGatewayDeployment:
类型:“AWS::ApiGateway::部署”
特性:
RestApiId:!参考apiGateway
apiGatewayStage:
类型:“AWS::ApiGateway::Stage”
特性:
部署ID:!Ref网关部署
RestApiId:!参考apiGateway
舞台名称:
...
apiGatewayMapping:
类型:“AWS::ApiGateway::BasePathMapping”
德彭森:
-网关级
特性:
基本路径:
域名:
RestApiId:!参考apiGateway
阶段:
一些后续和(黑客)修复
Resources:
apiDomainName:
Type: "AWS::ApiGateway::DomainName"
Properties:
CertificateArn: <CertificateArn>
DomainName: <DomainName>
SecurityPolicy: 'TLS_1_2'
EndpointConfiguration:
Types:
- EDGE
apiGateway:
Type: 'AWS::ApiGateway::RestApi'
...
apiGatewayDeployment:
Type: 'AWS::ApiGateway::Deployment'
Properties:
RestApiId: !Ref apiGateway
apiGatewayStage:
Type: "AWS::ApiGateway::Stage"
Properties:
DeploymentId: !Ref apiGatewayDeployment
RestApiId: !Ref apiGateway
StageName: <stage>
...
apiGatewayMapping:
Type: "AWS::ApiGateway::BasePathMapping"
DependsOn:
- apiGatewayStage
Properties:
BasePath: <path>
DomainName: <DomainName>
RestApiId: !Ref apiGateway
Stage: <stage>