AWS::ApiGateway::Stage 需要 DeploymentId ... 但我在哪里可以找到它?

AWS::ApiGateway::Stage requires DeploymentId ... but where do I find this?

我正在尝试以编程方式设置阶段,作为我的 AWS API 网关部署的一部分。我正在使用 SAM CLI。 The cloudformation docs给出定义:

DeploymentId The ID of the deployment that the stage points to.

Required: Yes

Type: String

Update requires: No interruption

和代码示例:

Resources:
  Prod:
    Type: AWS::ApiGateway::Stage
    Properties:
      StageName: Prod
      Description: Prod Stage
      RestApiId: !Ref MyRestApi
      DeploymentId: !Ref TestDeployment ##      <===== this
      DocumentationVersion: !Ref MyDocumentationVersion
      ClientCertificateId: !Ref ClientCertificate
      Variables:
        Stack: Prod
      MethodSettings:
        - ResourcePath: /
          HttpMethod: GET
          MetricsEnabled: 'true'
          DataTraceEnabled: 'true'
        - ResourcePath: /stack
          HttpMethod: POST
          MetricsEnabled: 'true'
          DataTraceEnabled: 'true'
          ThrottlingBurstLimit: '999'
        - ResourcePath: /stack
          HttpMethod: GET
          MetricsEnabled: 'true'
          DataTraceEnabled: 'true'
          ThrottlingBurstLimit: '555'

..但没有关于值 TestDeployment 指向什么的上下文。

我一直在谷歌搜索,但似乎仍然找不到答案。

查看 AWS 管理控制台,我可以看到我们已经存在的一些 APIs - 当阶段 已经存在 (手动设置)时,您可以通过阶段获得部署 ID,但如果我必须先手动设置它们,那将部分破坏 CloudFormation AWS::ApiGateway::Stage 的目的,不是吗(......理想情况下,我们希望能够通过代码创建 API 的 完全 ,而无需进入 AWS 界面)? deploymentId 不会只在部署后可用吗?如果它在之前可用(作为构建的一部分),我如何在部署之前获取它并将其放入我的 cloudformation.yaml 中?

感谢任何帮助理解这一点的人!

部署包含有关 API 网关部署的元数据,例如描述,也可用于部署 canary release. You can create a Deployment resource 作为 CloudFormation 模板的一部分。

Deployment: 
  Type: AWS::ApiGateway::Deployment
  Properties: 
    RestApiId: 
      Ref: "MyApi"
    Description: "My deployment"
    StageName: "DummyStage"

当你 !Ref 它会 return DeploymentId。请务必阅读名为 AWS::ApiGateway::Method Dependency 的文档部分,以了解如何将 API 方法附加到部署。