aws-samples / aws-media-services-simple-live-workflow

Workshop that covers AWS Elemental MediaLive, MediaPackage, and MediaTailor services
Apache License 2.0
169 stars 59 forks source link

Using type RTMP instead of HLS when creating MediaLive Inputs #14

Open edwin0527 opened 5 years ago

edwin0527 commented 5 years ago
def create_input(medialive, event, context, auto_id=True):
"""
Create a MediaLive input
"""

if auto_id:
    input_id = "%s-%s" % (resource_tools.stack_name(event),
                          event["LogicalResourceId"])
else:
    input_id = event["PhysicalResourceId"]

try:
    response = medialive.create_input(
        Name=input_id,
        Type='URL_PULL',
        Sources=[
            {'Url': event["ResourceProperties"]["HLSPrimarySource"]},
            {'Url': event["ResourceProperties"]["HLSSecondarySource"]}
        ]
    )

    print(json.dumps(response))

    # wait for the new input to reach detached state
    resource_tools.wait_for_input_states(medialive, response['Input']['Id'], ['DETACHED'])

    result = {
        'Status': 'SUCCESS',
        'Data': response,
        'ResourceId': response['Input']['Id']
    }

except Exception as ex:
    print(ex)
    result = {
        'Status': 'FAILED',
        'Data': {"Exception": str(ex)},
        'ResourceId': response['Input']['Id']
    }

return result

Do I change the following from

    try:
        response = medialive.create_input(
            Name=input_id,
            Type='URL_PULL',
            Sources=[
                {'Url': event["ResourceProperties"]["HLSPrimarySource"]},
                {'Url': event["ResourceProperties"]["HLSSecondarySource"]}
            ]
        )

to something like this:

        response = medialive.create_input(
            Name=input_id,
            Type='RTMP_PUSH',
            InputSecurityGroups=[
                '3525785',
            ]
            Destination=[
                {'"StreamName": "live/stream"}
            ]
        )
JimTharioAmazon commented 5 years ago

That looks good, but I believe you will need to provide two Destinations since MediaLive creates redundant input pipelines. Each destination should come back in the create-input response with an IP addresses in different availability zones. As in:

"Destinations": [ { "Ip": "54.203.XY.178", "Port": "1935", "Url": "rtmp://54.203.XY.178:1935/jimmy-test-rtmpA/" }, { "Ip": "35.163.217.ZZ", "Port": "1935", "Url": "rtmp://35.163.217.ZZ:1935/jimmy-test-rtmpB/" } ]