def restart_ecs_service_resource_handler(event, context):
    """Lambda handler function to restart an ECS service, as a CloudFormation resource.

    This is intended to be used in an inline deployment. The physical ID is
    the ID of the ECS service deployment
    """
    import cfnresponse
    import logging
    logging.basicConfig(level=logging.DEBUG)
    LOGGER = logging.getLogger('restarter')
    try:
        import boto3
        ecs = boto3.client('ecs')
        response = {}
        physical_id = event.get('PhysicalResourceId')
        if event['RequestType'] in ['Create', 'Update']:
            properties = event['ResourceProperties']
            update_result = ecs.update_service(cluster=properties[
                'ClusterArn'], service=properties['ServiceArn'],
                forceNewDeployment=True)
            deployment = update_result['service']['deployments'][0]
            physical_id = deployment['id']
            ecs.get_waiter('services_stable').wait(cluster=properties[
                'ClusterArn'], services=[properties['ServiceArn']])
        elif event['RequestType'] == 'Delete':
            LOGGER.info('Ignoring request to delete resource for deployment %s'
                , physical_id)
        else:
            raise ValueError('Unknown CloudFormation request type')
        cfnresponse.send(event, context, cfnresponse.SUCCESS, response,
            physical_id)
    except Exception as ex:
        LOGGER.exception('argh!')
        cfnresponse.send(event, context, cfnresponse.FAILED, {})
