【问题标题】:How to create usage plan with aws-sdk-apigateway?如何使用 aws-sdk-apigateway 创建使用计划?
【发布时间】:2021-01-31 21:54:29
【问题描述】:

我正在尝试使用 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 中设置特定资源的使用计划?

【问题讨论】:

    标签: aws-api-gateway aws-sdk aws-sdk-nodejs


    【解决方案1】:

    问题在于 apiStages -> 节流,它用于在资源和方法级别进行节流,它是可选的,但如果设置,键应该是资源 + 方法名称,即对于 GET /staff/list 方法,/员工/列表/GET 应该是关键

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-12
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      相关资源
      最近更新 更多