我正在通过CloudFormation部署Lambdas(和APIGateway配置),最终使用Serverless。
pathmapping
中生成的CloudFormation cloudformation-template-update-stack.json
部分如下所示:
"pathmapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"BasePath": "demolambda",
"DomainName": "staging-api.<REDACTED>",
"RestApiId": {
"Ref": "ApiGatewayRestApi"
},
"Stage": "staging"
}
}
当这个运行时,我收回错误:
pathmapping - Invalid stage identifier specified.
我不确定这意味着什么。堆栈上传到S3,一切看起来都不错,但是,无论我如何玩它,我都会继续收到这条消息。
好奇是否有人对导致此问题或如何解决问题有任何想法?
答案 0 :(得分:0)
运行堆栈时,我将部署的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
答案 1 :(得分:0)
首先,您需要资源AWS::ApiGateway::Stage
。此资源取决于AWS::ApiGateway::Deployment
然后使AWS::ApiGateway::BasePathMapping
依赖于AWS::ApiGateway::Stage
:
这是我经过测试的解决方案:
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>