使用 AWS CDK 从 EventBridge 触发 AWS Glue Worklfow
Use AWS CDK to trigger AWS Glue Worklfow from EventBridge
如 this link 中所述,Level 2 构造不支持它。但是,可以使用 Level 1 Constructs 来实现它。谁能告诉我如何使用 1 级构造来做,或者给我一个例子?非常感谢。
我刚刚为我自己的用例完成了设置。我很想听听其他人是如何做到的,因为我的解决方案似乎是一种横向方法。我能想到的最好办法是创建一个带有 EventBridge 触发器的胶水工作流。然后配置以您的工作流为目标的事件规则。您应该能够直接将 S3 配置为 post 事件,但是没有显示任何事件,所以我最终使用了中间 Trail。
obj1 = events.CfnRule(self, 'tgr_id',
#pattern to tgr on s3 Create Object events
event_pattern={
"source": ["aws.s3"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": ["PutObject", "CompleteMultipartUpload", "CopyObject", "RestoreObject"],
"requestParameters": {
"bucketName": ["bucket-name"],
"key": [{"prefix":"sample/"}]
}
}
},
targets=[events.CfnRule.TargetProperty(
arn=f'arn:aws:glue:{region}:{account-id}:workflow/{glue_workflow_name}',
id=glue_wf_id,
role_arn='arn:aws:iam::{account-id}:role/service-role/{role-name}'
)]
)
这是我找到的方法。与 Zcauchon 的非常相似。结果看起来像我手动创建的那个。但是代码看起来还是很老套。
trigger = glue.CfnTrigger(
self,
id=f"{job.name}-trigger",
workflow_name=workflow.name,
actions=[
glue.CfnTrigger.ActionProperty(
job_name=job.name,
)
],
type="EVENT",
name=f"{job.name}-trigger",
description=f"Scheduled run for {job.name}.",
)
event_pattern = {
"source": ["aws.s3"],
"detail-type": ["Object Created"],
"detail": {
"bucket": {
"name": ["name"],
},
"object": {
"key": [
{
"prefix": "prefix"
}
]
},
},
}
workflow_arn = (
f"arn:aws:glue:{self.region}:{self.account}:workflow/{workflow_id}"
)
role = self._create_iam_role(workflow_arn)
rule = CfnRule(
self,
"id",
event_pattern=event_pattern,
name="name",
role_arn=role.attr_arn,
targets=[
CfnRule.TargetProperty(
arn=workflow_arn,
id="id",
role_arn=role.attr_arn,
)
],
)
如 this link 中所述,Level 2 构造不支持它。但是,可以使用 Level 1 Constructs 来实现它。谁能告诉我如何使用 1 级构造来做,或者给我一个例子?非常感谢。
我刚刚为我自己的用例完成了设置。我很想听听其他人是如何做到的,因为我的解决方案似乎是一种横向方法。我能想到的最好办法是创建一个带有 EventBridge 触发器的胶水工作流。然后配置以您的工作流为目标的事件规则。您应该能够直接将 S3 配置为 post 事件,但是没有显示任何事件,所以我最终使用了中间 Trail。
obj1 = events.CfnRule(self, 'tgr_id',
#pattern to tgr on s3 Create Object events
event_pattern={
"source": ["aws.s3"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": ["PutObject", "CompleteMultipartUpload", "CopyObject", "RestoreObject"],
"requestParameters": {
"bucketName": ["bucket-name"],
"key": [{"prefix":"sample/"}]
}
}
},
targets=[events.CfnRule.TargetProperty(
arn=f'arn:aws:glue:{region}:{account-id}:workflow/{glue_workflow_name}',
id=glue_wf_id,
role_arn='arn:aws:iam::{account-id}:role/service-role/{role-name}'
)]
)
这是我找到的方法。与 Zcauchon 的非常相似。结果看起来像我手动创建的那个。但是代码看起来还是很老套。
trigger = glue.CfnTrigger(
self,
id=f"{job.name}-trigger",
workflow_name=workflow.name,
actions=[
glue.CfnTrigger.ActionProperty(
job_name=job.name,
)
],
type="EVENT",
name=f"{job.name}-trigger",
description=f"Scheduled run for {job.name}.",
)
event_pattern = {
"source": ["aws.s3"],
"detail-type": ["Object Created"],
"detail": {
"bucket": {
"name": ["name"],
},
"object": {
"key": [
{
"prefix": "prefix"
}
]
},
},
}
workflow_arn = (
f"arn:aws:glue:{self.region}:{self.account}:workflow/{workflow_id}"
)
role = self._create_iam_role(workflow_arn)
rule = CfnRule(
self,
"id",
event_pattern=event_pattern,
name="name",
role_arn=role.attr_arn,
targets=[
CfnRule.TargetProperty(
arn=workflow_arn,
id="id",
role_arn=role.attr_arn,
)
],
)