{"id":"eventbridge","name":"eventbridge","summary":"イベント駆動アーキテクチャ向けのAWS EventBridgeサーバーレスイベントバス。ルール作成、イベントパターンの設定、予定イベントの設定、SaaSとの統合、またはクロスアカウントイベントルーティングの構築などに活用します。","body":"# AWS EventBridge\n\nAmazon EventBridge is a serverless event bus that connects applications using events. Route events from AWS services, custom applications, and SaaS partners.\n\n## Table of Contents\n\n- [Core Concepts](#core-concepts)\n- [Common Patterns](#common-patterns)\n- [CLI Reference](#cli-reference)\n- [Best Practices](#best-practices)\n- [Troubleshooting](#troubleshooting)\n- [References](#references)\n\n## Core Concepts\n\n### Event Bus\n\nChannel that receives events. Types:\n- **Default**: Receives AWS service events\n- **Custom**: Your application events\n- **Partner**: SaaS application events\n\n### Rules\n\nMatch incoming events and route to targets. Each rule can have up to 5 targets.\n\n### Event Patterns\n\nJSON patterns that define which events match a rule.\n\n### Targets\n\nAWS services that receive matched events (Lambda, SQS, SNS, Step Functions, etc.).\n\n### Scheduler\n\nSchedule one-time or recurring events to invoke targets.\n\n## Common Patterns\n\n### Create Custom Event Bus and Rule\n\n**AWS CLI:**\n\n```bash\n# Create custom event bus\naws events create-event-bus --name my-app-events\n\n# Create rule\naws events put-rule \\\n  --name order-created-rule \\\n  --event-bus-name my-app-events \\\n  --event-pattern '{\n    \"source\": [\"my-app.orders\"],\n    \"detail-type\": [\"Order Created\"]\n  }'\n\n# Add Lambda target\naws events put-targets \\\n  --rule order-created-rule \\\n  --event-bus-name my-app-events \\\n  --targets '[{\n    \"Id\": \"process-order\",\n    \"Arn\": \"arn:aws:lambda:us-east-1:123456789012:function:ProcessOrder\"\n  }]'\n\n# Add Lambda permission\naws lambda add-permission \\\n  --function-name ProcessOrder \\\n  --statement-id eventbridge-order-created \\\n  --action lambda:InvokeFunction \\\n  --principal events.amazonaws.com \\\n  --source-arn arn:aws:events:us-east-1:123456789012:rule/my-app-events/order-created-rule\n```\n\n**boto3:**\n\n```python\nimport boto3\n\nevents = boto3.client('events')\n\n# Create event bus\nevents.create_event_bus(Name='my-app-events')\n\n# Create rule\nevents.put_rule(\n    Name='order-created-rule',\n    EventBusName='my-app-events',\n    EventPattern=json.dumps({\n        'source': ['my-app.orders'],\n        'detail-type': ['Order Created']\n    }),\n    State='ENABLED'\n)\n\n# Add target\nevents.put_targets(\n    Rule='order-created-rule',\n    EventBusName='my-app-events',\n    Targets=[{\n        'Id': 'process-order',\n        'Arn': 'arn:aws:lambda:us-east-1:123456789012:function:ProcessOrder'\n    }]\n)\n```\n\n### Publish Custom Events\n\n```python\nimport boto3\nimport json\n\nevents = boto3.client('events')\n\nevents.put_events(\n    Entries=[\n        {\n            'Source': 'my-app.orders',\n            'DetailType': 'Order Created',\n            'Detail': json.dumps({\n                'order_id': '12345',\n                'customer_id': 'cust-789',\n                'total': 99.99,\n                'items': [\n                    {'product_id': 'prod-1', 'quantity': 2}\n                ]\n            }),\n            'EventBusName': 'my-app-events'\n        }\n    ]\n)\n```\n\n### Scheduled Events\n\n```bash\n# Run every 5 minutes\naws events put-rule \\\n  --name every-5-minutes \\\n  --schedule-expression \"rate(5 minutes)\"\n\n# Run at specific times (cron)\naws events put-rule \\\n  --name daily-cleanup \\\n  --schedule-expression \"cron(0 2 * * ? *)\"\n\n# Add target\naws events put-targets \\\n  --rule every-5-minutes \\\n  --targets '[{\n    \"Id\": \"cleanup-function\",\n    \"Arn\": \"arn:aws:lambda:us-east-1:123456789012:function:Cleanup\"\n  }]'\n```\n\n### EventBridge Scheduler (One-Time and Flexible)\n\n```bash\n# One-time schedule\naws scheduler create-schedule \\\n  --name send-reminder \\\n  --schedule-expression \"at(2024-12-25T09:00:00)\" \\\n  --target '{\n    \"Arn\": \"arn:aws:lambda:us-east-1:123456789012:function:SendReminder\",\n    \"RoleArn\": \"arn:aws:iam::123456789012:role/scheduler-role\",\n    \"Input\": \"{\\\"message\\\": \\\"Merry Christmas!\\\"}\"\n  }' \\\n  --flexible-time-window '{\"Mode\": \"OFF\"}'\n\n# Recurring with flexible window\naws scheduler create-schedule \\\n  --name hourly-sync \\\n  --schedule-expression \"rate(1 hour)\" \\\n  --target '{\n    \"Arn\": \"arn:aws:lambda:us-east-1:123456789012:function:SyncData\",\n    \"RoleArn\": \"arn:aws:iam::123456789012:role/scheduler-role\"\n  }' \\\n  --flexible-time-window '{\"Mode\": \"FLEXIBLE\", \"MaximumWindowInMinutes\": 15}'\n```\n\n### AWS Service Events\n\n```bash\n# EC2 state changes\naws events put-rule \\\n  --name ec2-state-change \\\n  --event-pattern '{\n    \"source\": [\"aws.ec2\"],\n    \"detail-type\": [\"EC2 Instance State-change Notification\"],\n    \"detail\": {\n      \"state\": [\"stopped\", \"terminated\"]\n    }\n  }'\n\n# S3 object created\naws events put-rule \\\n  --name s3-upload \\\n  --event-pattern '{\n    \"source\": [\"aws.s3\"],\n    \"detail-type\": [\"Object Created\"],\n    \"detail\": {\n      \"bucket\": {\"name\": [\"my-bucket\"]},\n      \"object\": {\"key\": [{\"prefix\": \"uploads/\"}]}\n    }\n  }'\n```\n\n## CLI Reference\n\n### Event Buses\n\n| Command | Description |\n|---------|-------------|\n| `aws events create-event-bus` | Create event bus |\n| `aws events delete-event-bus` | Delete event bus |\n| `aws events list-event-buses` | List event buses |\n| `aws events describe-event-bus` | Get event bus details |\n\n### Rules\n\n| Command | Description |\n|---------|-------------|\n| `aws events put-rule` | Create or update rule |\n| `aws events delete-rule` | Delete rule |\n| `aws events list-rules` | List rules |\n| `aws events describe-rule` | Get rule details |\n| `aws events enable-rule` | Enable rule |\n| `aws events disable-rule` | Disable rule |\n\n### Targets\n\n| Command | Description |\n|---------|-------------|\n| `aws events put-targets` | Add targets to rule |\n| `aws events remove-targets` | Remove targets |\n| `aws events list-targets-by-rule` | List rule targets |\n\n### Events\n\n| Command | Description |\n|---------|-------------|\n| `aws events put-events` | Publish events |\n\n## Best Practices\n\n### Event Design\n\n- **Use meaningful source names** — `company.service.component`\n- **Use descriptive detail-types** — `Order Created`, `User Signed Up`\n- **Include correlation IDs** for tracing\n- **Keep events small** (< 256 KB)\n- **Use versioning** for event schemas\n\n```python\n# Good event structure\n{\n    'Source': 'mycompany.orders.api',\n    'DetailType': 'Order Created',\n    'Detail': json.dumps({\n        'version': '1.0',\n        'correlation_id': 'req-abc-123',\n        'timestamp': '2024-01-15T10:30:00Z',\n        'order_id': '12345',\n        'data': {...}\n    })\n}\n```\n\n### Reliability\n\n- **Use DLQs** for failed deliveries\n- **Implement idempotency** in consumers\n- **Monitor failed invocations**\n- **Use archive and replay** for recovery\n\n### Security\n\n- **Use resource policies** to control access\n- **Enable encryption** with KMS\n- **Use IAM roles** for targets\n\n### Cost Optimization\n\n- **Use specific event patterns** to reduce matches\n- **Batch events** when publishing (up to 10 per call)\n- **Archive selectively** — not all events\n\n## Troubleshooting\n\n### Rule Not Triggering\n\n**Debug:**\n\n```bash\n# Check rule status\naws events describe-rule --name my-rule\n\n# Check targets\naws events list-targets-by-rule --rule my-rule\n\n# Test event pattern\naws events test-event-pattern \\\n  --event-pattern '{\"source\": [\"my-app\"]}' \\\n  --event '{\"source\": \"my-app\", \"detail-type\": \"Test\"}'\n```\n\n**Common causes:**\n- Rule disabled\n- Event pattern doesn't match\n- Target permissions missing\n\n### Lambda Not Invoked\n\n**Check Lambda permissions:**\n\n```bash\naws lambda get-policy --function-name MyFunction\n```\n\n**Required permission:**\n\n```json\n{\n  \"Principal\": \"events.amazonaws.com\",\n  \"Action\": \"lambda:InvokeFunction\",\n  \"Resource\": \"function-arn\",\n  \"Condition\": {\n    \"ArnLike\": {\n      \"AWS:SourceArn\": \"rule-arn\"\n    }\n  }\n}\n```\n\n### Events Not Reaching Custom Bus\n\n**Check:**\n- Publishing to correct bus name\n- Event format is valid JSON\n- Put events has proper permissions\n\n```bash\n# Test publish\naws events put-events \\\n  --entries '[{\n    \"Source\": \"test\",\n    \"DetailType\": \"Test Event\",\n    \"Detail\": \"{}\",\n    \"EventBusName\": \"my-app-events\"\n  }]'\n```\n\n### Viewing Failed Events\n\n```bash\n# Enable CloudWatch metrics\naws events put-rule \\\n  --name my-rule \\\n  --event-pattern '...' \\\n  --state ENABLED\n\n# Check FailedInvocations metric\naws cloudwatch get-metric-statistics \\\n  --namespace AWS/Events \\\n  --metric-name FailedInvocations \\\n  --dimensions Name=RuleName,Value=my-rule \\\n  --start-time $(date -d '1 hour ago' -u +%Y-%m-%dT%H:%M:%SZ) \\\n  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \\\n  --period 300 \\\n  --statistics Sum\n```\n\n## References\n\n- [EventBridge User Guide](https://docs.aws.amazon.com/eventbridge/latest/userguide/)\n- [EventBridge API Reference](https://docs.aws.amazon.com/eventbridge/latest/APIReference/)\n- [EventBridge CLI Reference](https://docs.aws.amazon.com/cli/latest/reference/events/)\n- [boto3 EventBridge](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/events.html)\n- [Event Pattern Reference](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html)","author":"@itsmostafa","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/itsmostafa/aws-agent-skills/tree/main/skills/eventbridge","license":"MIT","category":"productivity","lang":"en","tokens":2335,"stars":0,"calls30d":2,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"event-patterns.md","size":7573,"sha256":"0db6525a92b99445e7dcf56333d054cb11f724d79d53231ff076e245c86a59c0"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":["boto3.amazonaws.com","docs.aws.amazon.com"]}}