AWS Cloudformation Link API Key to API Gateway

喜夏-厌秋 提交于 2019-12-06 20:28:30

Here's a sample template where I have connected my API to a API key. But that's only been possible because I am using usage plans. I believe that is the primary purpose of an API key. API gateway usage plan

ApiKey: 
  Type: AWS::ApiGateway::ApiKey
  Properties: 
    Name: !Join ["", [{"Ref": "AWS::StackName"}, "-apikey"]]
    Description: "CloudFormation API Key V1"
    Enabled: true
    GenerateDistinctId: false
ApiUsagePlan:
  Type: "AWS::ApiGateway::UsagePlan"
  Properties:
    ApiStages: 
    - ApiId: !Ref <API resource name>
      Stage: !Ref <stage resource name>     
    Description: !Join [" ", [{"Ref": "AWS::StackName"}, "usage plan"]]
    Quota:
      Limit: 2000
      Period: MONTH
    Throttle:
      BurstLimit: 10
      RateLimit: 10
    UsagePlanName: !Join ["", [{"Ref": "AWS::StackName"}, "-usage-plan"]]
ApiUsagePlanKey:
  Type: "AWS::ApiGateway::UsagePlanKey"
  Properties:
    KeyId: !Ref <API key>
    KeyType: API_KEY
    UsagePlanId: !Ref ApiUsagePlan

There does not seem to be a way to do this without a usage plan.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!