Run modesallow you to configure yourAEMinstance for a specific purpose (dev, uat, prod, staging), follow this informative blog tutorials to expand your knowledge for how to configure and consume run modes for your AEM development practices:
You can rely on Cloud Manager APIs (1) and set environment variables. This would need an integration via Adobe IO console so you can interact with Cloud manager to do things.