Using a secret key in Amazon Secrets Manager for an Apache Airflow connection
The following sample calls Amazon Secrets Manager to get a secret key for an Apache Airflow connection on Amazon Managed Workflows for Apache Airflow. It assumes you've completed the steps in Configuring an Apache Airflow connection using a Amazon Secrets Manager secret.
Version
-
The sample code on this page can be used with Apache Airflow v1 in Python 3.7
.
-
You can use the code example on this page with Apache Airflow v2 in Python 3.10
.
Prerequisites
To use the sample code on this page, you'll need the following:
-
The Secrets Manager backend as an Apache Airflow configuration option as shown in Configuring an Apache Airflow connection using a Amazon Secrets Manager secret.
-
An Apache Airflow connection string in Secrets Manager as shown in Configuring an Apache Airflow connection using a Amazon Secrets Manager secret.
Permissions
-
Secrets Manager permissions as shown in Configuring an Apache Airflow connection using a Amazon Secrets Manager secret.
Requirements
-
To use this code example with Apache Airflow v1, no additional dependencies are required. The code uses the Apache Airflow v1 base install
on your environment.
-
To use this code example with Apache Airflow v2, no additional dependencies are required. The code uses the Apache Airflow v2 base install
on your environment.
Code sample
The following steps describe how to create the DAG code that calls Secrets Manager to get the secret.
What's next?
-
Learn how to upload the DAG code in this example to the
dags
folder in your Amazon S3 bucket in Adding or updating DAGs.