# aws


12/12/2023, 5:39 AM
Hi, I’m trying to create a set of buckets driven by a config file. In this list,
Copy code
  - name: a
    is_primary: true
    region: <region-1>
      - <rules_config>
      region: <region-2>
      storage_class: STANDARD
      name: a-replica
      enabled: true
  - name: a-replica
    region: <region-2>
        - <rules_config>
      region: <region-1>
      name: a
where the first item replicates to the second and vice-versa. There could be more buckets configured like this… I’m trying to follow the bi-directional replication sample here. The sample captures each resource returned to reference it in another spot in the sample. (EX east_bucket_v2 = … and later is used. Is there a way to do this driven by the config file, and in a loop where there can be multiple sets of replicas defined? Ex. (if I add another 2 bucket definitions like above for a total of 4 buckets)?
I guess my question is if I do this in a loop, i would be loosing the references to the first set of buckets created. Is that okay or would I need those references later? If so, how can I save and reuse them?


12/12/2023, 7:54 PM
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.
If you're creating a packagable / distributable tool to allow other people to create resources, then something along these lines may be ok, but then it'd be your problem to cater for any and all changes in the config files. If you're creating an app to deploy your own infrastructure, you simply wouldn't do this. Since the project files and the config files are both developer artifacts, develop your code in the "safer" location.