IO Config Setup Guide
Theio_config
file is a crucial configuration file in Mage that stores credentials and connection information for accessing various data sources. This guide will help you understand where to store it and how to create it from scratch.
File Location
Theio_config
file should be stored in your Mage project’s root directory. The default path is:
Creating a New io_config File
1. Basic Structure
Create a new file namedio_config.yaml
in your project’s root directory (e.g. /home/src/your_mage_project
) with the following basic structure:
2. Configuration Formats
Mage supports two formats for theio_config
file:
Standard Format (Recommended)
Legacy Format (Verbose)
3. Using Variables and Secrets
For security, it’s recommended to use environment variables and other secret management systems for sensitive information. Mage provides several variable syntax options:Variable Syntax
Syntax | Description |
---|---|
{{ env_var('secret') }} | Get secret from environment variables |
{{ mage_secret_var('secret') }} | Get secret from Mage secrets |
{{ aws_secret_var('secret') }} | Get secret from AWS Secrets Manager |
{{ azure_secret_var('secret') }} | Get secret from Azure Key Vault |
{{ gcp_secret_var('secret') }} | Get secret from Google Cloud Secret Manager (Mage Pro only) |
{{ json_value(json_obj, 'key') }} | Extract value from a JSON string |
{{ file('path/to/file.txt') }} | Load contents of a local file (Mage Pro only) |
Example Configurations
Environment Variables:4. Multiple Profiles
You can create multiple profiles for different environments or use cases:Using io_config in Your Code
SQL Block Example
In SQL blocks, you can select the desired IO Config profile from the UI using the “Profile” dropdown menu. For detailed information about configuring SQL blocks, see the SQL Blocks documentation.Python Block Examples
You can useio_config
in your Python code with different profile selection strategies:
Basic Profile Usage:
Best Practices
-
Security:
- Never commit sensitive credentials directly in the
io_config
file - Use environment variables or secret variables for sensitive information
- Consider using a secrets management service for production environments
- Never commit sensitive credentials directly in the
-
Organization:
- Use meaningful profile names
- Group related configurations together
- Document any non-standard configurations
- Use the standard format for new configurations
-
Version Control:
- Add
io_config.yaml
to your.gitignore
file - Provide a template file (
io_config.yaml.template
) with dummy values - Document the required environment variables
- Add
Troubleshooting
Common Issues & Solutions
1. “FileNotFoundError” or “No such file or directory”- Make sure your
io_config.yaml
file exists in your project root (e.g.,/home/src/your_mage_project/io_config.yaml
). - If running in a different environment (e.g., Docker), confirm the file is mounted and accessible.
- Double-check that the profile name you are referencing in your code (e.g.,
'default'
,'staging'
) exists in yourio_config.yaml
. - Profile names are case-sensitive.
- Ensure all required fields for your data source/destination are present in the selected profile.
- If you use
{{ env_var('VAR_NAME') }}
in your config, make sure the environment variable is set in deployment environment. - You can check this by running
echo $VAR_NAME
in Mage terminal.
- Use a YAML linter or validator to check for indentation or formatting issues.
- Strings containing special characters (like
:
or{}
) should be quoted.
- Double-check your credentials and permissions.
- For cloud services, ensure your service account or IAM user has the necessary roles.
- Make sure you are importing from
mage_ai.io.config
(notmage_ai.io.io_config
). - Example:
- In the Mage UI, select the correct profile from the “Profile” dropdown before running your SQL block.