Utilisation d'une clé secrète dansAWS Secrets Managerpour une connexion Apache Airflow Snowflake - Amazon Managed Workflows for Apache Airflow

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Utilisation d'une clé secrète dansAWS Secrets Managerpour une connexion Apache Airflow Snowflake

Les exemples d'appels suivantsAWS Secrets Managerpour obtenir une clé secrète pour une connexion Apache Airflow Snowflake sur Amazon Managed Workflows pour Apache Airflow. Cela suppose que vous avez suivi les étapes décrites dansConfiguration d'une connexion Apache Airflow à l'aide d'un secret AWS Secrets Manager.

Version

  • Vous pouvez utiliser l'exemple de code de cette page avecApache Airflow v2 et versions ultérieuresdansPython 3.10.

Prérequis

Pour utiliser l'exemple de code de cette page, vous aurez besoin des éléments suivants :

Autorisations

Prérequis

Pour utiliser l'exemple de code de cette page, ajoutez les dépendances suivantes à votrerequirements.txt. Pour en savoir plus, consultez Installation des dépendances Python.

apache-airflow-providers-snowflake==1.3.0

Exemple de code

Les étapes suivantes décrivent comment créer le code DAG qui appelle Secrets Manager pour obtenir le secret.

  1. Dans votre invite de commandes, accédez au répertoire dans lequel votre code DAG est stocké. Par exemple :

    cd dags
  2. Copiez le contenu de l'exemple de code suivant et enregistrez-le localement soussnowflake_connection.py.

    """ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from airflow import DAG from airflow.providers.snowflake.operators.snowflake import SnowflakeOperator from airflow.utils.dates import days_ago snowflake_query = [ """use warehouse "MY_WAREHOUSE";""", """select * from "SNOWFLAKE_SAMPLE_DATA"."WEATHER"."WEATHER_14_TOTAL" limit 100;""", ] with DAG(dag_id='snowflake_test', schedule_interval=None, catchup=False, start_date=days_ago(1)) as dag: snowflake_select = SnowflakeOperator( task_id="snowflake_select", sql=snowflake_query, snowflake_conn_id="snowflake_conn", )

Quelle est la prochaine étape ?