使用 boto3 AWS api 网关将使用计划关联到 api 密钥

Associate a usage plan to api key using boto3 AWS api gateway

嘿,我正在使用 boto3 库创建一个新的 api 密钥。我成功地创建了一个新的 api 密钥,但我无法将它与现有的使用计划相关联。你能帮我把 api-key 关联到现有的使用计划吗 我创建 api 键的代码

import boto3
apiclient= boto3.client('apigateway')
response= apiclient.create_api_key(
        name='string',
        enabled=True,
        stageKeys=[{
            'restApiId':'string',
            'stageName':'string'
        }]
        )

我能够使用 'create_usage_plan_key' 方法将使用计划附加到 api 密钥 实施:

import boto3
apiclient= boto3.client('apigateway')
response= apiclient.create_api_key(
        name='string',
        enabled=True,
        stageKeys=[{
            'restApiId':'string',
            'stageName':'string'
        }]
        )
api_key_id=response['id']
usage_planId="<Your usage plan id>"
keytype='API-KEY' # use this line same as it is

usageresponse= apiclient.create_usage_plan_key(
     usagePlanId= usage_planId,
     keyId=api_key_id,
     keyType=keytype
     )

有关详细信息,请转到此文档https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/apigateway.html#APIGateway.Client.create_usage_plan_key