def delete_channel(medialive, event, context): """ Delete a MediaLive channel Return success/failure """ channel_id = event["PhysicalResourceId"] try: # stop the channel medialive.stop_channel(ChannelId=channel_id) # wait untl the channel is idle, otherwise the lambda will time out resource_tools.wait_for_channel_states(medialive, channel_id, ['IDLE']) except Exception as ex: # report it and continue print(ex) try: response = medialive.delete_channel(ChannelId=channel_id) result = {'Status': 'SUCCESS', 'Data': {}, 'ResourceId': channel_id} except Exception as ex: print(ex) result = { 'Status': 'FAILED', 'Data': { "Exception": str(ex) }, 'ResourceId': channel_id } return result
def create_channel(medialive, event, context, auto_id=True): """ Create a MediaLive channel Return the channel URL, username and password generated by MediaLive """ if auto_id: channel_id = "%s-%s" % (resource_tools.stack_name(event), event["LogicalResourceId"]) else: channel_id = event["PhysicalResourceId"] try: destinations = { 'p_url': event["ResourceProperties"]["PackagerPrimaryChannelUrl"], 'p_u': event["ResourceProperties"]["PackagerPrimaryChannelUsername"], 'p_p': event["ResourceProperties"]["PackagerPrimaryChannelPassword"], 'b_url': event["ResourceProperties"]["PackagerSecondaryChannelUrl"], 'b_u': event["ResourceProperties"]["PackagerSecondaryChannelUsername"], 'b_p': event["ResourceProperties"]["PackagerSecondaryChannelPassword"] } print("The Destinations are: %s \n" % destinations) channel_id = create_live_channel( event["ResourceProperties"]["MediaLiveInputId"], channel_id, event["ResourceProperties"]["Resolutions"], destinations, event["ResourceProperties"]["MediaLiveAccessRoleArn"], medialive) result = {'Status': 'SUCCESS', 'Data': {}, 'ResourceId': channel_id} # wait until the channel is idle, otherwise the lambda will time out resource_tools.wait_for_channel_states(medialive, channel_id, ['IDLE']) if event['State'] == "ON": medialive.start_channel(ChannelId=channel_id) except Exception as ex: print(ex) result = { 'Status': 'FAILED', 'Data': { "Exception": str(ex) }, 'ResourceId': channel_id } return result