Overview
Airflow 1.10.10 includes feature that allows you to use Environment Variables to sync Airflow Connections + Variables to secrets held in a few different secret backends, including Hashicorp Vault, GCP Secrets Manager and AWS Parameters Store.
On Astronomer’s 1.10.10 image, the following additional backends are included (not yet available in core Airflow’s 1.10.10 release):
- AWS Secrets Manager
- AWS Vault
Airflow Instructions: https://airflow.apache.org/docs/1.10.10/howto/use-alternative-secrets-backend.html#alternative-secrets-backend
AWS Parameter Store Example
1. Enable with Env Vars
ENV AIRFLOW__SECRETS__BACKEND =airflow.contrib.secrets.aws_systems_manager.SystemsManagerParameterStoreBackend
ENV AIRFLOW__SECRETS__BACKEND_KWARGS
=’{“connections_prefix”: “/airflow/connections”, “variables_prefix”: “/airflow/variables”}’
ENV AWS_DEFAULT_REGION=us-west-2
2A. Set your connection in AWS Parameter Store:
First, set connections_prefix
as /airflow/connections
. The connection itself has three parts:
- Connection Name
- Type
- Value
param = {
'Name': '/airflow/connections/example_postgres',
'Type': 'String',
'Value': 'postgresql://airflow:airflow@host:5432/airflow'
}
Note: SecureString Parameter Type is not yet supported, only String type.
2B. Supply AWS Profile
To authenticate, you can either supply a profile name to reference aws profile, e.g. defined in ~/.aws/config
or set the following Env Vars:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
3. Airflow Hook to pull Connection
Given the example above, using the following in your DAG - BaseHook.get_connection(conn_id="example_postgres")
should give a Connection
object with:
host=host
port=5432
login=airflow
password=airflow