Data Mesh: Practical Implementation with AWS S3, Glue, Athena, and Lake Formation
Build a step-by-step practical Data Mesh lab on AWS combining Amazon S3, Apache Parquet, AWS Glue Data Catalog, Amazon Athena, AWS DMS, and AWS Lake Formation to publish, query, and govern Data Products across multiple business domains.
The indicator keeps the furthest percentage explored; marking the article complete is your choice.
From Architecture Diagrams to a Working AWS Environment
After defining their domain boundaries, agreeing on Data Contracts, establishing quality SLIs, and designing their access matrix, the Sales, Payments, and Inventory teams at CommerceFlow reach the decisive moment: building and operating their first real Data Products (sales-orders, confirmed-payments, and inventory-availability) on AWS.
When moving from conceptual diagrams to the cloud, teams often fall into one of two opposite traps:
The shared data swamp under a new name: dumping CSV files from all three domains into a single shared S3 prefix (s3://commerceflow-data/raw/), exposing internal staging tables directly to analysts, and granting broad s3:* permissions so Amazon Athena queries "just work."
The illusion that provisioning AWS resources automatically creates a Data Mesh: assuming that creating three Amazon S3 buckets or three databases in AWS Glue Data Catalog constitutes a Data Mesh, even when there are no pre-publication acceptance checks, no clear domain ownership, and no separation between internal working zones and published product interfaces.
Provisioning cloud services does not install an organizational operating model by itself. However, a well-structured technical implementation built on Amazon S3, Apache Parquet, AWS Glue Data Catalog, Amazon Athena, and AWS Lake Formation provides a shared analytical platform where each domain publishes verified datasets, controls schema evolution, and governs consumer access without managing dedicated servers.
Reference Architecture of the AWS Lab
In this article, we will build a reproducible, incremental reference implementation for CommerceFlow. To keep laboratory costs near zero and make the setup easy to test within a single AWS account, we will organize logical domain isolation using dedicated S3 prefixes, per-domain catalog databases, and fine-grained permissions in AWS Lake Formation:
Amazon S3 (Decoupled Analytical Storage): Stores the physical files while strictly separating each domain's private working area (internal/) from its contracted public interface (published/). No external consumer is allowed to read internal/.
Apache Parquet (Columnar Storage Format): Stores published datasets in a compressed, column-oriented binary layout that includes column types and per-block statistics (min/max), enabling Athena to read only the specific columns requested by a query.
AWS Glue Data Catalog (Technical Metadata Registry): Stores logical databases (sales_products, payments_products, inventory_products), column schemas, data types, partition keys, and the S3 location of each published version.
AWS Lake Formation (Authorization Plane for Cataloged Data): Registers governed S3 locations and grants fine-grained SELECT and DESCRIBE permissions on databases, tables, columns, or row filters to producer and consumer roles without handing out raw s3:GetObject bucket access.
Amazon Athena (Serverless SQL Query Engine): Allows authorized consumers to query individual products or join datasets across domains using standard SQL (Trino/Presto engine), writing query results to an isolated workgroup prefix (athena-results/).
Step 1: Logical Storage Layout and Naming Conventions
A core architectural rule in Data Mesh is never exposing internal ingestion or staging tables as if they were the published Data Product. Inside our laboratory bucket (s3://commerceflow-mesh-lab-111122223333), we enforce three layout conventions:
Separation between internal and published zones: If the Sales team refactors its operational database or changes its staging pipeline inside internal/staging/, no downstream consumer is impacted as long as the schema and semantics in published/sales_orders/v1/ remain stable.
Explicit path versioning (v1/): If a breaking change becomes necessary in the future, Sales can publish v2/ alongside v1/ during the deprecation window without breaking consumers still reading v1/.
Business-date partitioning (order_date=YYYY-MM-DD): Enables Amazon Athena to skip irrelevant partitions (partition pruning) when queries filter by date range, reducing both query latency and scanned bytes billed.
Step 2: Generating Synthetic Datasets, Pre-Publication Validation, and Parquet Export
To make the lab self-contained without requiring a live operational database or an active AWS DMS replication instance from minute one, we start with a Python script that:
Prepares synthetic records for sales_orders, confirmed_payments, and inventory_availability following mesh interoperability standards (compatible order_id keys, ISO 4217 USD currency codes, and ISO 8601 UTC timestamps).
Runs pre-publication acceptance checks (schema presence, primary key uniqueness, non-null required attributes, and non-negative amounts) before allowing publication.
Verifies the datasets (and shows how to export them to Apache Parquet with pyarrow and upload them to S3).
Once exported as Apache Parquet files (using pyarrow locally via pip install pyarrow), we upload each file to its domain's published/ prefix using the AWS CLI:
# Upload validated Parquet files to each domain's published zone
aws s3 cp sales_orders.parquet \
s3://commerceflow-mesh-lab-111122223333/domains/sales/published/sales_orders/v1/order_date=2026-05-10/part-00001.parquet
aws s3 cp confirmed_payments.parquet \
s3://commerceflow-mesh-lab-111122223333/domains/payments/published/confirmed_payments/v1/payment_date=2026-05-10/part-00001.parquet
aws s3 cp inventory_availability.parquet \
s3://commerceflow-mesh-lab-111122223333/domains/inventory/published/inventory_availability/v1/snapshot_date=2026-05-10/part-00001.parquet
Step 3: Registering Databases and External Parquet Tables in AWS Glue Data Catalog / Athena
With the Parquet files in place, we register one catalog database per domain and define external tables with explicit column types and product metadata in TBLPROPERTIES. You can run these DDL statements directly in the Amazon Athena query editor (using a Workgroup configured to write query outputs to s3://commerceflow-mesh-lab-111122223333/athena-results/):
-- 1. Create per-domain logical databases in AWS Glue Data CatalogCREATE DATABASE IF NOTEXISTS sales_products
COMMENT 'Data Products published by the Sales domain (CommerceFlow)';
CREATE DATABASE IF NOTEXISTS payments_products
COMMENT 'Data Products published by the Payments domain (CommerceFlow)';
CREATE DATABASE IF NOTEXISTS inventory_products
COMMENT 'Data Products published by the Inventory domain (CommerceFlow)';
-- 2. Register external table sales_orders (Sales Domain)CREATEEXTERNALTABLE IF NOTEXISTS sales_products.sales_orders (
order_id STRING COMMENT 'Global unique order identifier',
customer_id_hash STRING COMMENT 'Pseudonymized customer identifier (HMAC)',
order_status STRING COMMENT 'Order status: PENDING, PAID, SHIPPED, CANCELLED, REFUNDED',
total_amount DECIMAL(12,2) COMMENT 'Gross order amount',
currency STRING COMMENT 'ISO 4217 currency code',
created_at STRING COMMENT 'UTC ISO 8601 creation timestamp',
updated_at STRING COMMENT 'UTC ISO 8601 last update timestamp'
)
PARTITIONED BY (order_date DATE)
STORED AS PARQUET
LOCATION 's3://commerceflow-mesh-lab-111122223333/domains/sales/published/sales_orders/v1/'
TBLPROPERTIES (
'parquet.compression'='SNAPPY',
'data_product.name'='sales-orders',
'data_product.domain'='sales',
'data_product.owner'='sales-data-team@commerceflow.internal',
'data_product.contract_version'='1.0.0',
'data_product.freshness_slo_minutes'='60'
);
-- Register the published partitionALTER TABLE sales_products.sales_orders
ADD IF NOTEXISTSPARTITION (order_date =DATE'2026-05-10')
LOCATION 's3://commerceflow-mesh-lab-111122223333/domains/sales/published/sales_orders/v1/order_date=2026-05-10/';
-- 3. Register external table confirmed_payments (Payments Domain)CREATEEXTERNALTABLE IF NOTEXISTS payments_products.confirmed_payments (
payment_id STRING COMMENT 'Unique payment transaction identifier',
order_id STRING COMMENT 'Associated order identifier (cross-domain join key)',
payment_method STRING COMMENT 'Payment method: CREDIT_CARD, DEBIT_CARD, TRANSFER',
settled_amount DECIMAL(12,2) COMMENT 'Actual settled monetary amount',
currency STRING COMMENT 'ISO 4217 currency code',
payment_status STRING COMMENT 'Settlement status: CONFIRMED, REJECTED, REFUNDED',
confirmed_at STRING COMMENT 'UTC ISO 8601 confirmation timestamp'
)
PARTITIONED BY (payment_date DATE)
STORED AS PARQUET
LOCATION 's3://commerceflow-mesh-lab-111122223333/domains/payments/published/confirmed_payments/v1/'
TBLPROPERTIES (
'parquet.compression'='SNAPPY',
'data_product.name'='confirmed-payments',
'data_product.domain'='payments',
'data_product.owner'='payments-data-team@commerceflow.internal',
'data_product.contract_version'='1.0.0'
);
ALTER TABLE payments_products.confirmed_payments
ADD IF NOTEXISTSPARTITION (payment_date =DATE'2026-05-10')
LOCATION 's3://commerceflow-mesh-lab-111122223333/domains/payments/published/confirmed_payments/v1/payment_date=2026-05-10/';
-- 4. Register external table inventory_availability (Inventory Domain)CREATEEXTERNALTABLE IF NOTEXISTS inventory_products.inventory_availability (
sku STRING COMMENT 'Unique product catalog SKU',
warehouse_id STRING COMMENT 'Fulfillment center identifier',
available_qty INT COMMENT 'Physical units available for sale',
reserved_qty INT COMMENT 'Units reserved in active carts or in-flight orders',
updated_at STRING COMMENT 'UTC ISO 8601 inventory snapshot timestamp'
)
PARTITIONED BY (snapshot_date DATE)
STORED AS PARQUET
LOCATION 's3://commerceflow-mesh-lab-111122223333/domains/inventory/published/inventory_availability/v1/'
TBLPROPERTIES (
'parquet.compression'='SNAPPY',
'data_product.name'='inventory-availability',
'data_product.domain'='inventory',
'data_product.owner'='inventory-data-team@commerceflow.internal',
'data_product.contract_version'='1.0.0'
);
ALTER TABLE inventory_products.inventory_availability
ADD IF NOTEXISTSPARTITION (snapshot_date =DATE'2026-05-10')
LOCATION 's3://commerceflow-mesh-lab-111122223333/domains/inventory/published/inventory_availability/v1/snapshot_date=2026-05-10/';
Important Limitation of AWS Glue Data Catalog: Glue Data Catalog excels as a technical metadata registry (column names, physical types, S3 locations, serialization formats, and key-value TBLPROPERTIES). However, by itself it does not provide a full business discovery portal with rich semantic glossaries, interactive access-request workflows, live SLI health badges, or full contract documentation; mature implementations typically pair it with a discovery catalog such as DataHub, OpenMetadata, or Amazon DataZone.
Step 4: Single-Product and Cross-Domain Analytical Queries in Amazon Athena
Once the tables and partitions are registered, we verify individual products and execute a federated cross-domain query joining Sales and Payments via their shared order_id and ISO 4217 currency:
-- Query 1: Single-domain check on inventory_availabilitySELECT
warehouse_id,
sku,
available_qty,
reserved_qty,
(available_qty - reserved_qty) AS net_sellable_units
FROM inventory_products.inventory_availability
WHERE snapshot_date =DATE'2026-05-10';
-- Query 2: Cross-domain reconciliation (Sales + Payments)SELECT
o.order_id,
o.order_status,
o.total_amount AS order_amount,
p.payment_id,
p.payment_method,
COALESCE(p.settled_amount, DECIMAL'0.00') AS settled_amount,
(o.total_amount -COALESCE(p.settled_amount, DECIMAL'0.00')) AS reconciliation_gap
FROM sales_products.sales_orders o
LEFTJOIN payments_products.confirmed_payments p
ON o.order_id = p.order_id
AND o.currency = p.currency
WHERE o.order_date =DATE'2026-05-10'ORDERBY o.order_id;
ORD-3003 (CANCELLED, 0.00) has no settled payment (NULL coalesced to 0.00), keeping reconciliation_gap = 0.00.
Step 5: Connecting Operational Databases via AWS DMS (and Why Raw CDC Is Not a Data Product)
In the previous steps, we uploaded validated Parquet files directly from our Python script. What happens when Sales orders originate in an operational relational database such as Amazon RDS for PostgreSQL or MySQL?
A common pattern in AWS is using AWS Database Migration Service (AWS DMS) in Full Load + CDC mode (initial snapshot plus ongoing change data capture) writing to an Amazon S3 target. However, this introduces one of the most frequent mistakes in cloud data engineering: pointing the external table sales_orders directly at the S3 folder where AWS DMS writes raw CDC files.
Why Raw AWS DMS Output Must Never Be Exposed Directly to Consumers
When AWS DMS replicates changes to S3, it does not update existing rows inside previously written Parquet files; instead, it appends new files containing change-log records with control columns such as Op (I for insert, U for update, D for delete) and dms_timestamp:
If a BI analyst runs SELECT SUM(total_amount) FROM sales_orders directly against that raw CDC folder, they will double-count order ORD-3001 (300.00 instead of 150.00) and include deleted records (Op = 'D').
Therefore, the proper flow inside the Sales domain separates CDC ingestion from product consolidation:
AWS DMS writes exclusively to the domain's private internal zone:s3://.../domains/sales/internal/cdc/sales_orders/.
State consolidation and deduplication: A domain transformation job (using AWS Glue, a MERGE INTO statement on an Apache Iceberg table in Athena, or a window query with ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY dms_timestamp DESC)) selects the latest state for each order_id and filters out deleted rows (Op != 'D').
Contract-validated publication: Only the consolidated, deduplicated, and validated state is written to s3://.../domains/sales/published/sales_orders/v1/.
Step 6: Access Governance with AWS Lake Formation and Practical Verification
Next, we configure real access controls so that the consumer role commerceflow-bi-order-finance-role can query sales_products.sales_orders and payments_products.confirmed_payments, while being denied access to inventory_products.inventory_availability and all internal/ zones.
The 5 Permission Layers That Must Be Coordinated
For an Amazon Athena query governed by AWS Lake Formation to succeed securely, five distinct permission layers must align (none of them automatically replaces the others):
IAM Service Permissions (on the consumer role): Permission to invoke athena:StartQueryExecution, athena:GetQueryResults, glue:GetDatabase, glue:GetTable, and lakeformation:GetDataAccess. The consumer role does NOT receive s3:GetObject on the data product bucket.
Disabling IAMAllowedPrincipals in Lake Formation: Default grants to the legacy group IAMAllowedPrincipals (Super) on new databases and tables must be disabled; otherwise, Lake Formation defers to IAM and bypasses fine-grained catalog restrictions.
Registering the S3 Location in Lake Formation: Each domain's published/ prefix is registered with Lake Formation using a dedicated service role (Data Access Role) that holds S3 and KMS permissions to vend temporary scoped credentials to the Athena engine.
Lake Formation Catalog Grants:DESCRIBE permission on the target databases and SELECT + DESCRIBE permissions on the authorized tables and columns.
S3 Permissions on the Athena Query Results Bucket (on the consumer role): Amazon Athena writes the output file of every query to the consumer's workgroup results prefix (s3://.../athena-results/bi-finance-analyst/). Even if Lake Formation authorizes reading the table, the query will fail if the consumer's IAM role lacks s3:PutObject and s3:GetObject on its own Athena query results prefix.
AWS CLI Commands to Register Locations and Grant Permissions in Lake Formation
# 1. Register the published S3 paths in Lake Formation using the service-linked data access role
aws lakeformation register-resource \
--resource-arn arn:aws:s3:::commerceflow-mesh-lab-111122223333/domains/sales/published/ \
--use-service-linked-role
aws lakeformation register-resource \
--resource-arn arn:aws:s3:::commerceflow-mesh-lab-111122223333/domains/payments/published/ \
--use-service-linked-role
aws lakeformation register-resource \
--resource-arn arn:aws:s3:::commerceflow-mesh-lab-111122223333/domains/inventory/published/ \
--use-service-linked-role
# 2. Grant DESCRIBE on the Sales and Payments databases to the Finance BI role
aws lakeformation grant-permissions \
--principal DataLakePrincipalIdentifier=arn:aws:iam::111122223333:role/commerceflow-bi-order-finance-role \
--resource '{"Database": {"Name": "sales_products"}}' \
--permissions "DESCRIBE"
aws lakeformation grant-permissions \
--principal DataLakePrincipalIdentifier=arn:aws:iam::111122223333:role/commerceflow-bi-order-finance-role \
--resource '{"Database": {"Name": "payments_products"}}' \
--permissions "DESCRIBE"# 3. Grant SELECT and DESCRIBE exclusively on sales_orders and confirmed_payments
aws lakeformation grant-permissions \
--principal DataLakePrincipalIdentifier=arn:aws:iam::111122223333:role/commerceflow-bi-order-finance-role \
--resource '{"Table": {"DatabaseName": "sales_products", "Name": "sales_orders"}}' \
--permissions "SELECT""DESCRIBE"
aws lakeformation grant-permissions \
--principal DataLakePrincipalIdentifier=arn:aws:iam::111122223333:role/commerceflow-bi-order-finance-role \
--resource '{"Table": {"DatabaseName": "payments_products", "Name": "confirmed_payments"}}' \
--permissions "SELECT""DESCRIBE"
Verifying Allowed vs. Denied Access
When we assume commerceflow-bi-order-finance-role via temporary AWS STS credentials and run two queries in Amazon Athena:
Allowed access test (sales_orders + confirmed_payments): The cross-domain reconciliation query from Step 4 finishes with SUCCEEDED and returns the 3 expected rows, even though the role has no direct s3:GetObject permission on the domain prefixes.
Denied access test (inventory_availability): Executing SELECT * FROM inventory_products.inventory_availability; is immediately rejected by Athena with:
AccessDeniedException: Insufficient Lake Formation permission(s) on inventory_availability.
Cost Analysis, Table Formats, and Lab vs. Production Boundaries
Before enabling services in an AWS account, every engineer and architect should understand how pricing works and what separates a laboratory setup from a production deployment:
Controlling AWS Costs from Day One
Amazon S3: Bills per gigabyte-month stored and per PUT/GET/LIST request. In a lab with a few megabytes of Parquet files, storage costs less than a cent, but writing thousands of tiny files (small files problem) inflates GET request charges and slows down Athena queries.
Amazon Athena: Bills per terabyte of data scanned per query (with a 10 MB minimum per query). DDL statements (CREATE EXTERNAL TABLE, ALTER TABLE ADD PARTITION) incur no scan charges. Converting CSVs to Snappy-compressed Apache Parquet, partitioning by date, and selecting only required columns reduces scanned bytes by 80%–95%.
AWS Glue: Storing a few tables in Glue Data Catalog is inexpensive, but Glue Crawlers and Glue ETL Jobs bill per DPU-hour (Data Processing Unit). In small labs, registering tables with explicit SQL DDL (CREATE EXTERNAL TABLE) is much cheaper than scheduling Crawlers every 15 minutes.
AWS DMS: Runs on replication instances (or serverless capacity) that bill by the hour while active, even when zero rows are changing. If you provision a DMS instance for an experiment, always stop and delete it immediately after testing.
Laboratory Implementation vs. Production-Ready Architecture
Dimension
Laboratory Implementation (This Article)
Production-Ready Architecture
Account Isolation
Single AWS account using S3 prefixes and separate Glue databases per domain.
Multi-account AWS topology (dedicated accounts per domain plus a central governance/catalog account using AWS RAM and cross-account Lake Formation).
Table Format
External static Parquet tables with partitions registered via DDL.
Open transactional table formats (Apache Iceberg on S3/Glue) supporting ACID MERGE, row-level updates/deletes, and snapshot time travel.
Provisioning
Manual AWS CLI commands and interactive Athena SQL statements.
Reproducible declarative Infrastructure as Code (Terraform) and automated CI/CD pipelines (covered in Article 22).
Access Governance
Direct named-resource grants on specific tables.
Scalable LF-Tag (ABAC) policies, domain-isolated AWS KMS keys, and active CloudTrail Data Events auditing.
Three Scenarios with Different AWS Implementation Decisions
Context: Three domains (Sales, Payments, Inventory) publish hourly batch updates consumed by Finance and BI teams.
Decision: Store published Data Products in Amazon S3 as partitioned Apache Parquet (or Apache Iceberg tables where order statuses update frequently), register schemas in AWS Glue Data Catalog, govern access via AWS Lake Formation, and query serverlessly with Amazon Athena Workgroups configured with per-query scan limits.
Why: Decouples storage from compute, lets each domain publish independently, and avoids paying for idle 24/7 clusters when analytical queries are bursty.
Scenario 2: Ongoing Replication from a Legacy Relational Database with Frequent Updates
Context: The operational Sales database in PostgreSQL updates the status of each order up to five times a day (PENDING -> PAID -> PACKED -> SHIPPED -> DELIVERED).
Decision: Use AWS DMS to write raw change events (I, U, D) into the domain's private internal/cdc/ S3 prefix, and run a compaction step using MERGE INTO on an Apache Iceberg table registered in Glue Data Catalog to publish only the deduplicated current state in sales_products.sales_orders.
Why: Plain Parquet tables require rewriting entire partitions whenever a single row changes; Iceberg manages metadata manifests and atomic snapshots on S3 without exposing raw CDC duplicates to consumers.
Scenario 3: When a Simpler Alternative Is Sufficient (Single-Team Monolithic Application)
Context: A university study-room booking app has 3 developers, a single PostgreSQL database on Amazon RDS with 50,000 rows in total, and one monthly utilization report.
Decision: Run the monthly analytical queries against a PostgreSQL read replica (or export a single monthly Parquet snapshot to S3 queried with DuckDB or Athena) without deploying AWS DMS, multiple Glue databases, or a multi-role Lake Formation hierarchy.
Why: When there are no multiple autonomous domains or cross-team governance boundaries, building a full multi-domain Data Mesh topology on AWS adds operational overhead without delivering business value.
Using AI Assistants to Build and Troubleshoot AWS Implementations
AI assistants can speed up authoring Athena DDL statements and diagnosing multi-layer permission errors across IAM and Lake Formation, provided you verify the generated commands against current AWS documentation.
Prompt 1: Generating Athena DDL and Post-Load Validation SQL from a Data Contract
Context: I am implementing the "confirmed-payments" Data Product for the Payments domain on AWS (Amazon S3 + AWS Glue Data Catalog + Amazon Athena engine v3).
Product contract:
- Columns: payment_id (STRING, PK), order_id (STRING, FK to sales-orders), payment_method (STRING), settled_amount (DECIMAL(12,2)), currency (STRING), payment_status (STRING), confirmed_at (STRING ISO-8601).
- Partition column: payment_date (DATE).
- Published S3 path: s3://commerceflow-mesh-lab-111122223333/domains/payments/published/confirmed_payments/v1/
Task:
1. Generate the CREATE EXTERNAL TABLE statement compatible with Amazon Athena using Parquet format, SNAPPY compression, and TBLPROPERTIES documenting the owner, domain, and contract version.
2. Generate a single post-load validation SQL query in Athena that checks: total row count > 0, payment_id uniqueness, 0 nulls in order_id, and settled_amount > 0 whenever payment_status = 'CONFIRMED'.
What a human must verify: Ensure the partition column (payment_date) appears only in PARTITIONED BY (...) and is not duplicated inside the main column list, and verify that the S3 LOCATION ends with a trailing slash / and points to the published/ zone.
Prompt 2: Troubleshooting AccessDeniedException Across IAM, S3, KMS, and Lake Formation
Context: I registered the table "sales_products.sales_orders" in AWS Glue Data Catalog and granted SELECT and DESCRIBE permissions to the IAM role "commerceflow-bi-order-finance-role" in AWS Lake Formation. However, when a user assumes that role and runs "SELECT * FROM sales_products.sales_orders LIMIT 10" in Amazon Athena, the query fails with AccessDeniedException.
Task: Provide an ordered checklist of the 5 most common technical root causes for this failure on AWS (covering IAMAllowedPrincipals, Lake Formation S3 location registration, AWS KMS key policies on the data bucket, and S3 permissions on the Athena Workgroup query results bucket) along with the exact AWS CLI command to inspect each layer.
What a human must verify: Never "fix" the error by attaching AdministratorAccess or AmazonS3FullAccess to the consumer role; isolate which of the five layers is rejecting the call and grant only the minimum required permission.
Practical Exercises
Exercise 1: The Pitfall of Exposing Raw AWS DMS CDC Files
The Sales domain team configures an AWS DMS task in Full Load + CDC mode from its operational PostgreSQL database directly into s3://commerceflow-mesh-lab-111122223333/domains/sales/published/sales_orders/v1/ and points the external table sales_products.sales_orders directly at that path. During the morning, order ORD-5001 for $200.00 is created in status PENDING, ten minutes later transitions to PAID, and one hour later is cancelled and deleted from the operational table.
Explain what records exist in S3, what SELECT COUNT(*), SUM(total_amount) FROM sales_products.sales_orders WHERE order_id = 'ORD-5001' in Amazon Athena will return, and what two architectural changes are required to fix the design.
Exercise 2: Diagnosing an Amazon Athena Output Location Failure
An administrator properly registers s3://commerceflow-mesh-lab-111122223333/domains/payments/published/ in AWS Lake Formation and grants DESCRIBE and SELECT permissions to commerceflow-bi-analyst-role on payments_products.confirmed_payments. The analyst's IAM role has athena:StartQueryExecution, glue:GetTable, and lakeformation:GetDataAccess, but zeros3:* permissions in IAM. When the analyst runs a query in Athena, the engine returns: Unable to verify/create output bucket commerceflow-mesh-lab-111122223333.
Explain why this error occurs even though Lake Formation governs access to confirmed_payments, and specify the exact minimum S3 permissions the analyst role needs without opening direct access to domain data buckets.
Exercise 3: Writing a Three-Domain Reconciliation Query
Suppose an operations analyst is granted Lake Formation permissions on sales_products.sales_orders and payments_products.confirmed_payments, and sales_orders includes sku and quantity columns. Write an Amazon Athena SQL query that joins paid orders (order_status = 'PAID'), confirmed payments (payment_status = 'CONFIRMED'), and available stock in inventory_products.inventory_availability for 2026-05-10, identifying any sku where total paid order units exceed current available_qty. Also state what additional Lake Formation permission the analyst needs before running the query.
Solutions to the Exercises
Solution to Exercise 1
What happens in S3 and Athena: AWS DMS writes three separate change records into the S3 Parquet files: one with Op = 'I' (PENDING, 200.00), a second with Op = 'U' (PAID, 200.00), and a third with Op = 'D' (200.00). When Athena queries the external table over that prefix, COUNT(*) returns 3 and SUM(total_amount) returns 600.00 for an order that was actually cancelled and deleted.
Two architectural changes to fix it:
Redirect AWS DMS output to the domain's private internal zone:s3://.../domains/sales/internal/cdc/sales_orders/, never directly to published/.
Add a consolidation and deduplication step (for example, using MERGE INTO on an Apache Iceberg table or a materialization job that selects the latest operation per order_id ordered by dms_timestamp DESC while filtering out Op = 'D') before writing the clean snapshot to published/sales_orders/v1/.
Solution to Exercise 2
Why it happens: AWS Lake Formation vends temporary credentials to read the underlying files of cataloged tables, but Amazon Athena must write the query execution results (output CSV/metadata files) into the S3 output location configured on the Athena Workgroup using the IAM permissions of the querying principal.
Least-privilege fix: Keep domains/* inaccessible in IAM, and grant commerceflow-bi-analyst-role permissions for s3:PutObject, s3:GetObject, s3:AbortMultipartUpload, and s3:ListBucketstrictly scoped to the workgroup's query results prefix (arn:aws:s3:::commerceflow-mesh-lab-111122223333/athena-results/bi-analyst/*) along with s3:GetBucketLocation on the bucket.
Solution to Exercise 3
Additional Lake Formation permission required: The analyst must be granted DESCRIBE on the inventory_products database and SELECT + DESCRIBE on the inventory_products.inventory_availability table (or on the specific columns sku, warehouse_id, available_qty, and snapshot_date).
Amazon Athena SQL Query:
WITH paid_demand_by_sku AS (
SELECT
o.sku,
SUM(o.quantity) AS total_paid_units
FROM sales_products.sales_orders o
INNERJOIN payments_products.confirmed_payments p
ON o.order_id = p.order_id
WHERE o.order_date =DATE'2026-05-10'AND p.payment_date =DATE'2026-05-10'AND o.order_status ='PAID'AND p.payment_status ='CONFIRMED'GROUPBY o.sku
),
current_stock_by_sku AS (
SELECT
sku,
SUM(available_qty) AS total_available_qty
FROM inventory_products.inventory_availability
WHERE snapshot_date =DATE'2026-05-10'GROUPBY sku
)
SELECT
d.sku,
d.total_paid_units,
COALESCE(s.total_available_qty, 0) AS total_available_qty,
(d.total_paid_units -COALESCE(s.total_available_qty, 0)) AS stock_shortfall
FROM paid_demand_by_sku d
LEFTJOIN current_stock_by_sku s
ON d.sku = s.sku
WHERE d.total_paid_units >COALESCE(s.total_available_qty, 0)
ORDERBY stock_shortfall DESC;
Key Takeaways and Decision Criteria
When building a Data Mesh implementation on AWS S3, Glue, Athena, and Lake Formation, keep these practical criteria in mind:
Cloud services enable the mesh, but ownership defines it: Three Glue databases only represent a Data Mesh when each domain separates its private working zone (internal/) from its published contract interface (published/), validates batches before publication, and owns the semantic quality of its data.
Never expose unconsolidated CDC streams as state tables: Tools like AWS DMS are ideal for landing operational changes into a domain's internal zone, but publishing an analytical state product requires consolidating inserts, updates, and deletes first.
Coordinate all five permission layers: Always verify the interaction between IAM service actions, disabling IAMAllowedPrincipals, Lake Formation location registration, KMS key policies, and S3 permissions on the Athena query results prefix.
Design for cost control upfront: Use compressed columnar formats (Apache Parquet), partition by frequently filtered business dates, avoid generating thousands of tiny files, and shut down continuous compute resources (such as DMS replication instances) as soon as lab testing finishes.
A comprehensive hands-on capstone project to design, build, and verify an end-to-end Data Mesh architecture on AWS using S3, Parquet, Glue, Athena, Lake Formation, Terraform, YAML contracts, and Python validations.
Learn how to connect governed Data Products in a Data Mesh with Machine Learning systems, Feature Stores, MLOps, and generative AI RAG architectures while preventing data leakage, semantic errors, and permission breaches.
A practical and strategic guide to planning enterprise Data Mesh adoption: maturity assessment, pilot selection, team topologies, FinOps cost modeling, real outcome KPIs, and criteria to avoid over-engineering.