【问题标题】:AWS CloudFormation: pathmapping - Invalid stage identifier specifiedAWS CloudFormation:路径映射 - 指定的阶段标识符无效
【发布时间】:2020-10-30 03:50:46
【问题描述】:

我正在通过 CloudFormation 部署 Lambda(和 APIGateway 配置),最终使用 Serverless

cloudformation-template-update-stack.json 中生成的 CloudFormation pathmapping 部分如下所示:

"pathmapping": {
      "Type": "AWS::ApiGateway::BasePathMapping",
      "Properties": {
        "BasePath": "demolambda",
        "DomainName": "staging-api.<REDACTED>",
        "RestApiId": {
          "Ref": "ApiGatewayRestApi"
        },
        "Stage": "staging"
      }
    }

当它运行时,我得到了错误:

pathmapping - Invalid stage identifier specified.

我不太确定这意味着什么。堆栈被上传到 S3,一切看起来都很好,但是,无论我如何使用它,我都会继续收到此消息。

想知道是否有人对导致此问题的原因或如何解决此问题有任何想法?

【问题讨论】:

标签: amazon-web-services amazon-cloudformation serverless-framework


【解决方案1】:

当我运行堆栈时,我保持部署的 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

【讨论】:

    【解决方案2】:

    首先,您需要一个资源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>
    

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 2017-04-27
      • 2020-02-21
      • 2018-06-04
      • 2021-12-09
      • 2018-07-23
      • 2018-02-02
      • 2017-10-10
      • 2019-08-27
      相关资源
      最近更新 更多