# eb-event-source-management

Part of **EB**

# EventBridge Event Sources

## Capabilities Overview

| Sub-capability | Calling Mode | Description |
|----------------|--------------|-------------|
| Test Event Source Configuration | Synchronous | Checks whether the event source configuration is active. Returns a list of all external event sources and validates the connection parameters for MySQL-based event sources. |

## API Calling Patterns

### Authentication
The primary authentication method is Bearer Token authentication.

- Include the header: `Authorization: Bearer <your_api_key>`
- Store your API key in the environment variable: `DASHSCOPE_API_KEY`

While other Alibaba Cloud authentication mechanisms may exist, Bearer Token is the recommended method for this API based on documentation examples.

### Service Endpoint
The API uses region-agnostic global endpoints:

- China region: `https://api.aliyun.com/api/eventbridge/2020-04-01/TestEventSourceConfig`
- International region: `https://api.alibabacloud.com/api/eventbridge/2020-04-01/TestEventSourceConfig`

Both endpoints accept POST requests and return immediate JSON responses.

### Synchronous Request Pattern
This API follows a synchronous calling pattern:

1. Send a POST request to the appropriate endpoint with the event source configuration in the request body
2. Include the `Authorization: Bearer <token>` header
3. The service immediately validates the configuration and returns a complete response
4. Parse the response to check the `Success` field and inspect individual `Data` items for detailed diagnostics

No polling or asynchronous handling is required.

## Parameter Reference

### Test Event Source Configuration

| Parameter | Type | Required | Default | Constraints | Description |
|----------|------|----------|---------|-------------|-------------|
| SourceMySQLParameters | object | false | null | — | The parameters for the MySQL source. |
| RegionId | string | false | null | — | The region ID. |
| HostName | string | false | null | — | The database endpoint. |
| Port | integer | false | null | — | The database connection port. |
| DatabaseName | string | false | null | — | The database name. |
| TableNames | string | false | null | — | The table name. The name must be prefixed with the database name in the ${DatabaseName}.${TableName} format. |
| User | string | false | null | — | The username for the database. |
| Password | string | false | null | — | The password for the specified username. |
| NetworkType | string | false | null | one of: PrivateNetwork, PublicNetwork | The network type. |
| VpcId | string | false | null | — | The VPC ID. |
| VSwitchIds | string | false | null | — | The vSwitch IDs. |
| SecurityGroupId | string | false | null | — | The security group ID. |
| AllowedCIDRs | string | false | null | — | The list of allowed CIDR blocks. |
| SnapshotMode | string | false | null | — | The snapshot mode. |

## Code Examples

### Test MySQL Event Source Configuration - JSON Request

```json
{
  "Code": "Success",
  "Data": [
    {
      "CheckItem": "CHECK_CONNECTION",
      "ErrorMsg": "Connection established successfully.",
      "IsSucceed": "true"
    }
  ],
  "Message": "Success",
  "RequestId": "FF942675-F937-549C-A942-EB94FFE28DD3",
  "Success": true
}
```

### Test Event Source via cURL - China Region

```bash
curl -X POST https://api.aliyun.com/api/eventbridge/2020-04-01/TestEventSourceConfig \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "HostName": "mydb.example.com",
    "Port": 3306,
    "DatabaseName": "mydb",
    "User": "testuser",
    "Password": "testpass",
    "NetworkType": "PublicNetwork"
  }'
```

### Test Event Source via cURL - International Region

```bash
curl -X POST https://api.alibabacloud.com/api/eventbridge/2020-04-01/TestEventSourceConfig \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "HostName": "mydb.example.com",
    "Port": 3306,
    "DatabaseName": "mydb",
    "User": "testuser",
    "Password": "testpass",
    "NetworkType": "PrivateNetwork",
    "VpcId": "vpc-12345",
    "VSwitchIds": "vsw-67890",
    "SecurityGroupId": "sg-abcde"
  }'
```

### Python Example Using requests

```python
import os
import requests

api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://api.aliyun.com/api/eventbridge/2020-04-01/TestEventSourceConfig"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

payload = {
    "HostName": "mydb.example.com",
    "Port": 3306,
    "DatabaseName": "mydb",
    "User": "testuser",
    "Password": "testpass",
    "NetworkType": "PublicNetwork"
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```

## Response Format

```json
{
  "Code": "Success",
  "Data": [
    {
      "CheckItem": "CHECK_CONNECTION",
      "ErrorMsg": "Connection established successfully.",
      "IsSucceed": "true"
    }
  ],
  "Message": "Success",
  "RequestId": "FF942675-F937-549C-A942-EB94FFE28DD3",
  "Success": true
}
```

**Key Fields**:
- `Success` — Indicates whether the overall request succeeded (true/false)
- `Code` — Standardized status code ("Success" for success)
- `Message` — Human-readable status message
- `RequestId` — Unique identifier for troubleshooting
- `Data` — Array of individual validation checks
- `CheckItem` — Name of the specific validation performed
- `IsSucceed` — Whether that specific check passed ("true"/"false")
- `ErrorMsg` — Detailed error message if the check failed

## Error Handling

| Error Code | Description | Recommended Action |
|------------|-------------|-------------------|
| 403 | ServiceNotEnable: The service is not enabled. Ensure that the EventBridge service is activated in your account. | Activate the EventBridge service in your Alibaba Cloud account before using this API. |

## Pricing & Billing

### Billing Model
Per-request billing: each API call is charged regardless of success or failure.

### Price Reference

| Tier | Input Price | Output Price |
|------|-------------|--------------|
| default | 0.001 / | 0.001 / |

### Free Tier
Monthly free quota of 100 calls.

### Usage Limits
Maximum 8192 characters per request.

### Billing Notes
Charged per call—both successful and failed requests incur costs.

## FAQ

Q: What types of event sources can I test with this API?
A: The API specifically validates MySQL-based event sources, checking connectivity, credentials, and network configuration (VPC, security groups, etc.).

Q: Do I need to enable any services before using this API?
A: Yes, you must activate the EventBridge service in your Alibaba Cloud account. Otherwise, you'll receive a 403 ServiceNotEnable error.

Q: How do I handle private network (VPC) databases?
A: Set `NetworkType` to "PrivateNetwork" and provide `VpcId`, `VSwitchIds`, and `SecurityGroupId` parameters to allow EventBridge to connect through your VPC.

Q: Is the API call asynchronous?
A: No, this is a synchronous API—all validation results are returned immediately in the response.

Q: Are there any free calls available?
A: Yes, you get 100 free calls per month. After that, each call costs 0.001 .