Skip to content

How I can compare two AWS S3-Buckets, to generate some comparison report

0

I am having AWS S3 buckets with version enabled. For each object

  • Object Key
    • VersionId , Last Modified , size

Is there any Service available to achieve this report whether data from S3 buckets having match in context with above mentioned criteria ? It is possible to write a java utility, but interested into looking for AWS way of running some service which can give data on this. AWS Lambda cant be use here since its short termed service and iterating over each and every key w.r.t. versions took considerable time period.

Currently I am having a Java based utility ready with me which can do iterative data collection and eventually do compare, but that's still manually doing fetching operation.

If something AWS having already such comparison then it will be value added for us. This is only comparison requirement and not sync based operation which will move data w.r.t. each other.

asked 2 years ago547 views

2 Answers
3

You can create an S3 Inventory job and the output can be used to compare objects with the same name but with different version IDs. This will provide you with information about the creation date, size, IsLatest and Etag (maybe useful if the objects are small and not uploaded with Multipart)

You can find more information about the S3 Inventory service here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage-inventory.html

answered 2 years ago

EXPERT

reviewed 2 years ago

2

You can consider the following high-level approaches:

Solution 1: AWS S3 Inventory + Amazon Athena Query

  1. Enable S3 Inventory for both S3 buckets.

    • Configure S3 Inventory on each bucket to produce regular reports (daily or weekly) containing object metadata, including object keys, version IDs, last modified timestamps, and sizes. These reports are stored in a designated S3 bucket.
  2. Leverage Amazon Athena to perform queries on the S3 Inventory reports.

    • Create Athena tables for each bucket's inventory reports.
    • Write SQL queries to compare the object data between the two buckets, focusing on key differences like missing objects, version mismatches, or size discrepancies.
    • Generate a comparison report to identify and highlight these differences.

    This solution is ideal for handling large datasets efficiently, as Athena allows you to perform serverless SQL queries on the inventory data.

Solution 2: AWS S3 Inventory + Python (Boto3)

  1. Set up S3 Inventory for both buckets, as in Solution 1, to generate object metadata reports.

  2. Use Python and Boto3 to programmatically compare the reports.

    • Load the S3 Inventory CSV reports into your Python environment.
    • Utilize the Boto3 library to fetch metadata from both S3 buckets.
    • Implement logic to compare object keys, version IDs, last modified timestamps, and sizes across the two buckets.
    • Generate a detailed report highlighting any discrepancies, such as objects missing in one bucket, different version IDs, or size differences.

    This solution offers more flexibility and control if you prefer a programmatic approach for automation.

Both methods leverage S3 Inventory for scalable object metadata management. The choice between Athena or Python depends on whether you prefer a query-based solution (Athena) or require a more customized, automated approach (Python with Boto3).

When implementing any of these solutions, please ensure to follow best practices and AWS guidelines for bucket access and data handling.

Consolidate and query Amazon S3 Inventory reports for Region-wide object-level visibility

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.