如何在 AWS Eventbridge 中创建自定义事件总线?
How do I create a custom Event Bus in AWS Event Bridge?
我无法在线找到文档或示例 Terraform 模块。
如何在 AWS Event Bridge 中创建自定义事件总线?
截至撰写本文时,AWS 的 Terraform Provider 尚不支持创建 EventBridge 事件总线。
我们必须使用默认事件总线或使用 AWS CLI 或控制台创建它。
注意事项:EventBridge 目前存在几个严重的 IAM 漏洞:您不能限制 IAM 主体也可以发布事件的总线,并且它使用服务主体而不是服务相关角色主体来访问 KMS 等内容用于加密总线的密钥。
您可以使用 null_resource 配置程序作为缺少提供程序资源的解决方法(假设您正在使用环境变量或 IAM 实例配置文件来验证您的 AWS供应商):
resource "null_resource" "custom_event_bus" {
triggers = {
event_bus_name = var.event_bus_name
}
provisioner "local-exec" {
command = "aws events create-event-bus --name ${var.event_bus_name}'"
}
}
如果您使用命名的 AWS 配置文件而不是环境变量,则需要使用 --profile profile_name
指定它,就像您 运行 在 [=25] =].
Terraform 不支持 Event Bridge:
https://github.com/terraform-providers/terraform-provider-aws/issues/9330
通过引用 github 用户 https://github.com/mwarkentin 值得称赞的以下片段,在 terraform hack 中有一个 cloudformation 以启用在 terraform 中声明事件桥:
resource "aws_cloudformation_stack" "eventbridge_bus" {
name = "eventbridge-bus"
template_body = <<EOF
Resources:
EventBus:
Type: AWS::Events::EventBus
Properties:
Name: bus-name
EOF
}
随着最近对 AWS Terraform Provider 的更新,另一个答案中提到的 EOF template_body 样式不再是指定 CloudFormation 堆栈的首选方式.以下是使用新的 STACK 声明样式完成相同事情(提供自定义 EventBridge 总线)的示例代码片段:
resource "aws_cloudformation_stack" "eventbridge_bus" {
name = "eventbridge-bus"
template_body = <<STACK
{
"Resources" : {
"bus" : {
"Type" : "AWS::Events::EventBus",
"Properties" : {
"Name": "bus-name"
}
}
}
}
STACK
}
我无法在线找到文档或示例 Terraform 模块。
如何在 AWS Event Bridge 中创建自定义事件总线?
截至撰写本文时,AWS 的 Terraform Provider 尚不支持创建 EventBridge 事件总线。
我们必须使用默认事件总线或使用 AWS CLI 或控制台创建它。
注意事项:EventBridge 目前存在几个严重的 IAM 漏洞:您不能限制 IAM 主体也可以发布事件的总线,并且它使用服务主体而不是服务相关角色主体来访问 KMS 等内容用于加密总线的密钥。
您可以使用 null_resource 配置程序作为缺少提供程序资源的解决方法(假设您正在使用环境变量或 IAM 实例配置文件来验证您的 AWS供应商):
resource "null_resource" "custom_event_bus" {
triggers = {
event_bus_name = var.event_bus_name
}
provisioner "local-exec" {
command = "aws events create-event-bus --name ${var.event_bus_name}'"
}
}
如果您使用命名的 AWS 配置文件而不是环境变量,则需要使用 --profile profile_name
指定它,就像您 运行 在 [=25] =].
Terraform 不支持 Event Bridge: https://github.com/terraform-providers/terraform-provider-aws/issues/9330
通过引用 github 用户 https://github.com/mwarkentin 值得称赞的以下片段,在 terraform hack 中有一个 cloudformation 以启用在 terraform 中声明事件桥:
resource "aws_cloudformation_stack" "eventbridge_bus" {
name = "eventbridge-bus"
template_body = <<EOF
Resources:
EventBus:
Type: AWS::Events::EventBus
Properties:
Name: bus-name
EOF
}
随着最近对 AWS Terraform Provider 的更新,另一个答案中提到的 EOF template_body 样式不再是指定 CloudFormation 堆栈的首选方式.以下是使用新的 STACK 声明样式完成相同事情(提供自定义 EventBridge 总线)的示例代码片段:
resource "aws_cloudformation_stack" "eventbridge_bus" {
name = "eventbridge-bus"
template_body = <<STACK
{
"Resources" : {
"bus" : {
"Type" : "AWS::Events::EventBus",
"Properties" : {
"Name": "bus-name"
}
}
}
}
STACK
}