如何为 AWS APIGateway 阶段设置 CloudWatch 设置



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

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

您应该能够通过对更新阶段操作的补丁请求来更新阶段的 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);

最新更新