Skip to content

Add API Key capabilities to AWS::Serverless::Api #547

@mariano-calandra-xp

Description

@mariano-calandra-xp

Hi, I was thinking about API key capabilities to AWS::Serverless::Api resource.

Something like:

  MyRestApi:
    Type: AWS::Serverless::Api
    Properties:
      ...
      ApiKeys: 
        - Enabled: true 
          Name: myFirstApiKey
          UsagePlanId: !Ref MyUsagePlan

  MyUsagePlan: 
    Type: AWS::Serverless::ApiUsagePlan
    Properties:
      Name: String
      Description: String
      Quota: QuotaSettings
      Throttle: ThrottleSettings

That will be translated into:

  MyRestApi:
    Type: AWS::Serverless::Api
    ...

  MyFirstApiKey: 
    Type: AWS::ApiGateway::ApiKey
    DependsOn: 
      - MyUsagePlan
    Properties: 
      Name: MyFirstApiKey
      Enabled: "true"
      StageKeys: 
        - RestApiId: !Ref MyRestApi
          StageName: !Ref MyRestApi.Stage

  MyUsagePlan:
    Type: AWS::ApiGateway::UsagePlan
    DependsOn:
      - MyRestApi
    Properties:
      ApiStages:
      - ApiId: !Ref MyRestApi
        Stage: !Ref MyRestApi.Stage
      UsagePlanName: MyUsagePlan
      Quota: QuotaSettings
      Throttle: ThrottleSettings

  MyUsagePlanKey:
    Type: AWS::ApiGateway::UsagePlanKey
    Properties : 
      KeyId: !Ref MyFirstApiKey
      UsagePlanId: !Ref MyUsagePlan
      KeyType: API_KEY

AWS::Serverless::ApiUsagePlan could be optional with a default.

The current way do the job but it's a little bit more verbose

Does it sound?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions