簡體   English   中英

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。

但是,您可以在UsagePlan之外創建ApiGatewayApi作為單獨的資源,並將其與您的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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM