Skip to content

[aws_cdk.aws_apigatewayv2]: [Add Usage Plan support via the L2 constructs for the aws_apigatewayv2 resources (eg. WebSocketApi)] #28756

@ayushrawat007

Description

@ayushrawat007

Describe the feature

Currently it is not possible as there is no methods associated with the WebSocketApi construct or the UsagePlan construct that could help achieve this use-case.

This is primarily because UsagePlan>> UsagePlanPerApiStage>> api property accepts the IRestApi object and not the IApi that the WebSocketApi class implements.

Something like :

api = apigwv2.WebSocketApi(
            self,
            "websocketapi",
            api_name="test",
            description=f"WebSocket API",
            connect_route_options=..,
            disconnect_route_options=...,
        )

stage = apigwv2.WebSocketStage(
            self,
            "WebsocketStage",
            auto_deploy=True,
            web_socket_api=api,
            stage_name="prod",
            throttle=API_THROTTLE,
        )
# Can not be achieved  
plan.addApiStage({
  api: api,
  stage: stage
});

Use Case

Would like to create UsagePlan for the aws_apigatewayv2 resource with the same ease as that of aws_apigateway.

The only way this is possible as of now is by dropping to L1 constructs:

      api = apigwv2.WebSocketApi(
           self,
           "websocketapi",
           api_name="api",
           description=f"WebSocket API",
           connect_route_options= ..,
           disconnect_route_options= ..,
       )

       API_THROTTLE = apigwv2.ThrottleSettings(
                   burst_limit=123,
                   rate_limit=123
               )

       stage = apigwv2.WebSocketStage(
           self,
           "WebsocketStage",
           auto_deploy=True,
           web_socket_api=api,
           stage_name="prod",
           throttle=API_THROTTLE,
       )
               
       cfn_api_key = apigw.CfnApiKey(self, "MyCfnApiKey",
               description="test api key for usage plan",
               enabled=True,
               name="ApiKey",
               # stage_keys=[apigw.CfnApiKey.StageKeyProperty(
               #     rest_api_id= api.api_id,
               #     stage_name= stage.stage_name
               # )],
               # value="ApiKey-value"
           )

       cfn_usage_plan = apigw.CfnUsagePlan(self, "MyCfnUsagePlan",
           api_stages=[apigw.CfnUsagePlan.ApiStageProperty(
               api_id=api.api_id,
               stage=stage.stage_name,
               #NOTE: Can not be defined as "No method level throttling for Web Socket APIs" can be checked from the UsagePlan console.
               # throttle={
               #     "$connect": apigw.CfnUsagePlan.ThrottleSettingsProperty(
               #         burst_limit=123,
               #         rate_limit=123
               #     )
               # }
           )],
           description="description",
           quota=apigw.CfnUsagePlan.QuotaSettingsProperty(
               limit=123,
               offset=0,
               period="DAY"
           ),
           throttle=apigw.CfnUsagePlan.ThrottleSettingsProperty(
               burst_limit=123,
               rate_limit=123
           ),
           usage_plan_name="usagePlanName"
       )

       cfn_usage_plan_key = apigw.CfnUsagePlanKey(self, "MyCfnUsagePlanKey",
           key_id=cfn_api_key.attr_api_key_id,
           key_type="API_KEY",
           usage_plan_id=cfn_usage_plan.attr_id
       )

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.121.1

Environment details (OS name and version, etc.)

Mac

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-apigatewayv2Related to Amazon API Gateway v2effort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions