如何使用 aws-sdk-apigateway 创建使用计划?

How to create usage plan with aws-sdk-apigateway?

我正在尝试使用 aws-sdk apigateway 创建使用计划,但收到错误响应。

这是我正在使用的函数:

const params = {
    name: 'My usage plan',
    description: 'My plan for checking the usage',
    apiStages: [
      {
        apiId: 'b3mzhze48g',
        stage: 'dev',
        throttle: {
          string: {
            burstLimit: 4,
            rateLimit: 8,
          },
        },
      },
    ],
    throttle: {
      burstLimit: 5,
      rateLimit: 10,
    },
    quota: {
      limit: 100,
      offset: 1,
      period: 'WEEK',
    },
  };
  try {
    const result = await apigateway.createUsagePlan(params).promise();
    res.send(result);
  } catch (err) {
    res.send(err);
  }

这是我的 API:

的 ID 图片

api-ids

这是我收到的错误消息:

{
    "message": "Invalid method {resourcePath: string,method: } specified",
    "code": "BadRequestException",
    "time": "2021-01-31T10:58:28.117Z",
    "requestId": "6d175534-e555-4a0d-99ef-1f3fc628e502",
    "statusCode": 400,
    "retryable": false,
    "retryDelay": 80.40030962554764
}

我应该如何修改 apiStages 参数才能为我的 API 中的特定资源设置使用计划?

问题出在 apiStages -> throttle,它用于在资源和方法级别进行节流,它是可选的,但如果设置了它,key 应该是 resource + method name ,即对于 GET /staff/list方法,/staff/list/GET 应该是 key

apiStages: [
    {
      apiId: "abc111i6h3",
      stage: "dev",
      throttle: {
        "/staff/list/GET": {
          burstLimit: 4,
          rateLimit: 8,
        },
      },
    },
  ]

来自 aws documentation 的示例给出了该提示: