mypy-boto3-mwaa: Type Annotations for AWS MWAA
mypy-boto3-mwaa provides type annotations for the `boto3` client and service resource for AWS Managed Workflows for Apache Airflow (MWAA). It is part of the `mypy-boto3` project, ensuring type safety for your AWS interactions. This package, currently at version 1.42.3, is updated frequently in tandem with new boto3 releases.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (and consequently packages like `mypy-boto3-mwaa` released after it), support for Python 3.8 has been removed. Projects requiring Python 3.8 should use older versions of `mypy-boto3` packages.
- gotcha The version of `mypy-boto3-mwaa` should ideally match the version of `boto3` used at runtime. Mismatched versions can lead to incorrect type hints or `mypy` errors, especially when `boto3` introduces new features or changes existing APIs.
- gotcha This package provides *only* type annotations for `boto3`. It does not include the `boto3` library itself. You must install `boto3` separately for your application to function at runtime.
- breaking The `mypy-boto3-builder` (which generates `mypy-boto3-mwaa`) sometimes changes the naming conventions for generated `TypedDict`s. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef` in `builder` v8.9.0. If you explicitly import and use specific `TypedDict` names, these changes can break your type checks.
Install
-
pip install boto3 mypy-boto3-mwaa
Imports
- MWAAClient
from mypy_boto3_mwaa import MWAAClient
- CreateEnvironmentRequestRequestTypeDef
from mypy_boto3_mwaa.type_defs import CreateEnvironmentRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_mwaa import MWAAClient
from mypy_boto3_mwaa.type_defs import CreateEnvironmentRequestRequestTypeDef
def create_mwaa_environment(
env_name: str,
bucket_name: str,
execution_role_arn: str
) -> dict:
client: MWAAClient = boto3.client('mwaa')
# Example of using a TypedDict for a complex request body
environment_config: CreateEnvironmentRequestRequestTypeDef = {
'Name': env_name,
'SourceBucketArn': f'arn:aws:s3:::{bucket_name}',
'ExecutionRoleArn': execution_role_arn,
'AirflowVersion': '2.6.3',
'EnvironmentClass': 'mw1.small',
'MaxWorkers': 1,
'NetworkConfiguration': {
'SubnetIds': ['subnet-xxxxxxxxxxxxxxxxx'], # Replace with actual subnet IDs
'SecurityGroupIds': ['sg-xxxxxxxxxxxxxxxxx'] # Replace with actual security group IDs
}
}
# This call is for demonstration and requires a valid MWAA setup
# response = client.create_environment(**environment_config)
# print(f"Environment creation initiated: {response}")
# For a simple type-checked call, without actual creation:
list_envs_response = client.list_environments()
print(f"Listed MWAA environments: {list_envs_response.get('Environments')}")
return list_envs_response
# Example usage (requires valid AWS credentials and configuration)
# This code will run and show type checking benefits even if the API call is commented out
if __name__ == "__main__":
# Replace with your actual values for a real run
# env_name = "my-airflow-env"
# bucket_name = "my-airflow-bucket"
# execution_role_arn = "arn:aws:iam::123456789012:role/MyMWAAExecutionRole"
# create_mwaa_environment(env_name, bucket_name, execution_role_arn)
create_mwaa_environment(
'example-env', 'example-bucket', 'arn:aws:iam::123456789012:role/ExampleRole'
)