mypy-boto3-mwaa: Type Annotations for AWS MWAA

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` client for MWAA and apply the `MWAAClient` type annotation. It also shows an example of using a `TypedDict` for a request, which is common for complex `boto3` API calls. Remember to install `boto3` alongside the type stubs.

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'
    )

view raw JSON →