This guide walks through the process of replicating your own public S3 bucket and its metadata into CKAN using the Python script.
You must have the following:
- An AWS account with access to the bucket you want to migrate
- The bucket must be owned by your IAM user.
- The bucket must be public so that links in CKAN work.
Your environment must have:
- Python 3
- boto3 installed
- requests installed
- AWS CLI configured:
aws configure(using your IAM credentials)
Make sure your your bucket is public and owned by your user.
- Set a public bucket policy: Go to the S3 console > your bucket > Permissions > Bucket Policy and paste this. Make sure to replace your bucket name.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketListPermissions",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME"
},
{
"Sid": "PublicReadObjects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}
-
Disable “Block Public Access”: Go to the "Permissions" tab in your bucket. Click "Edit" on “Block public access (bucket settings)”. Uncheck all boxes and confirm the change.
-
You can verify that the bucket is accessible: Visit a file directly in the browser:
https://YOUR_BUCKET_NAME.s3.amazonaws.com/EXAMPLE.txt
In main.py, update the following lines with your bucket name and AWS credentials:
bucket_name = "YOUR_BUCKET_NAME"
s3_client = get_s3_client("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY")Run the script in your terminal:
python aws_main.pyWhat this program does :
- Extract bucket metadata (creation date, region, tags)
- List all files and collect object-level metadata (size, content type, etc)
- Generate public URLs to each file
- Create a new dataset in CKAN using your bucket metadata
- Add each object as a resource (using its public S3 URL)
- Go to the CKAN (https://ckan.cyverse.rocks/)
- Log in with your account
- Find the dataset created (named after your bucket)