mypy-boto3-amplifybackend Type Annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-amplifybackend provides type annotations for the `boto3` AWS AmplifyBackend service. It ensures static type checking for your boto3 calls, catching potential errors at development time. This package is part of the `mypy-boto3-builder` ecosystem, currently at version 1.42.3, and releases frequently, synchronized with `boto3` and `botocore` updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-amplifybackend` to add type hints to your boto3 AmplifyBackend client calls. It includes defining request payloads using type definitions and ensures type safety for the client object and its methods.

import boto3
from mypy_boto3_amplifybackend import AmplifyBackendClient
from mypy_boto3_amplifybackend.type_defs import CreateBackendRequestRequestTypeDef, ResourceConfigTypeDef, AmplifyBackendTypeDef

def create_amplify_backend(app_id: str, app_name: str, region_name: str = "us-east-1") -> AmplifyBackendTypeDef:
    """
    Demonstrates creating an Amplify Backend using a type-hinted boto3 client.
    Note: A real backend creation requires more specific configurations
    and an existing Amplify application. This is a minimal example for typing.
    """
    
    # Initialize the AmplifyBackend client with type hints
    client: AmplifyBackendClient = boto3.client("amplifybackend", region_name=region_name)

    # Example minimal resource configuration
    resource_config: ResourceConfigTypeDef = {
        "BackendManagerAppId": "amplify", # Often "amplify" for Amplify Console managed backends
        "AmplifyMetaConfig": {} # Typically contains ARN, Region, etc.
    }

    # Prepare the request payload using type definitions
    request_payload: CreateBackendRequestRequestTypeDef = {
        "AppId": app_id,
        "AppName": app_name,
        "ResourceConfig": resource_config,
        "ResourceType": "Amplify", # Or "Auth", "Storage", "API" depending on what you're creating
    }

    try:
        print(f"Attempting to create Amplify Backend for AppId: {app_id}, AppName: {app_name}...")
        response: AmplifyBackendTypeDef = client.create_backend(**request_payload)
        print("Backend creation initiated successfully.")
        print(f"Operation ID: {response.get('OperationId')}")
        print(f"App ID: {response.get('AppId')}")
        return response
    except client.exceptions.NotFoundException:
        print(f"Error: Amplify App with ID '{app_id}' not found.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
    return {}

if __name__ == "__main__":
    # Replace with your actual Amplify App ID and a desired app name
    # Ensure AWS credentials are configured (e.g., via ~/.aws/credentials or environment variables)
    # This example won't actually succeed without a valid pre-existing Amplify app ID
    # and potentially more detailed ResourceConfig.
    dummy_app_id = "d123456789abc" # This should be a real Amplify App ID for testing
    dummy_app_name = "MyAmplifyBackendApp"
    
    # To run this code, replace dummy_app_id and dummy_app_name with real values
    # and ensure your AWS environment is configured for boto3.
    # result = create_amplify_backend(dummy_app_id, dummy_app_name)
    # print(result)
    print("Quickstart complete. Modify `dummy_app_id` and `dummy_app_name` to test with real values.")

view raw JSON →