Area: Ingestion Issues
Sub-Area: File Source / S3 Metadata File Ingestion
Applies to: OSS + Cloud
Issue
You have metadata in JSON files in an Amazon S3 bucket and want to load it into DataHub. DataHub's file source (Metadata File) reads these files. The source only accepts DataHub's own metadata record format. It does not read a custom JSON structure.
If a record is not in DataHub's format, the run reports Failed to deserialize metadata and the error Unknown object type: ... for that record.
You Might Be Asking
- What JSON format does DataHub expect in a metadata file?
- Can I ingest my own custom JSON structure directly from S3?
- What is the difference between an MCP and an MCE record?
- What do I need to install, and what AWS permissions does the ingestion need?
- How do I convert my existing metadata into a file DataHub can read?
Solution
The file source reads from a local path, an HTTP URL, or an s3:// path (see Metadata File source). Use a JSON array of records. The source accepts two record types:
- MetadataChangeProposal (MCP), recommended: an object with
entityType,entityUrn,changeType,aspectName, andaspect. The MetadataChangeProposal page describes these fields. - MetadataChangeEvent (MCE), legacy: an object with
proposedSnapshot. The snapshot is keyed by its full class name (for examplecom.linkedin.pegasus2avro.metadata.snapshot.DatasetSnapshot) and holds aurnand a list ofaspects, each keyed by its full class name.
The source rejects any other structure.
Step 1: Write your file as an MCP array
aspectName must be a DataHub aspect name, for example datasetProperties, ownership, globalTags, schemaMetadata, or status. Put the aspect's fields under aspect.json, following the schema of that aspect. Example:
[
{
"entityType": "dataset",
"entityUrn": "urn:li:dataset:(urn:li:dataPlatform:s3,my-bucket/my-dataset,PROD)",
"changeType": "UPSERT",
"aspectName": "datasetProperties",
"aspect": {
"json": {
"name": "my-dataset",
"description": "Example dataset description"
}
}
}
]
Caution: an UPSERT record replaces the whole aspect on the entity. In the example, any custom properties already on the dataset's datasetProperties are removed. Include every field you want to keep in the record.
Step 2: Install the S3 dependencies
The base acryl-datahub package does not include the AWS libraries the s3:// path needs. Without them the run fails with:
s3 is disabled due to a missing dependency: boto3; try running `pip install 'acryl-datahub[s3]'`
On the machine that runs the CLI, install the s3 extra:
pip install 'acryl-datahub[s3]'
The Metadata File source page lists the source's config options.
Step 3: Create a recipe that points to S3
source:
type: file
config:
path: "s3://<your-bucket>/<folder>/"
sink:
type: datahub-rest
config:
server: "${DATAHUB_GMS_URL}"
token: "${DATAHUB_GMS_TOKEN}"
For DataHub Cloud, the server is https://<your-instance>.acryl.io/gms.
file source options (see Metadata File source):
-
path: a file or folder path, an HTTP URL, or ans3://path. For S3, the source lists every object whose key starts with the path, including objects in subfolders. End a folder path with/, becauses3://bucket/dataalso matchess3://bucket/data-old/.... -
file_extension: only files whose name ends with this value are read. The default is.json. If you leave out the leading dot, the source adds it. There is no wildcard:*becomes.*and matches no files. To read files with another extension, set that extension (for example.txt) or rename the files to.json. -
read_mode:AUTO(default),BATCH, orSTREAM. InAUTO, files of 100 MB or more are streamed and smaller files are read whole. -
aspect: only MCP records with thisaspectNameare ingested. MCE records are not filtered. -
count_all_before_starting: defaulttrue. In streaming mode, the source counts the records first to estimate completion time. Set it tofalseif the count takes too long.
Step 4: Give the ingestion AWS access
The file source has no AWS credential settings (see the config options on the Metadata File source page). It uses boto3's default credential chain: environment variables, a shared AWS profile, or the IAM role of the host or pod that runs the ingestion. If you use a remote executor, attach the role to the executor's environment.
The credentials need:
-
s3:ListBucketon the bucket (the source lists the objects under the path) -
s3:GetObjecton the objects
Step 5: Validate with a dry run
datahub ingest -c recipe.yml --dry-run
A dry run reads and parses every record and writes nothing to DataHub. It still connects to the server in the sink, so DATAHUB_GMS_URL and DATAHUB_GMS_TOKEN must be set. Check the report for Failed to deserialize metadata errors before you run without --dry-run.
Do not use the source's connection test for an s3:// path. The test checks only the local file system, so it reports <path> doesn't appear to be a valid file or directory. even when ingestion works.
If your JSON is not in DataHub format
Convert it with the Python SDK. Build an MCP for each aspect and write the file with write_metadata_file, which writes the MCP format shown in Step 1:
from datahub.emitter.mce_builder import make_dataset_urn
from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.ingestion.sink.file import write_metadata_file
from datahub.metadata.schema_classes import DatasetPropertiesClass
mcps = [
MetadataChangeProposalWrapper(
entityUrn=make_dataset_urn("s3", "my-bucket/my-dataset", "PROD"),
aspect=DatasetPropertiesClass(
name="my-dataset", description="Example dataset description"
),
)
]
write_metadata_file("metadata.json", mcps)
Upload metadata.json to your bucket. With the s3 extra installed, you can also pass an s3:// path to write_metadata_file. That write needs s3:PutObject.
You can also skip the file and send the MCPs straight to DataHub with the REST emitter. See Python Emitter.
Reference examples
The open source repository has sample files at metadata-ingestion/examples/mce_files/. bootstrap_mce.json holds both MCE and MCP records. single_mce.json holds one MCE.
Additional Notes
- Use MCP records for new files. MCE is the legacy format.
- Business glossary YAML and lineage YAML files use their own sources:
datahub-business-glossaryanddatahub-lineage-file. Do not load them with thefilesource.
Related Documentation
- Metadata File source
- Metadata File sink
- MetadataChangeProposal & MetadataChangeLog Events
- Python Emitter
- Business Glossary source
- File Based Lineage source
Tags: file source, s3, metadata json, mcp, mce, metadata change proposal, ingestion, python emitter, recipe, datahub cloud