I found this script which does the trick
#!/bin/bash
# Get the time one hour ago in ISO 8601 format
one_hour_ago=$(date -u -d '1 hour ago' +'%Y-%m-%dT%H:%M:%SZ')
# List all the latest delete markers
delete_markers=$(aws s3api list-object-versions --bucket my-bucket --prefix my-folder/ --query 'DeleteMarkers[?IsLatest==`true`].[Key, VersionId, LastModified]' --output text)
# Delete only the delete markers set within the last hour
while IFS=$'\t' read -r key version_id last_modified; do
if [[ "$last_modified" > "$one_hour_ago" ]]; then
echo "Deleting delete marker for $key with version ID $version_id, set at $last_modified"
aws s3api delete-object --bucket my-bucket --key "$key" --version-id "$version_id"
fi
done <<< "$delete_markers"
source: https://dev.to/siddhantkcode/how-to-recover-an-entire-folder-in-s3-after-accidental-deletion-173f