如何在 Airflow 2.0 中更改最长持续时间或刷新 AWS 会话

How to change max duration or refresh AWS session in Airflow 2.0

当我们像在 AWS connection extra 中一样使用 assume role 时,我们能否在 Apache Airflow v 2.0.2 中增加 AWS 的会话持续时间或刷新会话?

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

我了解默认的最长持续时间为 1 小时,Airflow 2.1 支持可刷新凭证。

但我目前在 MWAA(Amazon Managed Workflows for Apache Airflow)中使用 Airflow v2.0.2。所以我们不能使用上面的选项。

在apache-airflow-providers-amazon==1.3.0中,AwsBaseHook将采用kwargs来承担这个角色。在您的连接中将 extras 设置为

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

在您提到的问题中,一条评论说

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

以下是 Airflow 中支持这一点的行。 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