如何为 AWS APIGateway Stage 设置 CloudWatch 设置

How to set CloudWatch Settings for AWS APIGateway Stage

在 AWS ApiGateway 中,在使用 JAVA api 部署新阶段后,如何使用 Java API 而不是通过 aws 启用 CloudWatch 设置控制台?

对于 create-stage,我可以在 CreateStage 输出下的 MethodSetting 中获取 CloudWatch 设置,但是我无法在创建阶段或创建部署时设置这些设置。

您应该能够使用 patch request to the update-stage operation

为您的阶段更新 CloudWatch 设置

这是一个示例代码片段(我还没有实际测试过;但基本原则应该有效):

AmazonApiGateway apiGateway = ...;
UpdateStageRequest req = new UpdateStageRequest().withRestApiId(<api-id>).
            withStageName(<stage-name>).
            withPatchOperations(
                new PatchOperation().withPath("*/*/metrics/enabled")
                                    .withOp("replace")
                                    .withValue("true"));

apiGateway.upate(req);