DEV Community

Cover image for Read cloud specific configuration from configuration files
Rahul Kashyap
Rahul Kashyap

Posted on

Read cloud specific configuration from configuration files

Configuration specific to cloud provider can be separated in a config file by setting cloud provider name as a section.

Define a configuration file

Create a configuration file - config.ini in the src package and define cloud provider specific configuration similar to below.

[aws]
bucket_name: test-aws-bucket

[gcp]
bucket_name: test-gcp-bucket
Enter fullscreen mode Exit fullscreen mode

Read the configuration in the code

Read cloud provider from environment variable.

cloud_provider = os.environ.get('CLOUD_PROVIDER')

Declare a config parser in python and read the configuration file

config = configparser.ConfigParser()
config_path = os.path.join(os.path.dirname(__file__), 'config.ini')
config.read(config_path)
bucket_name = config.get(cloud_provider,'bucket_name')
Enter fullscreen mode Exit fullscreen mode

In this way, we can separate cloud provider specific configuration in config files.

Please feel free to comment with any suggestions/feedback.

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay