Initialize a new Zappa project by creating a new zappa_settings.json in a guided process. This should probably be broken up into few separate componants once it's stable. Testing these inputs requires monkeypatching with mock, which isn't pretty.
(self, settings_file: str = "zappa_settings.json")
| 1983 | return confirm |
| 1984 | |
| 1985 | def init(self, settings_file: str = "zappa_settings.json"): |
| 1986 | """ |
| 1987 | Initialize a new Zappa project by creating a new zappa_settings.json in a guided process. |
| 1988 | This should probably be broken up into few separate componants once it's stable. |
| 1989 | Testing these inputs requires monkeypatching with mock, which isn't pretty. |
| 1990 | """ |
| 1991 | |
| 1992 | # Make sure we're in a venv. |
| 1993 | self.check_venv() |
| 1994 | |
| 1995 | # Ensure that we don't already have a zappa_settings file. |
| 1996 | settings_file_filepath = Path(settings_file).resolve() |
| 1997 | if settings_file_filepath.exists() and settings_file_filepath.is_file(): |
| 1998 | raise ClickException( |
| 1999 | "This project already has a " + click.style("{0!s} file".format(settings_file), fg="red", bold=True) + "!" |
| 2000 | ) |
| 2001 | |
| 2002 | # Explain system. |
| 2003 | click.echo( |
| 2004 | click.style( |
| 2005 | """\n███████╗ █████╗ ██████╗ ██████╗ █████╗ |
| 2006 | ╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗ |
| 2007 | ███╔╝ ███████║██████╔╝██████╔╝███████║ |
| 2008 | ███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██╔══██║ |
| 2009 | ███████╗██║ ██║██║ ██║ ██║ ██║ |
| 2010 | ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝\n""", |
| 2011 | fg="green", |
| 2012 | bold=True, |
| 2013 | ) |
| 2014 | ) |
| 2015 | |
| 2016 | click.echo( |
| 2017 | click.style("Welcome to ", bold=True) + click.style("Zappa", fg="green", bold=True) + click.style("!\n", bold=True) |
| 2018 | ) |
| 2019 | click.echo( |
| 2020 | click.style("Zappa", bold=True) + " is a system for running server-less Python web applications" |
| 2021 | " on AWS Lambda and AWS API Gateway." |
| 2022 | ) |
| 2023 | click.echo("This `init` command will help you create and configure your new Zappa deployment.") |
| 2024 | click.echo("Let's get started!\n") |
| 2025 | |
| 2026 | env = self._get_init_env() |
| 2027 | |
| 2028 | # Detect AWS profiles and regions |
| 2029 | # If anyone knows a more straightforward way to easily detect and |
| 2030 | # parse AWS profiles I'm happy to change this, feels like a hack |
| 2031 | session = botocore.session.Session() |
| 2032 | config = session.full_config |
| 2033 | profiles = config.get("profiles", {}) |
| 2034 | profile_names = list(profiles.keys()) |
| 2035 | |
| 2036 | click.echo( |
| 2037 | "\nAWS Lambda and API Gateway are only available in certain regions. " |
| 2038 | "Let's check to make sure you have a profile set up in one that will work." |
| 2039 | ) |
| 2040 | |
| 2041 | if not profile_names: |
| 2042 | profile_name, profile = None, None |