Type annotations for boto3 AppConfigData

1.42.3 · active · verified Sat Apr 11

mypy-boto3-appconfigdata provides a standalone package of type annotations for the boto3 AppConfigData service client. It enhances development with static type checking by tools like mypy and provides improved IDE autocompletion for `boto3.client("appconfigdata")`. The current version is 1.42.3, with releases typically synchronized with boto3 versions and updates from the mypy-boto3-builder.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `mypy-boto3-appconfigdata` type annotations with a boto3 AppConfigData client. It shows how to initialize the client with type hints, start a configuration session, and retrieve the latest configuration, including the use of generated TypedDicts for method parameters. Environment variables are used for AWS credentials for runnable examples.

import boto3
from mypy_boto3_appconfigdata import AppConfigDataClient
from mypy_boto3_appconfigdata.type_defs import GetLatestConfigurationRequestTypeDef
import os

def get_configuration_data(application: str, environment: str, configuration: str, client_id: str) -> dict:
    session = boto3.Session(
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
        region_name=os.environ.get('AWS_REGION', 'us-east-1')
    )
    client: AppConfigDataClient = session.client("appconfigdata")

    # First, start a session to get a configuration token
    start_session_params = {
        "ApplicationIdentifier": application,
        "ConfigurationIdentifier": configuration,
        "ClientConfigurationVersion": "1.0" # Example version, replace as needed
    }
    start_session_response = client.start_configuration_session(**start_session_params)
    configuration_token = start_session_response["InitialConfigurationToken"]

    # Then, get the latest configuration using the token
    get_config_params: GetLatestConfigurationRequestTypeDef = {
        "ConfigurationToken": configuration_token
    }
    response = client.get_latest_configuration(**get_config_params)
    
    # The configuration is returned as a streaming body
    if 'Configuration' in response and response['Configuration']:
        config_data = response['Configuration'].read().decode('utf-8')
        print(f"Received configuration: {config_data}")
        return {"data": config_data, "content_type": response.get('ContentType')}
    return {}

# Example usage (will use dummy credentials if env vars are not set)
if __name__ == "__main__":
    # These values would typically come from your AppConfig setup
    app_id = "MyApplication"
    env_id = "MyEnvironment"
    config_id = "MyConfigurationProfile"
    client_id = "my-unique-client"

    print("Attempting to get AppConfig data...")
    config = get_configuration_data(app_id, env_id, config_id, client_id)
    if config:
        print("Successfully retrieved configuration.")
    else:
        print("Failed to retrieve configuration or no configuration found.")

view raw JSON →