首页 > 解决方案 > 使用 CDK 为 AWS ApiGW 重用自定义授权方

问题描述

我想重用在一个存储库中使用 CDK 创建的自定义授权方,用于在另一个存储库中创建的新 AWS ApiGW 方法。目前,没有用于导入现有授权人的 CDK 内置方法。

标签: aws-api-gatewayaws-cdklambda-authorizer

解决方案


我找到了解决问题的方法:

# Import rest api from the environment using ids
rest_api = RestApi.from_rest_api_attributes(self, "fromrestapiid",
                                                    rest_api_id=rest_api_id,
                                                    root_resource_id=resource_id)
# Retrieve or create an API method
method_resource = rest_api.root.resource_for_path(endpoint_path)

# Change the property of the resource using the existing authorizer id
method_resource = method.node.find_child('Resource')
method_resource.add_property_override('AuthorizationType', 'CUSTOM')
method_resource.add_property_override('AuthorizerId', authorizer_id)

推荐阅读