Creating connection outside of Airflow GUI

纵饮孤独 提交于 2019-12-04 06:22:06

You can use the airflow CLI. Unfortunately there is no support for editing connections, so you would have to remove and add as part of your deployment process, e.g.:

airflow connections -d --conn_id 'aws_default'
airflow connections -a --conn_id 'aws_default' --conn_uri 'aws:' --conn_extra '{"region_name": "eu-west-1"}'

The query part of the URI will be transformed into a JSON and copied into the extra field of the connection so you can do this:

export AIRFLOW_CONN_S3_DEFAULT=s3://s3/?aws_account_id=99999999,role_arn=bbbbb

Looks silly but it should work. See Connection.

I was able to figure it out after checking out S3_hook.py

For example:

export AIRFLOW_CONN_S3_DEFAULT={"aws_account_id":"99999999","role_arn":"bbbbb"}

Here:

  • "S3_DEFAULT" is the connection id here
  • And passing AWS account id and role_arn and creating an environment variable.

It's probably late but now there is a section in the documentation about this:

When referencing the connection in the Airflow pipeline, the conn_id should be the name of the variable without the prefix. For example, if the conn_id is named postgres_master the environment variable should be named AIRFLOW_CONN_POSTGRES_MASTER (note that the environment variable must be all uppercase). Airflow assumes the value returned from the environment variable to be in a URI format (e.g. postgres://user:password@localhost:5432/master or s3://accesskey:secretkey@S3).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!