Guide · Amazon QuickSight · Data Sources & SPICE Datasets
QuickSight Data Sources and SPICE Datasets for MCP Servers — CreateDataSourceCommand, ImportMode, Row-Level Security
Before QuickSight can visualize your data it needs two resources: a data source (the connection to Redshift, RDS, Athena, S3, or another system) and a dataset (the specific tables, SQL, and transformations drawn from that source). For MCP server teams, managing both programmatically means you can provision analytics infrastructure as part of your deployment pipeline — no console clicks required. This guide covers every data source type supported by CreateDataSourceCommand, the SPICE vs DIRECT_QUERY tradeoff, the PhysicalTableMap and LogicalTableMap data model, ingestion polling, and how to layer row-level security (RLS) so each tenant sees only their own endpoint metrics.
TL;DR
Create a data source with CreateDataSourceCommand (choosing Type and the appropriate DataSourceParameters variant), then create a dataset with CreateDataSetCommand using PhysicalTableMap (table or SQL) and LogicalTableMap (renames, calculated fields, joins). Set ImportMode: "SPICE" for in-memory performance or "DIRECT_QUERY" for live results. After creation, trigger an ingestion with CreateIngestionCommand and poll DescribeIngestionCommand until IngestionStatus === "COMPLETED". Add row-level security via CreateRowLevelPermissionDataSetCommand to restrict rows per user or group.
Data source types
The Type field in CreateDataSourceCommand determines which DataSourceParameters variant you use. All types supported by AWS SDK v3:
| Type value | Use case | Parameters struct |
|---|---|---|
REDSHIFT | Amazon Redshift cluster or Serverless | RedshiftParameters (host, port, database, clusterId) |
AURORA | Aurora MySQL | AuroraParameters (host, port, database) |
AURORA_POSTGRESQL | Aurora PostgreSQL | AuroraPostgreSqlParameters (host, port, database) |
RDS | RDS MySQL, PostgreSQL, SQL Server, MariaDB, Oracle | RdsParameters (instanceId, database) |
MYSQL | Self-managed MySQL (not RDS) | MySqlParameters (host, port, database) |
POSTGRESQL | Self-managed PostgreSQL | PostgreSqlParameters (host, port, database) |
SQLSERVER | Microsoft SQL Server | SqlServerParameters (host, port, database) |
ORACLE | Oracle Database | OracleParameters (host, port, database) |
ATHENA | Amazon Athena (S3-based queries) | AthenaParameters (workGroup) |
S3 | CSV / JSON files in S3 | S3Parameters (ManifestFileLocation) |
SNOWFLAKE | Snowflake data warehouse | SnowflakeParameters (host, database, warehouse) |
BIGQUERY | Google BigQuery | BigQueryParameters (projectId, dataSetRegion) |
DATABRICKS | Databricks SQL warehouse | DatabricksParameters (host, port, sqlEndpointPath) |
TIMESTREAM | Amazon Timestream time-series database | TimestreamParameters (database) |
Creating a Redshift data source
Redshift is the most common data source for MCP server analytics — it stores aggregated metrics that would be too large to query live from QuickSight. The VpcConnectionArn field routes traffic through a VPC connection when the Redshift cluster is not publicly accessible:
import {
QuickSightClient,
CreateDataSourceCommand,
DescribeDataSourceCommand
} from "@aws-sdk/client-quicksight";
const qs = new QuickSightClient({ region: "us-east-1" });
const ACCOUNT_ID = process.env.AWS_ACCOUNT_ID;
const { DataSourceArn } = await qs.send(new CreateDataSourceCommand({
AwsAccountId: ACCOUNT_ID,
DataSourceId: "mcp-metrics-redshift",
Name: "MCP Metrics (Redshift)",
Type: "REDSHIFT",
DataSourceParameters: {
RedshiftParameters: {
Host: "mcp-cluster.abc123.us-east-1.redshift.amazonaws.com",
Port: 5439,
Database: "metrics",
ClusterId: "mcp-cluster",
},
},
Credentials: {
// Use SecretArn in production to avoid storing plaintext credentials
SecretArn: "arn:aws:secretsmanager:us-east-1:123456789012:secret:quicksight/redshift-XYZ",
},
SslProperties: { DisableSsl: false },
Permissions: [{
Principal: `arn:aws:quicksight:us-east-1:${ACCOUNT_ID}:user/default/automation-user`,
Actions: [
"quicksight:DescribeDataSource",
"quicksight:DescribeDataSourcePermissions",
"quicksight:PassDataSource",
],
}],
Tags: [{ Key: "project", Value: "alivemcp" }],
}));
console.log("Data source ARN:", DataSourceArn);
The Permissions array controls which QuickSight users (not IAM users) can use this data source when building analyses. At minimum, the user creating datasets from this source needs quicksight:PassDataSource.
Creating an Athena data source
For MCP teams storing logs in S3 and querying them with Athena, the data source is simpler — just reference the workgroup:
await qs.send(new CreateDataSourceCommand({
AwsAccountId: ACCOUNT_ID,
DataSourceId: "mcp-logs-athena",
Name: "MCP Logs (Athena)",
Type: "ATHENA",
DataSourceParameters: {
AthenaParameters: {
WorkGroup: "mcp-analytics",
// Optional: RoleArn for cross-account Athena access
},
},
// No Credentials needed for Athena — uses IAM role of the QuickSight service role
Permissions: [{
Principal: `arn:aws:quicksight:us-east-1:${ACCOUNT_ID}:user/default/automation-user`,
Actions: ["quicksight:DescribeDataSource", "quicksight:PassDataSource"],
}],
}));
The QuickSight service role needs Athena and S3 permissions to execute queries and read results. Use the AWSQuicksightAthenaAccess managed policy or scope it to specific workgroups and buckets. See the Athena workgroups guide for workgroup setup including per-workgroup S3 output paths.
VPC connections for private data sources
When your Redshift cluster, RDS instance, or self-managed database is in a VPC with no public endpoint, create a QuickSight VPC connection first:
import { CreateVPCConnectionCommand } from "@aws-sdk/client-quicksight";
await qs.send(new CreateVPCConnectionCommand({
AwsAccountId: ACCOUNT_ID,
VPCConnectionId: "mcp-vpc",
Name: "MCP Production VPC",
SubnetIds: ["subnet-aaa111", "subnet-bbb222"],
SecurityGroupIds: ["sg-ccc333"],
DnsResolvers: [], // optional custom DNS servers
RoleArn: "arn:aws:iam::123456789012:role/QuickSightVPCRole",
}));
Then reference the VPC connection in your data source: add VpcConnectionProperties: { VpcConnectionArn: "arn:aws:quicksight:..." } to the CreateDataSourceCommand call. The RoleArn must have EC2 permissions to describe and create ENIs in the specified subnets.
Creating a dataset with PhysicalTableMap and LogicalTableMap
A QuickSight dataset defines what data to pull and how to transform it. The PhysicalTableMap maps string keys to either a RelationalTable (a named table or view), a CustomSql (arbitrary SQL), or an S3Source (CSV manifest). The LogicalTableMap then references physical tables and applies column renames, type overrides, calculated fields, and join definitions:
import { CreateDataSetCommand } from "@aws-sdk/client-quicksight";
const { DataSetArn } = await qs.send(new CreateDataSetCommand({
AwsAccountId: ACCOUNT_ID,
DataSetId: "mcp-endpoint-metrics",
Name: "MCP Endpoint Metrics",
ImportMode: "SPICE", // or "DIRECT_QUERY"
PhysicalTableMap: {
"endpoint-checks": {
CustomSql: {
DataSourceArn: DataSourceArn,
Name: "endpoint-checks",
SqlQuery: `
SELECT
endpoint_id,
check_time,
response_ms,
status_code,
is_up,
region
FROM mcp_checks
WHERE check_time >= DATEADD(day, -30, GETDATE())
`,
Columns: [
{ Name: "endpoint_id", Type: "STRING" },
{ Name: "check_time", Type: "DATETIME" },
{ Name: "response_ms", Type: "INTEGER" },
{ Name: "status_code", Type: "INTEGER" },
{ Name: "is_up", Type: "BIT" },
{ Name: "region", Type: "STRING" },
],
},
},
},
LogicalTableMap: {
"endpoint-metrics-logical": {
Alias: "EndpointMetrics",
Source: { PhysicalTableId: "endpoint-checks" },
DataTransforms: [
{
RenameColumnOperation: {
ColumnName: "response_ms",
NewColumnName: "Response Time (ms)",
},
},
{
CastColumnTypeOperation: {
ColumnName: "is_up",
NewColumnType: "BOOLEAN",
},
},
{
CreateColumnsOperation: {
Columns: [{
ColumnName: "uptime_pct",
ColumnId: "uptime_pct",
Expression: "ifelse(is_up = 1, 1.0, 0.0)",
}],
},
},
],
},
},
Permissions: [{
Principal: `arn:aws:quicksight:us-east-1:${ACCOUNT_ID}:user/default/automation-user`,
Actions: [
"quicksight:DescribeDataSet",
"quicksight:DescribeDataSetPermissions",
"quicksight:PassDataSet",
"quicksight:DescribeIngestion",
"quicksight:ListIngestions",
],
}],
}));
console.log("Dataset ARN:", DataSetArn);
Column types in the Columns array of a CustomSql must be one of: STRING, INTEGER, DECIMAL, DATETIME, BIT, BOOLEAN, JSON. The DATETIME type is a string — it covers all timestamp/date/time variants. QuickSight infers the actual temporal precision during SPICE import.
SPICE vs DIRECT_QUERY
| Mode | Performance | Freshness | Cost model | Best for |
|---|---|---|---|---|
SPICE | Sub-second (in-memory) | As fresh as last ingestion (manual or scheduled) | $0.25/GB/month storage | Large datasets, dashboard responsiveness, concurrent viewers |
DIRECT_QUERY | Depends on source (ms to seconds) | Always current | No SPICE cost; source query costs apply | Small tables, compliance (data must stay at source), real-time |
For MCP server operational metrics, SPICE is almost always the right choice: pre-aggregated metrics tables are small (under a few GB) and sub-second dashboard loads matter for adoption. The 30-day history query in the example above will typically produce a SPICE dataset well under 1 GB — costing $0.25/month in storage.
SPICE ingestion — triggering and polling
When you create a SPICE dataset, QuickSight does not automatically load data. You trigger the initial load and any subsequent refreshes explicitly:
import { CreateIngestionCommand, DescribeIngestionCommand } from "@aws-sdk/client-quicksight";
const ingestionId = `refresh-${Date.now()}`;
await qs.send(new CreateIngestionCommand({
AwsAccountId: ACCOUNT_ID,
DataSetId: "mcp-endpoint-metrics",
IngestionId: ingestionId,
IngestionType: "FULL_REFRESH", // or "INCREMENTAL_REFRESH"
}));
// Poll until complete
while (true) {
const { Ingestion } = await qs.send(new DescribeIngestionCommand({
AwsAccountId: ACCOUNT_ID,
DataSetId: "mcp-endpoint-metrics",
IngestionId: ingestionId,
}));
console.log("Status:", Ingestion.IngestionStatus,
"Rows:", Ingestion.RowInfo?.RowsIngested ?? 0);
if (Ingestion.IngestionStatus === "COMPLETED") {
console.log("Ingested", Ingestion.RowInfo.RowsIngested, "rows");
break;
}
if (Ingestion.IngestionStatus === "FAILED") {
throw new Error(Ingestion.ErrorInfo?.Message);
}
await new Promise(r => setTimeout(r, 15_000)); // 15s poll
}
Ingestion statuses: INITIALIZED → QUEUED → RUNNING → COMPLETED or FAILED. For large datasets (100M+ rows), ingestion can take 10–30 minutes. For the small metrics tables typical in MCP server deployments, 15–60 seconds is typical. Set up a CloudWatch Events rule or EventBridge schedule to trigger CreateIngestionCommand nightly so dashboards are always current when users arrive in the morning.
Incremental refresh for large time-series
For datasets with hundreds of millions of rows where full refresh is too slow, configure incremental refresh. QuickSight needs to know which datetime column marks new rows and what window to reload:
import { UpdateDataSetCommand } from "@aws-sdk/client-quicksight";
await qs.send(new UpdateDataSetCommand({
AwsAccountId: ACCOUNT_ID,
DataSetId: "mcp-endpoint-metrics",
Name: "MCP Endpoint Metrics",
ImportMode: "SPICE",
PhysicalTableMap: { /* same as above */ },
LogicalTableMap: { /* same as above */ },
DataSetUsageConfiguration: {
DisableUseAsDirectQuerySource: false,
DisableUseAsImportedSource: false,
},
DatasetParameters: [{
DateTimeDatasetParameter: {
Id: "refresh-window-start",
Name: "RefreshWindowStart",
ValueType: "SINGLE_VALUED",
TimeGranularity: "HOUR",
DefaultValues: { StaticValues: ["2026-01-01T00:00:00"] },
},
}],
}));
Row-level security (RLS) datasets
Row-level security lets a single QuickSight dataset serve multiple tenants. Each user or group only sees rows that match their identity. RLS works through a separate "rules dataset" — a CSV or table that maps QuickSight usernames (or groups) to field values that filter the main dataset:
Example rules table content (CSV in S3 or a table in your data source):
UserName,endpoint_id
alice@example.com,ep_001
alice@example.com,ep_002
bob@example.com,ep_003
When Alice views a dashboard, QuickSight automatically appends WHERE endpoint_id IN ('ep_001','ep_002') to every query — without Alice knowing the filter exists.
import { CreateRowLevelPermissionDataSetCommand } from "@aws-sdk/client-quicksight";
await qs.send(new CreateRowLevelPermissionDataSetCommand({
AwsAccountId: ACCOUNT_ID,
DataSetId: "mcp-endpoint-metrics",
Namespace: "default",
PermissionPolicy: "GRANT_ACCESS", // or "DENY_ACCESS"
Arn: rlsDatasetArn, // ARN of the rules dataset (must be SPICE, same account)
FormatVersion: "VERSION_2", // VERSION_2 supports group names
Status: "ENABLED",
}));
The FormatVersion: "VERSION_2" rules dataset supports both a UserName column (for individual users) and a GroupName column (for group-based filtering). Using groups scales better for large tenants — add all users for a tenant to a QuickSight group, then one row in the rules table grants access to all group members.
To disable RLS (e.g., for admin users who should see all data), call DeleteRowLevelPermissionDataSetCommand and re-enable it after the privileged session. Alternatively, add an all-access row for admin users to the rules dataset with a wildcard: set the filter column to * in the rules table (not supported by all source types — test with your specific data source).
Scheduled SPICE refresh via EventBridge
Rather than triggering refreshes manually, wire an EventBridge Scheduler rule to invoke a Lambda that calls CreateIngestionCommand:
// Lambda handler (triggered by EventBridge Scheduler daily at 06:00 UTC)
export const handler = async () => {
const qs = new QuickSightClient({ region: "us-east-1" });
const ingestionId = `scheduled-${new Date().toISOString().slice(0, 10)}`;
await qs.send(new CreateIngestionCommand({
AwsAccountId: process.env.ACCOUNT_ID,
DataSetId: process.env.DATASET_ID,
IngestionId: ingestionId,
IngestionType: "FULL_REFRESH",
}));
return { ingestionId };
};
This keeps the dataset fresh without coupling your MCP server to a cron job. The Lambda's execution role needs only quicksight:CreateIngestion — a narrow permission that cannot modify data source credentials or access other QuickSight resources.
Key gotchas
- Column names in PhysicalTableMap must match SQL aliases exactly: If your SQL aliases a column as
"Response Time (ms)", theColumnsarray must use that exact string including spaces and parentheses. Mismatches throwInvalidColumnInfoException. - DIRECT_QUERY datasets cannot use row-level security via RLS dataset: RLS only works with SPICE datasets. For DIRECT_QUERY, enforce tenant isolation at the data source level (Redshift views with session context, RDS row security policies).
- SecretArn is preferred over CredentialPair:
CredentialPairstores credentials in QuickSight's internal metadata.SecretArnstores a reference to Secrets Manager — credentials rotate without touching the data source configuration. Use Secrets Manager for all production data sources. See the RDS secret rotation guide for rotation setup. - Dataset IDs must be unique within an account-region: You cannot reuse a DataSetId after deletion until QuickSight fully purges the resource (usually a few minutes). Use a naming convention like
project-entity-environmentand avoid reuse in rapid CI/CD loops. - RLS rules dataset must have ImportMode: SPICE: You cannot use a DIRECT_QUERY dataset as an RLS rules table. Import the rules dataset to SPICE and refresh it whenever user-tenant mappings change.
Continue in this series
- QuickSight overview for MCP servers — SDK quick start, account subscription, five-layer hierarchy, IAM setup
- Analyses and dashboard publishing — CreateAnalysisCommand, CreateDashboardCommand, versioning, assets-as-code, themes
- Embedding QuickSight in agent UIs — embedding-sdk v2, anonymous vs registered embed, namespaces, RLS, allowed domains
Related data guides: Redshift with MCP servers · Athena workgroups · RDS Data API · S3 for MCP servers