Home > Back-end >  How to change max duration or refresh AWS session in Airflow 2.0
How to change max duration or refresh AWS session in Airflow 2.0

Time:02-11

Can we increase session duration or refresh session for AWS in Apache Airflow v 2.0.2 when we use assume role like in AWS connection extra?

{
  "role_arn": "arn:aws:iam::xxx:role/airflow-connection-role",
  "region_name": "ap-southeast-1"
}

I understand that default max duration is 1 hour and refreshable credential is supported in Airflow 2.1.

But I am currently using Airflow v2.0.2 in MWAA (Amazon Managed Workflows for Apache Airflow). so we can not use the option above.

CodePudding user response:

In apache-airflow-providers-amazon==1.3.0, AwsBaseHook will take kwargs for assuming the role. Set extras in your connection to

{
  "role_arn": "arn:aws:iam::xxx:role/airflow-connection-role",
  "region_name": "ap-southeast-1",
  "assume_role_kwargs": "{ 'DurationSeconds': 7200 }"
}

In the issue you reference, one comment says

After digging a little into the code, it appears that #7619 introduced the ability to set arbitrary kwargs for the assume role function call.

Here are the lines in Airflow supporting this. https://github.com/apache/airflow/blob/0823d46a7f267f2e45195a175021825367938add/airflow/providers/amazon/aws/hooks/base_aws.py#L92 https://github.com/apache/airflow/blob/0823d46a7f267f2e45195a175021825367938add/airflow/providers/amazon/aws/hooks/base_aws.py#L172

  • Related