简体   繁体   English

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

[英]CloudFormation - How can I reference a serverless usage plan?

Problem:问题:

I want to associate an existing API key to a newly created "Usage Plan" which is created via AWS SAM as below:我想将现有的 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: ????????????????????

Is it possible to reference the UsagePlanId here?是否可以在此处引用 UsagePlanId? I tried: !Ref UsagePlan but no success... Any ideas on how to do it?我试过: !Ref UsagePlan但没有成功......关于如何做的任何想法?

Thanks谢谢

As far as I know, there is no way to reference the UsagePlan created as part of your Api.据我所知,无法引用作为 Api 的一部分创建的 UsagePlan。

However, you can create UsagePlan outside of ApiGatewayApi as a separate resource, and associate it with your ApiGatewayApi .但是,您可以在UsagePlan之外创建ApiGatewayApi作为单独的资源,并将其与您的ApiGatewayApi相关联。 Then you can easily reference it in your UsagePlanKey :然后您可以轻松地在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.

相关问题 使用无服务器框架将 API 添加到使用计划 - Adding API to Usage Plan using Serverless Framework 如何通过 cloudformation 在 sagemaker 中创建无服务器端点? - how to create a serverless endpoint in sagemaker via cloudformation? 如何检查资源是否由 CloudFormation 创建? - How can I check if a resource was created by CloudFormation? 如何在 cloudformation 中引用 ImportValue 中的变量? - How can I ref a variable in ImportValue in cloudformation? 如何在 Serverless 中引用 ssm 中的变量 - How do I reference a variable inside a ssm in Serverless 无法将 AWS API 网关使用计划引用为 Terraform 中的数据源 - Unable to reference an AWS API Gateway Usage Plan as a data source in Terraform 我们可以在 Serverless 中做类似 Terraform Plan 的事情吗? - can we do something like Terraform Plan in Serverless? 我如何在无服务器中添加 http api 阶段 - how i can add a http api stage in serverless 有没有 serverless-cloudformation-changesets 的替代品? 对于无服务器版本 3 - Is there an alternative to the serverless-cloudformation-changesets? for serverless version 3 如何在 cloudformation 的参考参数中使用 AWS principal - How to use AWS principal in reference parameter in cloudformation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM