- Newest
- Most votes
- Most comments
This error occurs when the worker overloads or loses connection to the metadata database, or when a task tries to reuse a closed database connection. The "psycopg2.OperationalError: SSL connection has been closed unexpectedly" error is a common issue in Amazon MWAA environments.
When you upgraded from a small to medium environment class, it's possible that the change in resources affected how your DAG interacts with the metadata database. Here are some troubleshooting steps to resolve this issue:
- Reduce CPU and memory utilization:
- Spread out task schedules
- Narrow imports in your DAG
- Use external services for heavy processing
- Reduce data passed between tasks
- Customize Apache Airflow configurations:
- Adjust celery.worker_autoscale
- Set core.execute_tasks_new_python_interpreter to True
- Set worker, scheduler, and web server logs to at least WARNING level
- Optimize your DAG:
- Use deferrable operators for tasks that submit jobs to external systems
- Remove top-level code that uses unnecessary resources
- Don't use Apache Airflow variables in top-level Python code
- Simplify the DAG structure
- Create an .airflowignore file to disregard non-DAG files during parsing
-
If you're using Apache Airflow v1.x, consider upgrading to Apache Airflow v2.0.2 or later, which allows you to specify up to 5 Schedulers, providing better resource management.
-
For PostgreSQL-specific issues, ensure you have the proper PostgreSQL dependencies in your requirements.txt file:
apache-airflow[postgres]==<your-airflow-version>
- Test your DAGs, custom plugins, and Python dependencies locally using the aws-mwaa-local-runner tool to identify any compatibility issues.
The error is likely not directly caused by the environment class change itself, but rather by how your DAG's resource usage interacts with the new environment configuration. By optimizing your DAG and adjusting configurations, you should be able to resolve the SSL connection issue.
Sources
Troubleshoot error in Amazon MWAA | AWS re:Post
Troubleshooting: CloudWatch Logs and CloudTrail errors - Amazon Managed Workflows for Apache Airflow
Troubleshooting: DAGs, Operators, Connections, and other issues in Apache Airflow v1 - Amazon Managed Workflows for Apache Airflow
answered a year ago
Relevant content
asked 3 years ago
asked 6 years ago
asked 7 months ago
- AWS OFFICIALUpdated 2 years ago

Dag's are developed according to best practices (At least o my knowledge). celery_worker_autoscale was adjusted to "8,4".
what does "core.execute_tasks_new_python_interpreter" do?
Main question still stands, why it worked OK on small environment, but doesn't on medium, I do feel there are some changes in SSL after upgrade.