mypy-boto3-efs Type Annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-efs provides type annotations for the boto3 EFS service, generated using the `mypy-boto3-builder`. These stubs enhance type checking for `boto3` code, allowing tools like MyPy to catch type-related errors before runtime. The current version is 1.42.3, and it follows the frequent release cadence of its builder.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `mypy-boto3-efs` to get type hints for `boto3.client('efs')`. It defines a function to create an EFS file system, explicitly typing the client and the request parameters. Note that `mypy-boto3-efs` provides *only* type stubs; `boto3` must be installed and configured for actual AWS interactions.

import boto3
from mypy_boto3_efs.client import EFSClient
from mypy_boto3_efs.type_defs import CreateFileSystemRequestRequestTypeDef
import os

# Ensure boto3 can find credentials (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or ~/.aws/credentials)
# This example does not explicitly set credentials, relying on default boto3 behavior.

def create_efs_filesystem(token: str) -> None:
    client: EFSClient = boto3.client(
        "efs", 
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )

    request_params: CreateFileSystemRequestRequestTypeDef = {
        "CreationToken": token,
        "PerformanceMode": "generalPurpose",
        "Encrypted": False  # Set to True for encryption
    }

    try:
        response = client.create_file_system(**request_params)
        print(f"Created EFS File System with ID: {response['FileSystemId']}")
        print(f"ARN: {response['FileSystemArn']}")
    except client.exceptions.FileSystemAlreadyExists as e:
        print(f"File system with token '{token}' already exists: {e}")
    except Exception as e:
        print(f"Error creating file system: {e}")

# Example usage (replace with a unique token for actual creation)
# create_efs_filesystem("my-unique-efs-token")
print("Run 'create_efs_filesystem("my-unique-efs-token")' to test")

view raw JSON →