Lambda函数可以生成简单的HTTP请求

I want to use AWS lambda to make a cronjob-style HTTP request. Unfortunately I don't know Python.

I found they had a "Canary" function which seems to be similar to what I want. How do I simplify this to simply make the HTTP request? I just need to trigger a PHP file.

from __future__ import print_function

from datetime import datetime
from urllib2 import urlopen

SITE = 'https://www.amazon.com/'  # URL of the site to check
EXPECTED = 'Online Shopping'  # String expected to be on the page


def validate(res):
    '''Return False to trigger the canary

    Currently this simply checks whether the EXPECTED string is present.
    However, you could modify this to perform any number of arbitrary
    checks on the contents of SITE.
    '''
    return EXPECTED in res


def lambda_handler(event, context):
    print('Checking {} at {}...'.format(SITE, event['time']))
    try:
        if not validate(urlopen(SITE).read()):
            raise Exception('Validation failed')
    except:
        print('Check failed!')
        raise
    else:
        print('Check passed!')
        return event['time']
    finally:
        print('Check complete at {}'.format(str(datetime.now())))

This program will "simply make the HTTP request."

from urllib2 import urlopen

SITE = 'https://www.amazon.com/'  # URL of the site to check

def lambda_handler(event, context):
    urlopen(SITE)

You can use Requests (http://docs.python-requests.org/en/master/) to work with the response in a easier way.

import requests

URL = 'https://www.amazon.com/'
def lambda_handler(event, context):
    requests.get(URL)