gpt4 book ai didi

amazon-web-services - 如何使用 AWS_MSK CDK 创建连接器 CustomPlugin?

转载 作者:行者123 更新时间:2023-12-03 07:39:27 29 4
gpt4 key购买 nike

我正在使用 CfnConnector(如下面的文档引用链接所述)创建 MSK 连接器,它需要一个 customPluginArn。我如何使用 CDK 创建自定义插件,以便能够获取 CustomPluginArn 和修订号?没有任何关于它的文档。谢谢

引用类 CfnConnector 文档: enter link description here

最佳答案

我结束了创建自定义资源,如果对某人有用,请在此处编码:

 def _create_custom_plugin(self):
create_params = {
"contentType": 'ZIP',
"location": {
's3Location': {
'bucketArn': self._msk_connector_bucket_arn,
'fileKey': self._plugin_file_name,
'objectVersion': 'null'
}
},
"name": self._plugin_name,
"description": self._plugin_name
}

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

cr_policy = iam.Policy(self, 'cr_policy',
statements = [iam.PolicyStatement(
actions=[
's3:*'
],
effect=iam.Effect.ALLOW,
resources=['*']
)]
)

lambda_role = self._get_provisioning_lambda_role(construct_id=id)
lambda_role.attach_inline_policy(cr_policy)

create_update_custom_plugin = custom_resources.AwsCustomResource(self,
'CreateUpdateCustomPlugin',
on_create=create_custom_plugin,
on_update=create_custom_plugin,
policy=custom_resources.AwsCustomResourcePolicy.from_sdk_calls(resources=custom_resources.AwsCustomResourcePolicy.ANY_RESOURCE)
,role=lambda_role)
self._custom_plugin_arn = create_update_custom_plugin.get_response_field('customPluginArn')
self._revision = create_update_custom_plugin.get_response_field('revision')


def _get_provisioning_lambda_role(self, construct_id: str):
return iam.Role(
scope=self,
id=f'{construct_id}-LambdaRole',
assumed_by=iam.ServicePrincipal('lambda.amazonaws.com'),
managed_policies=[iam.ManagedPolicy.from_aws_managed_policy_name(
"service-role/AWSLambdaBasicExecutionRole")],
)

关于amazon-web-services - 如何使用 AWS_MSK CDK 创建连接器 CustomPlugin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73348883/

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