mypy-boto3-amplifybackend Type Annotations
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
- breaking Python 3.8 support was removed for all `mypy-boto3` packages starting with `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-amplifybackend` 1.42.3).
- breaking TypeDef naming conventions were changed in `mypy-boto3-builder` 8.9.0. This can break code that explicitly imports and uses specific TypeDef names if they were affected by the shortening of 'RequestRequestTypeDef' to 'RequestTypeDef' or the reordering of 'Extra' suffixes.
- gotcha For full type-checking of dynamic `boto3.client()` and `boto3.resource()` calls (e.g., `boto3.client("amplifybackend")`), `mypy` must be configured with the `boto3.mypy_boto3_plugin`.
- gotcha `mypy-boto3` stub versions are designed to synchronize with `boto3` releases. Using a `mypy-boto3-amplifybackend` version that significantly differs from your installed `boto3` can lead to incorrect or missing type hints.
Install
-
pip install mypy-boto3-amplifybackend
Imports
- AmplifyBackendClient
from mypy_boto3_amplifybackend import AmplifyBackendClient
- CreateBackendRequestRequestTypeDef
from mypy_boto3_amplifybackend.type_defs import CreateBackendRequestRequestTypeDef
Quickstart
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.")