#!/bin/bash

# Check if an argument is provided
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <path_to_amplify_outputs.json>" >&2
    exit 1
fi

input_file="$1"

# Check if the input file exists
if [ ! -f "$input_file" ]; then
    echo "Error: File not found: $input_file" >&2
    exit 1
fi

# Extract the bucket_name
bucket_name=$(grep -m1 '"bucket_name":' "$input_file" | sed 's/.*"bucket_name": *"\([^"]*\)".*/\1/')

# Check if bucket_name was found
if [ -z "$bucket_name" ]; then
    echo "Error: bucket_name not found in $input_file" >&2
    exit 1
fi

# Output the bucket_name
echo "$bucket_name"