import click


def create_instance(config):
    """Create (and start) a new EC2 instance using the default AMI.
    """
    if not config.ami_default:
        raise click.UsageError(
            'No default AMI specified. Cannot create instances.'
        )
    res = config.ec2.run_instances(
        ImageId=config.ami_ids[config.ami_default],
        InstanceType=config.ec2_type,
        MinCount=1,
        MaxCount=1,
        KeyName=config.key_name,
        SecurityGroups=[config.security_group],
    )
    assert len(res['Instances']) == 1
    return res['Instances'][0]