Guide · Amazon Forecast · Dataset Schema & Import
Amazon Forecast Dataset Import for MCP Servers — Schema Design, S3 CSV Format, and Timestamp Gotchas
Amazon Forecast requires structured time-series data uploaded to S3 before training begins. The schema design step is where most teams hit their first wall: attribute names must be lowercase, the timestamp format string must match your CSV exactly character-by-character, and missing time steps are silently skipped unless you configure fill transformations. This guide covers CreateDatasetCommand, the three dataset types (target time series, related time series, item metadata), S3 CSV formatting rules, CreateDatasetImportJobCommand params, and how to wire datasets into the dataset group.
TL;DR
- Schema attribute names are lowercase:
item_id,timestamp,target_value— notITEM_ID. Uppercase names fail validation. - TimestampFormat must match your CSV exactly: a single missing second field (
HH:mmvsHH:mm:ss) causes the import to "succeed" with zero rows loaded. Always verify row count after import. - Wire datasets into the group:
UpdateDatasetGroupCommand(or the initialCreateDatasetGroupCommandDatasetArnsfield) — datasets created standalone are invisible to the predictor until associated. - Missing rows in target series are gaps, not zeros: configure
AttributeConfigsfill transforms on the predictor, not on the dataset import job, to control how gaps are handled during training.
Dataset types and when to use each
A Forecast dataset group supports up to three dataset types. Each type has different schema requirements and plays a different role in the model:
TARGET_TIME_SERIES (required)
The values you want Forecast to predict. Required columns: item_id (string), timestamp (timestamp), target_value (float). Every other column is a custom covariate. For MCP server monitoring:
item_id= your endpoint slug (e.g."weather-mcp-prod")target_value= request count per interval, latency p95 in milliseconds, or error rate percentage
Choose target_value as the metric that most directly represents what you want to predict — you cannot change it after the dataset is created without deleting and recreating the dataset.
RELATED_TIME_SERIES (optional)
Additional time series that co-vary with your target — these are covariates the model uses during training. Required columns: item_id (string), timestamp (timestamp), plus at least one additional float column. The related time series must:
- Cover the same items and time range as the target time series
- Extend through the entire forecast horizon (future values must be known at query time, or you use a "featurization" step to impute them)
For MCP monitoring, useful related time series include: upstream dependency error rates (if endpoint A's errors predict endpoint B's failures), deployment event flags (0 or 1 per hour), or external API quota consumption rates.
ITEM_METADATA (optional)
Static attributes per item — these don't vary over time. Required column: item_id (string), plus any string or float columns. Examples: endpoint category ("REST", "SSE", "stdio"), cloud provider, region, tier. Item metadata is included as categorical features and helps the model generalize across items with similar attributes.
Creating a dataset with CreateDatasetCommand
import { CreateDatasetCommand } from "@aws-sdk/client-forecast";
const { DatasetArn } = await forecast.send(new CreateDatasetCommand({
DatasetName: "mcp-endpoint-requests",
Domain: "CUSTOM", // must match the dataset group's Domain
DatasetType: "TARGET_TIME_SERIES",
DataFrequency: "H", // "Y"|"M"|"W"|"D"|"H"|"30min"|"15min"|"10min"|"5min"|"1min"
Schema: {
Attributes: [
{ AttributeName: "item_id", AttributeType: "string" },
{ AttributeName: "timestamp", AttributeType: "timestamp" },
{ AttributeName: "target_value", AttributeType: "float" },
// Optional extra float covariate:
// { AttributeName: "error_rate", AttributeType: "float" },
],
},
Tags: [{ Key: "project", Value: "alivemcp" }],
}));
console.log("Dataset ARN:", DatasetArn);
Schema attribute name rules
- Must be lowercase:
item_idnotITEM_ID,target_valuenotTARGET_VALUE. The validation error message is misleading ("Invalid schema") — always check case first. - Must start with a letter and contain only letters, digits, underscores.
item_id,timestamp,target_valueare reserved names for the target time series — do not use them for custom columns.- For related time series and item metadata, the
item_idcolumn is still required (same name). Custom column names can be anything lowercase that doesn't conflict with reserved names.
DataFrequency values
| Code | Interval | Typical use |
|---|---|---|
"1min" | 1 minute | High-frequency endpoint metrics |
"5min" | 5 minutes | MCP health check ping data |
"H" | 1 hour | Request-per-hour traffic patterns |
"D" | 1 day | Daily active user counts |
"W" | 1 week | Weekly trend analysis |
DataFrequency is immutable after dataset creation. If your data granularity changes, you must create a new dataset.
S3 CSV format
Forecast imports data from CSV files in S3. The required format:
- No header row — the schema defines column order
- Column order must match the schema
Attributesarray order exactly - Timestamps must use the format specified in
TimestampFormat - UTF-8 encoding; gzip-compressed files (.gz) are supported
- File can be split across multiple objects in one S3 prefix; Forecast imports all objects at the prefix
Example CSV for the schema above (item_id, timestamp, target_value):
weather-mcp-prod,2026-01-01 00:00:00,142
weather-mcp-prod,2026-01-01 01:00:00,98
weather-mcp-prod,2026-01-01 02:00:00,67
maps-mcp-prod,2026-01-01 00:00:00,312
maps-mcp-prod,2026-01-01 01:00:00,289
Upload to S3 before creating the import job:
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { createReadStream } from "fs";
const s3 = new S3Client({ region: "us-east-1" });
await s3.send(new PutObjectCommand({
Bucket: "my-forecast-data",
Key: "mcp-endpoints/target-2026.csv",
Body: createReadStream("./target-2026.csv"),
}));
Running CreateDatasetImportJobCommand
import { CreateDatasetImportJobCommand } from "@aws-sdk/client-forecast";
const { DatasetImportJobArn } = await forecast.send(new CreateDatasetImportJobCommand({
DatasetImportJobName: "mcp-target-2026-import",
DatasetArn,
DataSource: {
S3Config: {
Path: "s3://my-forecast-data/mcp-endpoints/", // S3 prefix — imports ALL objects here
RoleArn: "arn:aws:iam::123456789012:role/ForecastS3ReadRole",
},
},
TimestampFormat: "yyyy-MM-dd HH:mm:ss",
// Other common formats:
// "yyyy-MM-dd" → "2026-01-15"
// "yyyy-MM-dd'T'HH:mm:ss" → "2026-01-15T14:00:00"
// "MM/dd/yyyy HH:mm" → "01/15/2026 14:00"
ImportMode: "FULL", // "FULL" replaces all data; "INCREMENTAL" appends new rows
// TimeZone: "UTC", // only needed if timestamps are local time, not UTC
}));
CRITICAL: TimestampFormat matching
The TimestampFormat string must match your CSV data character-for-character. The import job will return Status: "ACTIVE" even if zero rows were parsed — there is no row count in the success response. Always verify:
import { DescribeDatasetImportJobCommand } from "@aws-sdk/client-forecast";
// Poll until complete
let importJob;
while (true) {
importJob = await forecast.send(new DescribeDatasetImportJobCommand({
DatasetImportJobArn,
}));
if (importJob.Status === "ACTIVE" || importJob.Status === "CREATE_FAILED") break;
await new Promise(r => setTimeout(r, 30_000));
}
if (importJob.Status === "CREATE_FAILED") {
throw new Error(`Import failed: ${importJob.Message}`);
}
// CRITICAL: check that rows were actually imported
console.log("Data size:", importJob.DataSize); // bytes imported
console.log("Field stats:", importJob.FieldStatistics); // per-column stats
// If DataSize is 0 or FieldStatistics.target_value.Count is 0,
// your TimestampFormat doesn't match the CSV — no error thrown, just 0 rows.
The FieldStatistics map includes Count, Min, Max, and CountNan per column. If FieldStatistics.target_value.Count === 0, the entire import silently failed due to format mismatch.
Common TimestampFormat mistakes
| CSV data example | Correct format | Common mistake |
|---|---|---|
2026-01-15 14:00:00 | yyyy-MM-dd HH:mm:ss | yyyy-MM-dd HH:mm (missing :ss) |
2026-01-15 | yyyy-MM-dd | yyyy/MM/dd (wrong separator) |
2026-01-15T14:00:00 | yyyy-MM-dd'T'HH:mm:ss | yyyy-MM-dd HH:mm:ss (space vs T) |
01/15/2026 14:00 | MM/dd/yyyy HH:mm | dd/MM/yyyy HH:mm (day/month order) |
IAM role for S3 access
The RoleArn in S3Config must be assumable by the Forecast service and have S3 read permissions:
// Trust policy (allow Forecast service to assume this role)
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "forecast.amazonaws.com" },
"Action": "sts:AssumeRole"
}]
}
// Permission policy
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": [
"arn:aws:s3:::my-forecast-data",
"arn:aws:s3:::my-forecast-data/*"
]
}]
}
For export jobs (CreateForecastExportJobCommand), the same role also needs s3:PutObject.
Wiring datasets into the dataset group
Creating a dataset does not automatically associate it with a dataset group. You must either pass DatasetArns at dataset group creation time, or update the group afterward:
import { UpdateDatasetGroupCommand } from "@aws-sdk/client-forecast";
// Add all datasets to the group at once — this replaces the full list
await forecast.send(new UpdateDatasetGroupCommand({
DatasetGroupArn,
DatasetArns: [
targetDatasetArn,
relatedDatasetArn, // optional
metadataDatasetArn, // optional
],
}));
The predictor training stage references only the DatasetGroupArn — it discovers all associated datasets automatically. If you forget to wire a dataset into the group, the predictor trains without it and you won't get an error — it just trains on less data.
INCREMENTAL imports and re-training
To append new rows without replacing existing data, use ImportMode: "INCREMENTAL":
await forecast.send(new CreateDatasetImportJobCommand({
DatasetImportJobName: `mcp-target-${Date.now()}-incremental`,
DatasetArn,
DataSource: {
S3Config: {
Path: "s3://my-forecast-data/mcp-endpoints/incremental/",
RoleArn,
},
},
TimestampFormat: "yyyy-MM-dd HH:mm:ss",
ImportMode: "INCREMENTAL",
}));
Incremental imports update the dataset, but existing predictors do not automatically retrain on the new data. After an incremental import, you must create a new predictor (or use RetrainingFrequency on an AutoPredictor) to incorporate the new data into forecasts.
Automatic retraining with AutoPredictor
The CreateAutoMLPredictorCommand supports a DataConfig.AdditionalDatasets parameter where you configure automatic retraining frequency so that incremental imports trigger model updates on a schedule rather than requiring manual predictor recreation. This is covered in the predictor training guide.
Continue in this series
- Amazon Forecast overview — pipeline stages, domain selection, two-SDK setup, pricing
- Predictor training and AutoML — CreateAutoMLPredictorCommand, ForecastHorizon, weather signals, accuracy metrics
- Generating and querying forecasts — CreateForecastCommand, QueryForecastCommand, percentile bands
Related guides: S3 for MCP server storage · IAM roles for MCP servers