fromchaliceimportChaliceapp=Chalice(app_name="helloworld")
# Whenever an object is uploaded to 'mybucket'# this lambda function will be invoked.@app.on_s3_event(bucket='mybucket')defhandler(event):
print("Object uploaded for bucket: %s, key: %s"% (event.bucket, event.key))
以及SQS队列:
fromchaliceimportChaliceapp=Chalice(app_name="helloworld")
# Invoke this lambda function whenever a message# is sent to the ``my-queue-name`` SQS queue.@app.on_sqs_message(queue='my-queue-name')defhandler(event):
forrecordinevent:
print("Message body: %s"%record.body)
"""Lists <--- Name of the topic here# @see: https://www.learnpython.org/en/Lists <-- Link to further readings goes hereHere might go more detailed explanation of the current topic (i.e. general info about Lists)."""deftest_list_type():
"""Explanation of sub-topic goes here. Each file contains test functions that illustrate sub-topics (i.e. lists type, lists methods). """# Here is an example of how to build a list. <-- Comments here explain the actionsquares= [1, 4, 9, 16, 25]
# Lists can be indexed and sliced. # Indexing returns the item.assertsquares[0] ==1# <-- Assertions here illustrate the result.# Slicing returns a new list.assertsquares[-3:] == [9, 16, 25] # <-- Assertions here illustrate the result.
# filename: happy_birthday.py"""A basic (single function) API written using hug"""importhug@hug.get('/happy_birthday')defhappy_birthday(name, age:hug.types.number=1):
"""Says happy birthday to a user"""return"Happy {age} Birthday {name}!".format(**locals())
# filename: versioning_example.py"""A simple example of a hug API call with versioning"""importhug@hug.get('/echo', versions=1)defecho(text):
returntext@hug.get('/echo', versions=range(2, 5))defecho(text):
return"Echo: {text}".format(**locals())
$ cd ./docker
# This will run Gunicorn on port 8000 of the Docker container.
$ docker-compose up gunicorn
# From the host machine, find your Dockers IP address.# For Windows & Mac:
$ docker-machine ip default
# For Linux:
$ ifconfig docker0 | grep 'inet'| cut -d: -f2 | awk '{ print $1}'| head -n1