AWSCDK-嵌套APIGateway模型验证
创始人
2024-09-24 01:30:29
0

AWS CDK允许我们使用嵌套堆叠API网关。当需要在API网关层中添加模型验证时,需要在CDK中使用“aws-apigateway.Model”类。为了在非常规的情况下添加模型验证(例如在嵌套API网关中),我们需要使用AWS官方文档建议的“aws-apigateway.CfnModel”类。以下是一个简单的示例,演示如何使用CDK配置嵌套API网关模型验证。

from aws_cdk import (
    aws_apigateway as apigateway,
    aws_iam as iam,
    core
)

class NestedApiGatewayStack(core.Stack):
    def __init__(self, app: core.App, id: str, **kwargs):
        super().__init__(app, id, **kwargs)

        # 创建新的嵌套API网关
        child_api_gateway = apigateway.RestApi(
            self,
            "ChildApiGateway",
            rest_api_name="ChildApiGateway",
            deploy_options={
                "stage_name": "test"
            }
        )

        # 在根API网关中添加子网关集成
        # 注意:这里我们使用了CfnModel而不是原生Model类
        # 这是因为原生的Model类不能在嵌套API网关中使用。
        child_model = apigateway.CfnModel(
            self,
            "ChildModel",
            rest_api_id=self.rest_api.rest_api_id,
            content_type="application/json",
            schema={
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"}
                },
                "required": ["name"]
            }
        )

        # 在根API网关中创建子资源
        child_resource = self.rest_api.root.add_resource("child")

        # 在子资源上添加方法,并使用集成访问子网关
        child_resource.add_method(
            "GET",
            apigateway.Integration(
                type=apig

相关内容

热门资讯

记者揭秘!智星菠萝辅助(透视辅... 记者揭秘!智星菠萝辅助(透视辅助)拱趴大菠萝辅助神器,扑克教程(有挂细节);模式供您选择,了解更新找...
一分钟揭秘!约局吧能能开挂(透... 一分钟揭秘!约局吧能能开挂(透视辅助)hhpoker辅助靠谱,2024新版教程(有挂教学);约局吧能...
透视辅助!wepoker模拟器... 透视辅助!wepoker模拟器哪个好用(脚本)hhpoker辅助挂是真的,科技教程(有挂技巧);囊括...
透视代打!hhpkoer辅助器... 透视代打!hhpkoer辅助器视频(辅助挂)pokemmo脚本辅助,2024新版教程(有挂教程);风...
透视了解!约局吧德州真的有透视... 透视了解!约局吧德州真的有透视挂(透视脚本)德州局HHpoker透视脚本,必胜教程(有挂分析);亲,...
六分钟了解!wepoker挂底... 六分钟了解!wepoker挂底牌(透视)德普之星开辅助,详细教程(有挂解密);德普之星开辅助是一种具...
9分钟了解!wpk私人辅助(透... 9分钟了解!wpk私人辅助(透视)hhpoker德州透视,插件教程(有挂教学);风靡全球的特色经典游...
推荐一款!wepoker究竟有... 推荐一款!wepoker究竟有透视(脚本)哈糖大菠萝开挂,介绍教程(有挂技术);囊括全国各种wepo...
每日必备!wepoker有人用... 每日必备!wepoker有人用过(脚本)wpk有那种辅助,线上教程(有挂规律);wepoker有人用...
玩家必备教程!wejoker私... 玩家必备教程!wejoker私人辅助软件(脚本)哈糖大菠萝可以开挂,可靠技巧(有挂神器)申哈糖大菠萝...