Skip to main content

Overview

The /api/sync-history endpoint retrieves a list of recent ingestion jobs from AWS Bedrock Knowledge Base. This is useful for viewing past synchronization attempts, their statuses, and timestamps.

Endpoint

POST /api/sync-history

Request Body

The request must be sent as JSON:
region
string
required
AWS region where your Knowledge Base is located (e.g., us-east-1)
knowledgeBaseId
string
required
The unique identifier of your Bedrock Knowledge Base
dataSourceId
string
required
The unique identifier of the data source within the Knowledge Base
accessKeyId
string
required
AWS Access Key ID for authentication
secretAccessKey
string
required
AWS Secret Access Key for authentication
sessionToken
string
Optional AWS Session Token for temporary credentials
maxResults
number
Maximum number of results to return (default: 30, min: 1, max: 100)

Request Example

{
  "region": "us-east-1",
  "knowledgeBaseId": "ABCDEFGHIJ",
  "dataSourceId": "KLMNOPQRST",
  "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
  "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
  "maxResults": 40
}

Response

Success (200 OK)

executions
array
Array of execution objects representing ingestion jobs from AWS
{
  "executions": [
    {
      "id": "aws-abc123xyz",
      "source": "AWS",
      "jobId": "abc123xyz",
      "status": "COMPLETADO",
      "startedAt": "2024-03-05T14:30:00.000Z",
      "finishedAt": "2024-03-05T14:32:15.000Z",
      "logs": [
        "[3/5/2024, 3:00:00 PM] Historial recuperado desde AWS.",
        "Ingestion Job ID: abc123xyz",
        "Estado AWS: COMPLETE",
        "Iniciado: 3/5/2024, 2:30:00 PM",
        "Última actualización: 3/5/2024, 2:32:15 PM"
      ]
    },
    {
      "id": "aws-def456uvw",
      "source": "AWS",
      "jobId": "def456uvw",
      "status": "FALLIDO",
      "startedAt": "2024-03-05T12:00:00.000Z",
      "finishedAt": "2024-03-05T12:01:30.000Z",
      "logs": [
        "[3/5/2024, 1:00:00 PM] Historial recuperado desde AWS.",
        "Ingestion Job ID: def456uvw",
        "Estado AWS: FAILED",
        "Iniciado: 3/5/2024, 12:00:00 PM",
        "Última actualización: 3/5/2024, 12:01:30 PM"
      ]
    }
  ]
}

Status Mapping

The endpoint maps AWS ingestion job statuses to UI-friendly status values:
AWS StatusUI StatusDescription
COMPLETECOMPLETADOJob finished successfully
FAILEDFALLIDOJob failed with an error
IN_PROGRESSEN_EJECUCIONJob is currently running
STARTINGEN_EJECUCIONJob is starting up
OtherPENDIENTEUnknown or pending status

Implementation

const mapAwsStatusToUiStatus = (status?: string): UiSyncStatus => {
  if (status === 'COMPLETE') return 'COMPLETADO';
  if (status === 'FAILED') return 'FALLIDO';
  if (status === 'IN_PROGRESS' || status === 'STARTING') return 'EN_EJECUCION';
  return 'PENDIENTE';
};

Error Responses

400 Bad Request

{
  "error": "Faltan parámetros para consultar historial de sincronización."
}
Returned when required parameters are missing.

500 Internal Server Error

{
  "error": "Error message from AWS or internal error"
}
Returned when there’s an error communicating with AWS or processing the request.

cURL Example

curl -X POST https://your-domain.com/api/sync-history \
  -H "Content-Type: application/json" \
  -d '{
    "region": "us-east-1",
    "knowledgeBaseId": "ABCDEFGHIJ",
    "dataSourceId": "KLMNOPQRST",
    "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
    "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
    "maxResults": 40
  }'

JavaScript Example

const response = await fetch('/api/sync-history', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    region: 'us-east-1',
    knowledgeBaseId: 'ABCDEFGHIJ',
    dataSourceId: 'KLMNOPQRST',
    accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
    secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
    maxResults: 40
  })
});

const data = await response.json();

console.log(`Found ${data.executions.length} historical jobs`);

data.executions.forEach(exec => {
  console.log(`Job ${exec.jobId}: ${exec.status}`);
  console.log(`  Started: ${new Date(exec.startedAt).toLocaleString()}`);
  if (exec.finishedAt) {
    console.log(`  Finished: ${new Date(exec.finishedAt).toLocaleString()}`);
  }
});

Merging with Local Executions

The UI merges executions from this endpoint with local executions from POST /api/sync:
const mergeExecutions = (incomingExecutions) => {
  const map = new Map();

  state.executions.forEach((exec) => {
    if (!exec?.id) return;
    map.set(exec.id, exec);
  });

  (incomingExecutions || []).forEach((exec) => {
    if (!exec?.id) return;
    const previous = map.get(exec.id) || {};
    map.set(exec.id, {
      ...previous,
      ...exec,
      logs: Array.isArray(exec.logs) && exec.logs.length > 0 
        ? exec.logs 
        : previous.logs || []
    });
  });

  state.executions = Array.from(map.values());
};
This ensures:
  • Local executions (from POST /api/sync) are preserved
  • AWS executions are added
  • Local logs are kept if AWS doesn’t provide detailed logs

Use Cases

Audit Trail

Review all past ingestion jobs for auditing and compliance

Troubleshooting

Investigate failed jobs and identify patterns

Performance Monitoring

Track ingestion job durations and success rates

Status Dashboard

Display recent sync activity in a monitoring dashboard

Knowledge Base Sync

Learn about the Knowledge Base sync interface

Start Sync Job

Start a new ingestion job with POST /api/sync

KB Configuration

Configure your Knowledge Base settings

Build docs developers (and LLMs) love