Guide · Amazon Macie · Classification Jobs
Macie Classification Jobs for MCP Servers — CreateClassificationJob, Job Types, and Bucket Scope
Amazon Macie classification jobs are the mechanism that actively scans S3 object content for sensitive data. The background bucket inventory tells you about public access and encryption gaps; classification jobs tell you which objects contain credit card numbers, AWS credentials, PII, or your own custom-pattern secrets. For MCP servers that read S3 content and relay it to LLM agents, running a classification job before onboarding a new bucket is a critical gating check. This guide covers the CreateClassificationJobCommand API, one-time vs scheduled job types, bucket and prefix scoping, job status polling, and cost-aware scanning strategies.
TL;DR
Use JobType.ONE_TIME for initial bucket audits (runs once, then becomes COMPLETE). Use JobType.SCHEDULED with a dailySchedule, weeklySchedule, or monthlySchedule for continuous monitoring of active upload buckets. Scope jobs to specific prefixes with scoping.includes to avoid scanning cold archival content. Poll job status with DescribeClassificationJobCommand — a job is done when jobStatus is COMPLETE (one-time) or when you read its statistics.approximateNumberOfObjectsToProcess drops to zero (scheduled).
Job types: one-time vs scheduled
Macie offers two job types that suit different MCP server use cases:
| Job type | Use case | Terminal status | Cost model |
|---|---|---|---|
ONE_TIME |
Initial audit of a new bucket before wiring it into an MCP tool; ad-hoc compliance scans; before-deploy checks in CI/CD | Becomes COMPLETE when all objects processed; then read-only (cannot restart) |
Charged once per object scanned |
SCHEDULED |
Ongoing monitoring of active upload buckets; continuous credential-leak detection on output buckets; weekly compliance runs | Runs until cancelled; IDLE between runs, RUNNING during run windows |
Charged per run; Macie skips objects it has already classified since the last run if unchanged |
Creating a one-time classification job
import {
Macie2Client,
CreateClassificationJobCommand,
JobType,
ManagedDataIdentifierSelector,
} from "@aws-sdk/client-macie2";
const macie = new Macie2Client({ region: "us-east-1" });
// Audit a bucket before wiring it into an MCP document-retrieval tool
const { jobId } = await macie.send(new CreateClassificationJobCommand({
name: `mcp-onboard-audit-${Date.now()}`,
description: "One-time audit before onboarding bucket into MCP document tool",
jobType: JobType.ONE_TIME,
s3JobDefinition: {
bucketDefinitions: [
{
accountId: "123456789012",
buckets: ["mcp-document-store-prod"],
},
],
// Scope to the docs/ prefix only — skip raw-uploads/ and archive/
scoping: {
includes: {
and: [
{
simpleScopeTerm: {
comparator: "STARTS_WITH",
key: "OBJECT_KEY",
values: ["docs/"],
},
},
],
},
excludes: {
and: [
{
simpleScopeTerm: {
comparator: "ENDS_WITH",
key: "OBJECT_EXTENSION",
values: [".log", ".tmp"],
},
},
],
},
},
},
managedDataIdentifierSelector: ManagedDataIdentifierSelector.ALL,
customDataIdentifierIds: [
"12345678-1234-1234-1234-123456789012", // mcp-session-token identifier
],
tags: { project: "mcp-platform", stage: "onboarding" },
}));
console.log("Job created:", jobId);
Scoping: includes, excludes, and scope terms
The scoping block is the most important cost-control lever. It determines which objects within the target buckets Macie will scan. Both includes and excludes are AND-arrays of simpleScopeTerm and tagScopeTerm entries.
SimpleScopeTerm keys and comparators:
| Key | What it filters on | Valid comparators |
|---|---|---|
OBJECT_KEY |
S3 object key (full path) | STARTS_WITH, EQ, NE, CONTAINS |
OBJECT_EXTENSION |
File extension (e.g. .pdf) |
EQ, NE, ENDS_WITH |
OBJECT_SIZE |
Object size in bytes | EQ, NE, GT, GTE, LT, LTE |
OBJECT_LAST_MODIFIED_DATE |
Last modified timestamp (ISO-8601) | EQ, NE, GT, GTE, LT, LTE |
OBJECT_STORAGE_CLASS |
S3 storage class | EQ, NE |
A common pattern for MCP servers: scan only objects uploaded in the past 30 days (new content) and exclude objects in GLACIER storage class:
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString();
scoping: {
includes: {
and: [
{
simpleScopeTerm: {
comparator: "GTE",
key: "OBJECT_LAST_MODIFIED_DATE",
values: [thirtyDaysAgo],
},
},
],
},
excludes: {
and: [
{
simpleScopeTerm: {
comparator: "EQ",
key: "OBJECT_STORAGE_CLASS",
values: ["GLACIER", "DEEP_ARCHIVE"],
},
},
],
},
}
Creating a scheduled classification job
Scheduled jobs run on a recurring cadence. Use daily scheduling for active upload buckets that MCP servers read from continuously:
const scheduledJob = await macie.send(new CreateClassificationJobCommand({
name: "mcp-uploads-daily-scan",
jobType: JobType.SCHEDULED,
scheduleFrequency: {
// Run at the start of each day (UTC)
dailySchedule: {},
// Or use weeklySchedule: { dayOfWeek: "MONDAY" }
// Or use monthlySchedule: { dayOfMonth: 1 }
},
s3JobDefinition: {
bucketDefinitions: [
{ accountId: "123456789012", buckets: ["mcp-user-uploads"] },
],
scoping: {
includes: {
and: [
{
simpleScopeTerm: {
comparator: "STARTS_WITH",
key: "OBJECT_KEY",
values: ["uploads/"],
},
},
],
},
},
},
managedDataIdentifierSelector: ManagedDataIdentifierSelector.INCLUDE,
managedDataIdentifierIds: ["AWS_CREDENTIALS", "STRIPE_API_KEY", "GITHUB_PERSONAL_ACCESS_TOKEN"],
initialRun: true, // Run immediately when created, then follow schedule
}));
Setting initialRun: true causes Macie to scan all current objects immediately when the job is created, before waiting for the first scheduled run. Without it, the first scan happens at the next scheduled time — which could be up to 24 hours away for a daily schedule.
For scheduled jobs, Macie is incremental: on each run after the initial run, it only processes objects whose LastModified timestamp is after the previous run's start time. This keeps ongoing costs predictable — you pay for new and modified objects, not the entire bucket on every run.
Polling job status
Use DescribeClassificationJobCommand to check job progress:
import {
DescribeClassificationJobCommand,
JobStatus,
} from "@aws-sdk/client-macie2";
async function waitForJob(client: Macie2Client, jobId: string): Promise<void> {
const terminalStatuses = new Set([
JobStatus.COMPLETE,
JobStatus.CANCELLED,
JobStatus.USER_PAUSED,
]);
while (true) {
const job = await client.send(new DescribeClassificationJobCommand({ jobId }));
console.log(
`Status: ${job.jobStatus}`,
`| Objects processed: ${job.statistics?.numberOfObjectsProcessed ?? 0}`,
`| Findings: ${job.statistics?.numberOfObjectsWithSensitiveData ?? 0}`,
);
if (terminalStatuses.has(job.jobStatus!)) {
if (job.jobStatus === JobStatus.COMPLETE) {
console.log("Job complete —", job.statistics?.numberOfObjectsWithSensitiveData, "objects with sensitive data found");
}
break;
}
// Poll every 60 seconds for jobs scanning large buckets
await new Promise(resolve => setTimeout(resolve, 60_000));
}
}
await waitForJob(macie, jobId);
Key statistics fields from DescribeClassificationJobCommand:
| Field | Meaning |
|---|---|
statistics.numberOfObjectsProcessed |
Objects inspected so far |
statistics.approximateNumberOfObjectsToProcess |
Remaining estimate (not exact — Macie updates this as it discovers objects) |
statistics.numberOfObjectsSkipped |
Objects Macie could not inspect (Glacier, >20 MB, unsupported format, server-side error) |
statistics.numberOfObjectsWithSensitiveData |
Objects where Macie found at least one match — the signal you're looking for |
userPausedDetails.jobImminentExpirationHealthEventArn |
Non-null when a paused job is about to auto-cancel (jobs paused >30 days auto-cancel) |
Job statuses and lifecycle
Understanding the full job status lifecycle prevents polling loops that mistake an intermediate state for completion:
RUNNING— actively scanning objectsCOMPLETE— one-time job finished; scheduled job run completed (will transition toIDLE)IDLE— scheduled job waiting for next run windowPAUSED— Macie internally paused the job (quota, account issue)USER_PAUSED— you calledUpdateClassificationJobCommandwithjobStatus: "USER_PAUSED"CANCELLED— job cancelled; cannot be restarted
For one-time jobs, the terminal success state is COMPLETE. For scheduled jobs, IDLE between runs is normal — do not treat IDLE as an error.
Cancelling and listing jobs
import {
UpdateClassificationJobCommand,
ListClassificationJobsCommand,
JobComparator,
} from "@aws-sdk/client-macie2";
// Cancel a job (irreversible)
await macie.send(new UpdateClassificationJobCommand({
jobId: "job-id-here",
jobStatus: "CANCELLED",
}));
// List all active jobs for an account
const jobs = await macie.send(new ListClassificationJobsCommand({
filterCriteria: {
includes: [
{
comparator: JobComparator.NE,
key: "jobStatus",
values: ["CANCELLED"],
},
],
},
sortCriteria: {
attributeName: "createdAt",
orderBy: "DESC",
},
}));
for (const job of jobs.items ?? []) {
console.log(job.jobId, job.name, job.jobStatus, job.jobType);
}
Integrating classification jobs into the MCP server onboarding workflow
A reliable pattern for MCP server teams is to gate new S3 data sources on a Macie classification job result before allowing an MCP tool to read from them. The workflow:
- When a new S3 bucket is tagged
mcp-data-source: pending, trigger a one-time classification job via EventBridge → Lambda →CreateClassificationJobCommand. - Poll job status or wait for the
COMPLETEEventBridge event (see the findings and EventBridge guide). - Query
ListFindingsCommandfor the job. IfnumberOfObjectsWithSensitiveData === 0and no policy findings: approve the bucket by tagging itmcp-data-source: approved. - If sensitive data findings exist: tag the bucket
mcp-data-source: quarantine, send an alert to the security channel, and block the MCP tool's IAM role from reading the bucket using a resource-based policy condition on the tag.
This pattern keeps sensitive data out of LLM agent context automatically, without requiring manual review of every new data source.