Guide · AWS DataSync · Amazon S3

AWS DataSync with S3 for MCP Servers — Storage Classes, Filters, and Cross-Account Copies

Amazon S3 is the most common DataSync endpoint for MCP server deployments — either as the source (copying existing S3 artifacts into EFS or FSx) or as the destination (archiving MCP server outputs to S3 with specific storage class tiering). This guide covers every parameter of CreateLocationS3Command, the IAM trust policy that DataSync requires to assume the bucket access role, how to scope transfers using SIMPLE_PATTERN filters, and how to wire up cross-account S3 copies where source and destination live in different AWS accounts.

TL;DR

The most common DataSync + S3 error is InvalidRequestException: The source S3 bucket is not accessible — caused by a missing datasync.amazonaws.com entry in the BucketAccessRoleArn trust policy, or an overly-strict aws:SourceAccount condition. The second most common is confusion over VerifyMode: ONLY_FILES_TRANSFERRED verifies the most recently transferred files only (fast), POINT_IN_TIME_CONSISTENT verifies every file in the destination against the source (slow but thorough), and NONE skips verification entirely (fastest but no integrity guarantee). For most MCP server use cases, ONLY_FILES_TRANSFERRED is the right default.

CreateLocationS3 — full parameter reference

import {
  DataSyncClient,
  CreateLocationS3Command,
} from "@aws-sdk/client-datasync";

const datasync = new DataSyncClient({ region: "us-east-1" });

const loc = await datasync.send(new CreateLocationS3Command({
  // Required: S3 bucket ARN (never include a path here — use Subdirectory)
  S3BucketArn: "arn:aws:s3:::my-mcp-artifacts",

  // Optional: transfer only objects under this prefix
  Subdirectory: "/models/llama/",

  // Required: IAM role that DataSync assumes to access the bucket
  S3Config: {
    BucketAccessRoleArn: "arn:aws:iam::123456789012:role/datasync-s3-access",
  },

  // Optional: storage class to use when writing objects to this S3 location
  // (only relevant when this location is the destination)
  S3StorageClass: "INTELLIGENT_TIERING",

  Tags: [{ Key: "project", Value: "mcp-server" }],
}));

The S3BucketArn must be just the bucket ARN — do not append a path or prefix. Use Subdirectory for path scoping. Including a path in the bucket ARN causes InvalidParameterValueException: Bucket ARN is not valid.

BucketAccessRoleArn: IAM trust policy

DataSync assumes the BucketAccessRoleArn role using sts:AssumeRole with the service principal datasync.amazonaws.com. Without the correct trust policy, DataSync cannot access the bucket and the location creation appears to succeed but the task execution immediately fails.

Trust policy

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "datasync.amazonaws.com" },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals": { "aws:SourceAccount": "123456789012" },
      "ArnLike": {
        "aws:SourceArn": "arn:aws:datasync:us-east-1:123456789012:*"
      }
    }
  }]
}

The aws:SourceAccount and aws:SourceArn conditions are optional but strongly recommended — they prevent confused-deputy attacks where another account's DataSync service could assume your role. Without them, any DataSync task in any account could use your role if they somehow obtained the ARN.

Permissions policy on the role

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetBucketLocation",
        "s3:ListBucket",
        "s3:ListBucketMultipartUploads"
      ],
      "Resource": "arn:aws:s3:::my-mcp-artifacts"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:AbortMultipartUpload",
        "s3:DeleteObject",
        "s3:GetObject",
        "s3:ListMultipartUploadParts",
        "s3:PutObject",
        "s3:GetObjectTagging",
        "s3:PutObjectTagging"
      ],
      "Resource": "arn:aws:s3:::my-mcp-artifacts/*"
    }
  ]
}

If this location is source-only (read from S3), you can remove s3:PutObject, s3:DeleteObject, and s3:AbortMultipartUpload. DataSync will refuse to delete objects from a source location regardless of permissions, but following least privilege is good practice.

S3StorageClass selection for destinations

When S3 is the destination, S3StorageClass controls the storage class of newly written objects. This is set at the location level and applies to all objects written by any task using this location as a destination.

S3StorageClass value Min storage duration Retrieval latency Best for
STANDARD None Milliseconds Default; frequently accessed artifacts
STANDARD_IA 30 days Milliseconds Infrequently accessed; min 128 KB objects (smaller objects billed at 128 KB)
ONEZONE_IA 30 days Milliseconds Reproducible data; cheaper than IA, single-AZ durability
INTELLIGENT_TIERING None Milliseconds (Standard/IA tiers); minutes (Archive tier if opted in) Unknown or variable access patterns; monitoring fee of $0.0025/1,000 objects/month
GLACIER_INSTANT_RETRIEVAL 90 days Milliseconds Quarterly-access archives with millisecond retrieval requirement
GLACIER 90 days Minutes to hours Long-term archival; cannot be used as a DataSync source without restore first
DEEP_ARCHIVE 180 days 12 hours 7-10 year regulatory archives; cannot be used as a DataSync source without restore

Critical: if you try to use a bucket containing GLACIER or DEEP_ARCHIVE objects as a DataSync source, those specific objects will show as FilesSkipped or cause the execution to fail with GLACIER_OBJECT_NOT_ACCESSIBLE. You must restore them to Standard first with s3:RestoreObject before DataSync can read them.

Filter patterns: IncludeFilters and ExcludeFilters

Filters scope the transfer to a subset of files. They are set per-task in CreateTaskCommand (or overridden per-execution in StartTaskExecutionCommand).

SIMPLE_PATTERN syntax

import { CreateTaskCommand } from "@aws-sdk/client-datasync";

await datasync.send(new CreateTaskCommand({
  SourceLocationArn: sourceS3Arn,
  DestinationLocationArn: destEfsArn,
  Name: "mcp-models-onnx-only",
  Includes: [
    // Only transfer .onnx and .gguf model files
    { FilterType: "SIMPLE_PATTERN", Value: "*.onnx|*.gguf" },
  ],
  Excludes: [
    // Exclude temp dirs and test fixtures
    { FilterType: "SIMPLE_PATTERN", Value: "_tmp/*|test-fixtures/*|*.tmp" },
  ],
  Options: { VerifyMode: "ONLY_FILES_TRANSFERRED" },
}));

When both Includes and Excludes are specified, Excludes takes precedence: a file matching both an include pattern and an exclude pattern is excluded. This matches the behavior of most file sync tools.

Pattern matching is case-sensitive on Linux file systems (EFS, Lustre) and case-insensitive on Windows/ONTAP SMB locations.

VerifyMode: choosing the right integrity check

VerifyMode controls the VERIFYING phase after transfer. The default is ONLY_FILES_TRANSFERRED for new tasks.

VerifyMode What it checks Time cost Use when
ONLY_FILES_TRANSFERRED Checksums only for files that were transferred in this execution Low (scales with files transferred, not total dataset) Default for most cases; catches write errors during this execution
POINT_IN_TIME_CONSISTENT Checksums every file in the destination against the source, including files not transferred in this run High (scales with total dataset size) First-time migration or after a known source modification event where you need to guarantee destination matches source exactly
NONE No verification; trust the transfer Zero Highest throughput scenarios where you have independent integrity checks downstream, or for large datasets where VERIFYING cost exceeds acceptable time window

POINT_IN_TIME_CONSISTENT is expensive. For a 100 GB dataset with 1 million small files, the VERIFYING phase can take longer than the TRANSFERRING phase because every file requires a checksum read from both source and destination. Use it only when you need to certify that the destination is a byte-exact replica of the source.

OverwriteMode: controlling what happens to existing destination objects

OverwriteMode determines whether DataSync overwrites files that already exist at the destination with the same name but different content.

// Compliance destination: never overwrite existing objects
await datasync.send(new CreateTaskCommand({
  SourceLocationArn: appS3Arn,
  DestinationLocationArn: complianceS3Arn,
  Options: {
    OverwriteMode: "NEVER",
    // Don't delete destination objects that are absent from source
    PreserveDeletedFiles: "PRESERVE",
    VerifyMode: "ONLY_FILES_TRANSFERRED",
  },
}));

PreserveDeletedFiles: "PRESERVE" means DataSync will not delete destination objects even if the corresponding source object has been deleted. The default is REMOVE — DataSync mirrors deletions from source to destination.

Cross-account S3 copy

DataSync tasks run within a single AWS account. For cross-account copies, you create both locations in the same DataSync account but each BucketAccessRoleArn points to a role in the respective account. The destination bucket must have a bucket policy allowing the DataSync execution role (or the assumed cross-account role) to write.

Pattern: account A → DataSync in account A → bucket in account B

// Account A: source location (same account as DataSync task)
const sourceLocA = await datasync.send(new CreateLocationS3Command({
  S3BucketArn: "arn:aws:s3:::account-a-artifacts",
  S3Config: {
    BucketAccessRoleArn: "arn:aws:iam::111111111111:role/datasync-read-accountA",
  },
}));

// Account B bucket needs a policy allowing account A's DataSync role to write:
// {
//   "Effect": "Allow",
//   "Principal": { "AWS": "arn:aws:iam::111111111111:role/datasync-write-accountB-crossaccount" },
//   "Action": ["s3:PutObject", "s3:GetObject", "s3:ListBucket", "s3:GetBucketLocation"],
//   "Resource": ["arn:aws:s3:::account-b-archive", "arn:aws:s3:::account-b-archive/*"]
// }

// Account A: destination location (cross-account role that account A is allowed to assume)
const destLocB = await datasync.send(new CreateLocationS3Command({
  S3BucketArn: "arn:aws:s3:::account-b-archive",
  S3Config: {
    BucketAccessRoleArn: "arn:aws:iam::111111111111:role/datasync-write-accountB-crossaccount",
  },
}));

// The cross-account role in account A must have the s3: permissions for the account B bucket,
// and account B's bucket policy must trust the role ARN above.

The cross-account role (datasync-write-accountB-crossaccount) lives in account A, not account B. Account B's bucket policy grants access to this role ARN. This avoids the need to create or assume a role in account B from DataSync — the DataSync service principal only assumes roles in the same account as the task.

Bandwidth throttling

Use BytesPerSecond in Options to cap transfer bandwidth. This prevents DataSync from saturating your NAT gateway or PrivateLink endpoints during peak hours.

Options: {
  // Limit to 50 MB/s (50 * 1024 * 1024 = 52428800 bytes/second)
  BytesPerSecond: 52428800,
}

// Or set per-execution to override the task-level throttle:
await datasync.send(new StartTaskExecutionCommand({
  TaskArn: taskArn,
  OverrideOptions: {
    BytesPerSecond: -1, // -1 = unlimited for this execution (e.g., off-hours batch)
  },
}));

The minimum throttle is 1 MB/s. Setting BytesPerSecond: 0 causes InvalidParameterValueException; use -1 for unlimited.

Logging task executions to CloudWatch Logs

await datasync.send(new CreateTaskCommand({
  SourceLocationArn: sourceArn,
  DestinationLocationArn: destArn,
  CloudWatchLogGroupArn:
    "arn:aws:logs:us-east-1:123456789012:log-group:/datasync/mcp-artifacts",
  Options: {
    // BASIC: log errors only
    // TRANSFER: log every file transferred or skipped
    // OFF: no per-file logging (reduces CloudWatch costs for large transfers)
    LogLevel: "BASIC",
  },
}));

The DataSync execution role (the caller's role, not the BucketAccessRoleArn) must have logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents on the log group ARN. DataSync creates the log stream automatically per execution using the execution ARN as the stream name. With LogLevel: TRANSFER, a 1 million-file transfer generates ~1 million log events — this can be expensive; prefer BASIC for routine syncs and TRANSFER only when debugging.

EventBridge notifications for task completion

// EventBridge rule to catch DataSync completion (success or error)
// Add this via AWS Console or CloudFormation — DataSync emits these events automatically
// {
//   "source": ["aws.datasync"],
//   "detail-type": ["DataSync Task Execution State Change"],
//   "detail": {
//     "State": ["SUCCESS", "ERROR"],
//     "TaskArn": ["arn:aws:datasync:us-east-1:123456789012:task/task-xxx"]
//   }
// }

// In your MCP tool, trigger a downstream workflow when DataSync finishes:
import { EventBridgeClient, PutRuleCommand, PutTargetsCommand } from "@aws-sdk/client-eventbridge";

const events = new EventBridgeClient({ region: "us-east-1" });

await events.send(new PutRuleCommand({
  Name: "mcp-datasync-models-sync-complete",
  EventPattern: JSON.stringify({
    source: ["aws.datasync"],
    "detail-type": ["DataSync Task Execution State Change"],
    detail: {
      State: ["SUCCESS"],
      TaskArn: [taskArn],
    },
  }),
  State: "ENABLED",
}));

Common S3 DataSync errors and fixes

Error Cause Fix
InvalidRequestException: The source S3 bucket is not accessible Trust policy on BucketAccessRoleArn does not include datasync.amazonaws.com principal, or the aws:SourceAccount value is wrong Add {"Service": "datasync.amazonaws.com"} to the role's trust policy with matching aws:SourceAccount
InvalidParameterValueException: Bucket ARN is not valid S3BucketArn contains a path (e.g., arn:aws:s3:::bucket/prefix) Use just arn:aws:s3:::bucket and put the prefix in Subdirectory
Files in source are present but destination shows zero objects OverwriteMode: NEVER + all files already exist at destination with same name Check FilesSkipped in DescribeTaskExecution; switch to OverwriteMode: ALWAYS if you want updates to overwrite
AccessDenied on specific files at destination Bucket policy denies PutObject for certain key prefixes (e.g., a bucket policy with Deny on paths matching the destination prefix) Check bucket policy conditions; also check if bucket versioning is enabled — DataSync generates a new version per object on each sync, which may exceed bucket storage if retention is short
GLACIER objects show as FilesSkipped Objects in source bucket are in GLACIER or DEEP_ARCHIVE tier — DataSync cannot read them directly Restore objects with RestoreObjectCommand before running the DataSync task, or exclude them with Excludes filter if they should not be transferred

Related guides