CloudFormation - 如何参考无服务器使用计划?

CloudFormation - How can I reference a serverless usage plan?

问题:

我想将现有的 API 密钥与通过 AWS SAM 创建的新创建的“使用计划”相关联,如下所示:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: MyAPI
      OpenApiVersion: '2.0'
      EndpointConfiguration:
        Type: REGIONAL
      StageName: prod
      MethodSettings:
        - ResourcePath: "/*"
          HttpMethod: "*"
          ThrottlingBurstLimit: 1
          ThrottlingRateLimit: 1
      Domain:
        DomainName: api.mywebsite.com
        CertificateArn: 'arn:aws:acm:eu-north-1:101010101010:certificate/88888888-4444-3333-2222-1111111111'
        EndpointConfiguration: REGIONAL
        Route53:
          HostedZoneId: 'OMMITTD82737373'
        BasePath:
          - /
      Auth:
        UsagePlan:
          CreateUsagePlan: PER_API
          Description: Usage plan for this API
          Quota:
            Limit: 1000
            Period: MONTH
          Throttle:
            BurstLimit: 1
            RateLimit: 1
          Tags:
            - Key: Name
              Value: MyUsagePlan
  usagePlanKey:
    Type: 'AWS::ApiGateway::UsagePlanKey'
    Properties:
      KeyId: 2672762828
      KeyType: API_KEY
      UsagePlanId: ????????????????????

这里可以引用UsagePlanId吗? 我试过:!Ref UsagePlan 但没有成功... 有什么想法吗?

谢谢

据我所知,无法引用作为 Api 的一部分创建的 UsagePlan。

但是,您可以在 ApiGatewayApi 之外创建 UsagePlan 作为单独的资源,并将其与您的 ApiGatewayApi 相关联。然后您可以轻松地在 UsagePlanKey:

中引用它
usagePlan:
  Type: 'AWS::ApiGateway::UsagePlan'
  Properties:
    ApiStages:
      - ApiId: !Ref ApiGatewayApi
        Stage: prod
    ... (rest of the properties omitted)

usagePlanKey:
  Type: 'AWS::ApiGateway::UsagePlanKey'
  Properties:
    KeyId: 2672762828
    KeyType: API_KEY
    UsagePlanId: !Ref usagePlan