def create_channel()

in source/customresources/custom-resource-py/lib/medialive.py [0:0]


def create_channel(config):
    # set InputSpecification based on the input resolution:
    if config['Resolution'] == '1080':
        res = 'HD'
        bitrate = 'MAX_20_MBPS'
        profile = './encoding-profiles/medialive-1080p30-settings.json'

    #hotfix/V52152945 loop only supported in HLS_PULL
    if config['Type'] == 'URL_PULL':
        settings = {
                "AudioSelectors": [],
                "CaptionSelectors": [
                    {
                        "Name": "empty"
                    }
                ],
                "DeblockFilter": "DISABLED",
                "DenoiseFilter": "DISABLED",
                "FilterStrength": 1,
                "InputFilter": "AUTO",
                "SourceEndBehavior": "LOOP"
        }
    else:
        settings = {
                "AudioSelectors": [],
                "CaptionSelectors": [
                    {
                        "Name": "empty"
                    }
                ],
                "DeblockFilter": "DISABLED",
                "DenoiseFilter": "DISABLED",
                "FilterStrength": 1,
                "InputFilter": "AUTO"
        }

    with open(profile) as encoding:
        EncoderSettings = json.load(encoding)

    response = medialive.create_channel(
        InputSpecification = {
            'Codec': config['Codec'],
            'Resolution':res,
            'MaximumBitrate':bitrate
        },
        InputAttachments = [{
            'InputId': config['InputId'],
            "InputSettings": settings
        }],
        ChannelClass='SINGLE_PIPELINE',
        Destinations = [{
            "Id": "destination1",
            "MediaPackageSettings": [],
            "Settings": [
                {
                    'PasswordParam': config['MediaPackagePriUser'],
                    'Url': config['MediaPackagePriUrl'],
                    'Username': config['MediaPackagePriUser']
                }
            ]
        },
        {
            "Id": "destination2",
            "MediaPackageSettings": [],
            "Settings": [
                {
                    "Url": config['UDPAudioPriUrl'] 
                    # Example "udp://name-aa5b21d06e6c434c.elb.us-east-1.amazonaws.com:7950"
                }
            ]
        }],
        Name = config['Name'],
        RoleArn = config['Role'],
        EncoderSettings = EncoderSettings,
    )
    # Feature/V103650687 check channel create completes.
    # Valid states are CREATING, CREATE_FAILED and IDLE
    channel_id = response['Channel']['Id']

    while True:
        channel = medialive.describe_channel(
            ChannelId = channel_id
        )
        if channel['State'] == 'IDLE':
            time.sleep(3)
            # Get the Eggress IP Addresses 
            print("Here is the channel response")
            print(str(channel))
            responseData['EgressIpPipe0'] = channel['EgressEndpoints'][0]['SourceIp']

            break
        elif channel['State'] == 'CREATE_FAILED':
            raise Exception('Channel Create Failed')
        else:
            time.sleep(3)

    responseData['ChannelId'] = channel_id

    print('RESPONSE::{}'.format(responseData))
    return responseData