|
| 1 | +--- |
| 2 | +subcategory: "EventBridge" |
| 3 | +layout: "aws" |
| 4 | +page_title: "AWS: aws_events_put_events" |
| 5 | +description: |- |
| 6 | + Sends custom events to Amazon EventBridge so that they can be matched to rules. |
| 7 | +--- |
| 8 | + |
| 9 | +# Action: aws_events_put_events |
| 10 | + |
| 11 | +~> **Note:** `aws_events_put_events` is in beta. Its interface and behavior may change as the feature evolves, and breaking changes are possible. It is offered as a technical preview without compatibility guarantees until Terraform 1.14 is generally available. |
| 12 | + |
| 13 | +Sends custom events to Amazon EventBridge so that they can be matched to rules. This action provides an imperative way to emit events from Terraform plans (e.g., deployment notifications) while still allowing Terraform to manage when the emission occurs through `action_trigger` lifecycle events. |
| 14 | + |
| 15 | +## Example Usage |
| 16 | + |
| 17 | +### Basic Event |
| 18 | + |
| 19 | +```terraform |
| 20 | +action "aws_events_put_events" "example" { |
| 21 | + config { |
| 22 | + entry { |
| 23 | + source = "mycompany.myapp" |
| 24 | + detail_type = "User Action" |
| 25 | + detail = jsonencode({ |
| 26 | + user_id = "12345" |
| 27 | + action = "login" |
| 28 | + }) |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +### Multiple Events |
| 35 | + |
| 36 | +```terraform |
| 37 | +action "aws_events_put_events" "batch" { |
| 38 | + config { |
| 39 | + entry { |
| 40 | + source = "mycompany.orders" |
| 41 | + detail_type = "Order Created" |
| 42 | + detail = jsonencode({ |
| 43 | + order_id = "order-123" |
| 44 | + amount = 99.99 |
| 45 | + }) |
| 46 | + } |
| 47 | +
|
| 48 | + entry { |
| 49 | + source = "mycompany.orders" |
| 50 | + detail_type = "Order Updated" |
| 51 | + detail = jsonencode({ |
| 52 | + order_id = "order-456" |
| 53 | + status = "shipped" |
| 54 | + }) |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +### Custom Event Bus |
| 61 | + |
| 62 | +```terraform |
| 63 | +resource "aws_cloudwatch_event_bus" "example" { |
| 64 | + name = "custom-bus" |
| 65 | +} |
| 66 | +
|
| 67 | +action "aws_events_put_events" "custom_bus" { |
| 68 | + config { |
| 69 | + entry { |
| 70 | + source = "mycompany.analytics" |
| 71 | + detail_type = "Page View" |
| 72 | + event_bus_name = aws_cloudwatch_event_bus.example.name |
| 73 | + detail = jsonencode({ |
| 74 | + page = "/home" |
| 75 | + user = "anonymous" |
| 76 | + }) |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +### Event with Resources and Timestamp |
| 83 | + |
| 84 | +```terraform |
| 85 | +action "aws_events_put_events" "detailed" { |
| 86 | + config { |
| 87 | + entry { |
| 88 | + source = "aws.ec2" |
| 89 | + detail_type = "EC2 Instance State-change Notification" |
| 90 | + time = "2023-01-01T12:00:00Z" # RFC3339 |
| 91 | + resources = ["arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0"] |
| 92 | + detail = jsonencode({ |
| 93 | + instance_id = "i-1234567890abcdef0" |
| 94 | + state = "running" |
| 95 | + }) |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +### Triggered by Terraform Data |
| 102 | + |
| 103 | +```terraform |
| 104 | +resource "terraform_data" "deploy" { |
| 105 | + input = var.deployment_id |
| 106 | +
|
| 107 | + lifecycle { |
| 108 | + action_trigger { |
| 109 | + events = [before_create, before_update] |
| 110 | + actions = [action.aws_events_put_events.deployment] |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | +
|
| 115 | +action "aws_events_put_events" "deployment" { |
| 116 | + config { |
| 117 | + entry { |
| 118 | + source = "mycompany.deployments" |
| 119 | + detail_type = "Deployment Complete" |
| 120 | + detail = jsonencode({ |
| 121 | + deployment_id = var.deployment_id |
| 122 | + environment = var.environment |
| 123 | + timestamp = timestamp() |
| 124 | + }) |
| 125 | + } |
| 126 | + } |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +## Argument Reference |
| 131 | + |
| 132 | +This action supports the following arguments: |
| 133 | + |
| 134 | +* `entry` - (Required) One or more `entry` blocks defining events to send. Multiple blocks may be specified. See [below](#entry-block). |
| 135 | +* `region` - (Optional) AWS region override. Defaults to the provider region if omitted. |
| 136 | + |
| 137 | +### `entry` Block |
| 138 | + |
| 139 | +Each `entry` block supports: |
| 140 | + |
| 141 | +* `source` - (Required) The source identifier for the event (e.g., `mycompany.myapp`). |
| 142 | +* `detail_type` - (Optional) Free-form string used to decide what fields to expect in the event detail. |
| 143 | +* `detail` - (Optional) JSON string (use `jsonencode()`) representing the event detail payload. |
| 144 | +* `event_bus_name` - (Optional) Name or ARN of the event bus. Defaults to the account's default bus. |
| 145 | +* `resources` - (Optional) List of ARNs the event primarily concerns. |
| 146 | +* `time` - (Optional) RFC3339 timestamp for the event. If omitted, the receive time is used. |
0 commit comments