Yes, it's ok, it's just a normal programming problem. You can store the already-created buckets in a map of name-to-bucket.
However you should do this only for learning purposes. This technique is vulnerable to unintended reordering which will cause deletes and re-creates. Also, nearly all production-like use cases would depend on you knowing in advance that you have a certain set of buckets, so you would configure them in your chosen language. Configuring them in a YAML file brings complexities that are not needed.