def handler(event, aws_config):
    target = get_target(event)

    ec2 = get_aws_resource('ec2', aws_config)
    instance = ec2.Instance(str(target))

    instance.reboot()

    return fulfill(event, 'success')
def handler(event):
    date = event['currentIntent']['slots'].get('date')
    time = event['currentIntent']['slots'].get('time')
    schedule_datetime = parse(str(date) + ' ' + str(time), ignoretz=True)

    event['sessionAttributes']['scheduling_status'] = 'set_in_this_fulfillment'
    event['sessionAttributes']['scheduling_datetime'] = str(schedule_datetime)

    return fulfill(event, 'schedule_set_in_progress')
Beispiel #3
0
def __schedule(event):
    event_copy = copy(event)
    event_copy['sessionAttributes'] = {}

    scheduled_datetime = event['sessionAttributes']['scheduling_datetime']

    scheduled_action.add({
        'added_by': get_id(event_copy),
        'event': event_copy,
        'scheduled_datetime': scheduled_datetime,
        'execution_status': 'not_started'
    })

    return fulfill(event, 'schedule_set')
Beispiel #4
0
def handler(event, aws_config):
    target = str(get_target(event))

    # there is a strange bug, that AWS Lex sometimes cuts down the first / char
    # this should solve it
    if target and target[0:1] != '/':
        target = '/' + target

    limit = 25
    if event['currentIntent']['slots'].get('limit'):
        limit = int(event['currentIntent']['slots']['limit'])

    logs = get_aws_client('logs', aws_config)
    log_streams = logs.describe_log_streams(
        logGroupName=str(target),
        orderBy='LastEventTime',
        descending=True,
        limit=1
    )

    log = ''
    if log_streams and log_streams.get('logStreams') and log_streams['logStreams'][0]:
        log_stream = log_streams['logStreams'][0]['logStreamName']
        response = logs.get_log_events(
            logGroupName=str(target),
            logStreamName=log_stream,
            limit=limit,
            startFromHead=False
        )

        for record in response.get('events'):
            log += record.get('message', '') + '\n'

    if not log:
        return fulfill(event, 'log_not_found')

    return fulfill(event, None, str(log))
def handler(event, aws_config):
    target = get_target(event)

    client = get_aws_client('cloudfront', aws_config)
    client.create_invalidation(DistributionId=str(target),
                               InvalidationBatch={
                                   'Paths': {
                                       'Quantity': 1,
                                       'Items': ['/*']
                                   },
                                   'CallerReference':
                                   datetime.utcnow().strftime('%Y%m%d%H%M%S')
                               })

    return fulfill(event, 'success')
Beispiel #6
0
def handler(event):
    keys = ['aws_access_key', 'aws_secret_key', 'aws_region']

    # Let's get the namespace first.
    event['currentIntent']['slots']['namespace'] = get_namespace(
        event['currentIntent']['slots']['namespace'])
    if not event['currentIntent']['slots']['namespace']:
        return get_slot(event, 'namespace', 'missing_namespace')

    # Copy the config into session attributes, but add a new_ prefix, so it won't affect the current config
    for key in keys:
        if event['currentIntent']['slots'].get(key):
            event['sessionAttributes'][
                'new_' + key] = event['currentIntent']['slots'][key]

    # check for missing data
    for key in keys:
        if not event['sessionAttributes'] or not event[
                'sessionAttributes'].get('new_' + key):
            return get_slot(event, key, 'missing_' + key)

    item_id = get_id(event)
    item = user_config.get(item_id)

    if item:
        response = confirm(event)
        if response:
            return response

    config = {
        'namespace': event['currentIntent']['slots']['namespace'],
        'aws_access_key': event['sessionAttributes']['new_aws_access_key'],
        'aws_secret_key': event['sessionAttributes']['new_aws_secret_key'],
        'aws_region': event['sessionAttributes']['new_aws_region']
    }

    del event['sessionAttributes']['new_aws_access_key']
    del event['sessionAttributes']['new_aws_secret_key']
    del event['sessionAttributes']['new_aws_region']

    # Insert or update config record
    user_config.update(item_id, {
        'last_modified_by': event['userId'],
        'config': config
    })

    return fulfill(event, 'success')
def handler(event):
    alias = str(event['currentIntent']['slots']['alias']).lower()
    target = str(event['currentIntent']['slots']['target'])

    item_id = get_id(event)
    item = user_alias.get(item_id)

    aliases = item['aliases'] if item and item.get('aliases') else {}

    if item and alias in aliases:
        response = confirm(event)
        if response:
            return response

    aliases[alias] = target
    # Insert or update config record
    user_alias.update(item_id, {
        'last_modified_by': event['userId'],
        'aliases': aliases
    })

    return fulfill(event, 'success')
def handler(event, aws_config):
    target = get_target(event)

    client = get_aws_client('lambda', aws_config)
    lambda_response = client.invoke(
        FunctionName=str(target),
        InvocationType='RequestResponse',
        LogType='Tail',
    )

    response = ''
    log_result = str(lambda_response.get('LogResult', ''))
    function_error = str(lambda_response.get('FunctionError', ''))
    pay_load = lambda_response.get('Payload')

    if log_result:
        response += '*Log:*\n' + b64decode(log_result) + '\n\n'
    if function_error:
        response += '*Function error:*\n' + function_error + '\n\n'
    if pay_load:
        response += '*Response:*\n' + str(pay_load.read()) + '\n\n'

    return fulfill(event, 'success', response)
Beispiel #9
0
def handler(event):
    return fulfill(event, None, '42')
def handler(event, aws_config):
    target = get_target(event)
    sqs_client = get_aws_client('sqs', aws_config)

    sqs_client.purge_queue(QueueUrl=target)
    return fulfill(event, 'success')
Beispiel #11
0
def handler(event):

    return fulfill(event, 'help')
Beispiel #12
0
def handler(event):
    return fulfill(event, 'schedule_canceled')