moto/moto/server.py

95 lines
2.4 KiB
Python
Raw Normal View History

lambda + SNS enhancements (#1048) * updates - support lambda messages from SNS - run lambda in docker container * decode output * populate timeout * simplify * whoops * skeletons of cloudwatchlogs * impl filter log streams * fix logging * PEP fixes * PEP fixes * fix reset * fix reset * add new endpoint * fix region name * add docker * try to fix tests * try to fix travis issue with boto * fix escaping in urls * fix environment variables * fix PEP * more pep * switch back to precise * another fix attempt * fix typo * fix lambda invoke * fix more unittests * work on getting this to work in new scheme * fix py2 * fix error * fix tests when running in server mode * more lambda fixes * try running with latest docker adapted from aiodocker * switch to docker python client * pep fixes * switch to docker volume * fix unittest * fix invoke from sns * fix zip2tar * add hack impl for get_function with zip * try fix * fix for py < 3.6 * add volume refcount * try to fix travis * docker test * fix yaml * try fix * update endpoints * fix * another attempt * try again * fix recursive import * refactor fix * revert changes with better fix * more reverts * wait for service to come up * add back detached mode * sleep and add another exception type * put this back for logging * put back with note * whoops :) * docker in docker! * fix invalid url * hopefully last fix! * fix lambda regions * fix protocol * travis!!!! * just run lambda test for now * use one print * fix escaping * another attempt * yet another * re-enable all tests * fixes * fix for py2 * revert change * fix for py2.7 * fix output ordering * remove this given there's a new unittest that covers it * changes based on review - add skeleton logs test file - switch to docker image that matches test env - fix mock_logs import * add readme entry
2017-09-27 16:04:58 -07:00
import argparse
import os
import signal
2013-03-05 08:14:43 -05:00
import sys
from werkzeug.serving import run_simple
2013-03-05 08:14:43 -05:00
from moto.moto_server.werkzeug_app import (
DomainDispatcherApplication,
create_backend_app,
)
from moto.moto_server.threaded_moto_server import ( # noqa # pylint: disable=unused-import
ThreadedMotoServer,
)
2013-03-05 08:14:43 -05:00
def signal_handler(signum, frame):
sys.exit(0)
2022-01-14 18:51:49 -01:00
def main(argv=None):
argv = argv or sys.argv[1:]
parser = argparse.ArgumentParser()
2013-12-28 20:15:37 -05:00
# Keep this for backwards compat
parser.add_argument(
"service",
type=str,
2019-10-31 08:44:26 -07:00
nargs="?", # http://stackoverflow.com/a/4480202/731592
default=os.environ.get("MOTO_SERVICE"),
2019-10-31 08:44:26 -07:00
)
parser.add_argument(
2019-10-31 08:44:26 -07:00
"-H", "--host", type=str, help="Which host to bind", default="127.0.0.1"
)
parser.add_argument(
2021-11-29 19:35:18 -01:00
"-p",
"--port",
type=int,
help="Port number to use for connection",
default=int(os.environ.get("MOTO_PORT", 5000)),
2019-10-31 08:44:26 -07:00
)
parser.add_argument(
2019-10-31 08:44:26 -07:00
"-r",
"--reload",
action="store_true",
help="Reload server on a file change",
default=False,
)
2017-06-27 17:18:21 +10:00
parser.add_argument(
2019-10-31 08:44:26 -07:00
"-s",
"--ssl",
action="store_true",
help="Enable SSL encrypted connection with auto-generated certificate (use https://... URL)",
default=False,
2017-06-27 17:18:21 +10:00
)
parser.add_argument(
2019-10-31 08:44:26 -07:00
"-c", "--ssl-cert", type=str, help="Path to SSL certificate", default=None
)
parser.add_argument(
2019-10-31 08:44:26 -07:00
"-k", "--ssl-key", type=str, help="Path to SSL private key", default=None
)
args = parser.parse_args(argv)
2021-11-29 19:35:18 -01:00
if "MOTO_PORT" not in os.environ:
os.environ["MOTO_PORT"] = f"{args.port}"
try:
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
except Exception:
pass # ignore "ValueError: signal only works in main thread"
# Wrap the main application
2019-10-31 08:44:26 -07:00
main_app = DomainDispatcherApplication(create_backend_app, service=args.service)
main_app.debug = True
2013-03-05 08:14:43 -05:00
ssl_context = None
if args.ssl_key and args.ssl_cert:
ssl_context = (args.ssl_cert, args.ssl_key)
elif args.ssl:
2019-10-31 08:44:26 -07:00
ssl_context = "adhoc"
run_simple(
args.host,
args.port,
main_app,
threaded=True,
use_reloader=args.reload,
ssl_context=ssl_context,
)
2013-03-05 08:14:43 -05:00
2019-10-31 08:44:26 -07:00
if __name__ == "__main__":
2013-03-05 08:14:43 -05:00
main()