import json


def create_button(action, 
                  payload, 
                  label, 
                  display_mode='popup', 
                  disabled=False):
    """
    This function creates an HTML button the user can interact with from
    a CloudWatch custom widget.
    
    Parameters:
        action (string):
            The ARN of a lambda function to call when clicking on this button
        payload (string):
            A JSON formatted string that will be passed as argument to the
            lambda function used as endpoint for this button
        label (string):
            The label to use on the button
        display_mode (string):
            Can either be `popup` (display the result in a popup) or `widget` 
            (to replace the content of the current widget by the output of the 
            Lambda function used as endpoint). Defaults to `popup`
        disabled (boolean):
            Set to True to display a disabled button
            
    Returns:
        string: an HTML string with the button to display
    """
    if disabled:
        button_style = 'awsui-button-disabled'
        disabled = 'disabled=""'
        
    else:
        button_style = 'awsui-button awsui-button-variant-primary'
        disabled = ""
    
    button = (
        f'<a class="btn {button_style}" {disabled}>{label}</a>\n'
        '<cwdb-action '
            f'action="call" '
            f'endpoint="{action}" '
            f'display="{display_mode}">'
            f'{json.dumps(payload)}'
        '</cwdb-action>\n'
    )
    
    return button