Closed ihsanashi closed 2 years ago
Command for getting all the filenames from a particular folder in an S3 bucket, and saving them to a local file:
aws s3api list-objects --bucket your-bucket-name --prefix "example/sub/directory/" > /Users/example/folder/sub/folder/filenames.json
Original JSON dump from AWS includes the root object for each folder, eg. /instagram/stories, so those were deleted. I also have uploaded metadata files for each folder (photos, stories & videos) to S3 as a backup, these were also included in the JSON dump, and manually deleted in the local JSON file. Also, I removed the first key whose values is the array of objects in each JSON file, eg. "stories" key in stories.json file, to ensure the file is just an array of objects, with no parent key referring to said array.
Then I use jq to manipulate the JSON files to only have the key value pairs that I need.
Supabase schema
jq
to remove undesired keys from each JSON file returned from running the previous AWS CLI commands (should only be left withKey
andLastModified
keys)jq
to transform JSON data from the previous step, to create a new JSON file withpath
andlast_modified_at
keys. Forpath
, prefix with{AWS_REGION}/{AWS_BUCKET_NAME}
.Maybe this part can be done when merging the modified AWS JSON with Instagram metadata JSON files.Transformed the keys first.jq
to combine data from AWS CLI with metadata JSON files from Instagram to the correct format (accounting for alt text, caption and URL paths). The common key/value pair is thepath
.jq
to insert a new key for AWS & cloudinary URLs in the merged JSON fileINSERT
query for each object to run inpostgresSupabase