gpt4 book ai didi

amazon-web-services - 如何获取 Amazon MSK 的代理终端节点作为输出

转载 作者:行者123 更新时间:2023-12-03 22:30:00 33 4
gpt4 key购买 nike

我们有一个 AWS cloudformation 模板,通过它我们可以创建 Amazon MSK(Kafka) 集群。运行良好。

现在,我们的产品堆栈中有多个应用程序,它们使用由 Amazon MSK 创建的代理终端节点。现在,为了自动化产品部署,我们决定为 MSK 代理端点创建 Route53 记录集。我们很难找到如何获取 MSK 集群的代理端点作为 AWS Cloudformation 模板中的输出。

期待对此的建议/指导。

最佳答案

根据 @joinEffort 的回答,我是如何使用自定义资源作为 MKS::Cluster 的 CFN 资源来做到这一点的,不会公开代理 URL:(选项 2 使用 boto3 并调用 AWS API

可以在此处找到 CDK 自定义资源代码中使用的类和方法的描述: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Kafka.html#getBootstrapBrokers-property

选项 1:使用自定义资源:

def get_bootstrap_servers(self):

create_params = {
"ClusterArn": self._platform_msk_cluster_arn
}

get_bootstrap_brokers = custom_resources.AwsSdkCall(
service='Kafka',
action='getBootstrapBrokers',
region='ap-southeast-2',
physical_resource_id=custom_resources.PhysicalResourceId.of(f'connector-{self._environment_name}'),
parameters = create_params
)

create_update_custom_plugin = custom_resources.AwsCustomResource(self,
'getBootstrapBrokers',
on_create=get_bootstrap_brokers,
on_update=get_bootstrap_brokers,
policy=custom_resources.AwsCustomResourcePolicy.from_sdk_calls(resources=custom_resources.AwsCustomResourcePolicy.ANY_RESOURCE)
)

return create_update_custom_plugin.get_response_field('BootstrapBrokerString')

选项 2:使用 boto3:

 client = boto3.client('kafka', region_name='ap-southeast-2')
response = client.get_bootstrap_brokers(
ClusterArn='xxx')

#From here u can get the broker urls:
json_response = json.loads(json.dumps(response))

引用:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/kafka.html#Kafka.Client.get_bootstrap_brokers

关于amazon-web-services - 如何获取 Amazon MSK 的代理终端节点作为输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60596875/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com