diff --git a/samcli/commands/init/__init__.py b/samcli/commands/init/__init__.py index 90cf870900..38432cacc3 100644 --- a/samcli/commands/init/__init__.py +++ b/samcli/commands/init/__init__.py @@ -8,7 +8,7 @@ from samcli.cli.main import pass_context, common_options from samcli.commands.exceptions import UserException -from samcli.local.common.runtime_template import INIT_RUNTIMES, SUPPORTED_DEP_MANAGERS +from samcli.local.common.runtime_template import INIT_RUNTIMES, SUPPORTED_DEP_MANAGERS, DEFAULT_RUNTIME from samcli.local.init import generate_project from samcli.local.init.exceptions import GenerateProjectFailedError @@ -17,7 +17,7 @@ @click.command(context_settings=dict(help_option_names=[u'-h', u'--help'])) @click.option('-l', '--location', help="Template location (git, mercurial, http(s), zip, path)") -@click.option('-r', '--runtime', type=click.Choice(INIT_RUNTIMES), default="nodejs8.10", +@click.option('-r', '--runtime', type=click.Choice(INIT_RUNTIMES), default=DEFAULT_RUNTIME, help="Lambda Runtime of your app") @click.option('-d', '--dependency-manager', type=click.Choice(SUPPORTED_DEP_MANAGERS), default=None, help="Dependency manager of your Lambda runtime", required=False) diff --git a/samcli/local/common/runtime_template.py b/samcli/local/common/runtime_template.py index ef67fe93ea..3535553160 100644 --- a/samcli/local/common/runtime_template.py +++ b/samcli/local/common/runtime_template.py @@ -13,10 +13,12 @@ _init_path = str(pathlib.Path(os.path.dirname(__file__)).parent) _templates = os.path.join(_init_path, 'init', 'templates') + +# Note(TheSriram): The ordering of the runtimes list per language is based on the latest to oldest. RUNTIME_DEP_TEMPLATE_MAPPING = { "python": [ { - "runtimes": ["python2.7", "python3.6", "python3.7"], + "runtimes": ["python3.7", "python3.6", "python2.7"], "dependency_manager": "pip", "init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-python"), "build": True @@ -32,7 +34,7 @@ ], "nodejs": [ { - "runtimes": ["nodejs8.10", "nodejs10.x"], + "runtimes": ["nodejs10.x", "nodejs8.10"], "dependency_manager": "npm", "init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-nodejs"), "build": True @@ -46,7 +48,7 @@ ], "dotnet": [ { - "runtimes": ["dotnetcore", "dotnetcore1.0", "dotnetcore2.0", "dotnetcore2.1"], + "runtimes": ["dotnetcore2.1", "dotnetcore2.0", "dotnetcore1.0", "dotnetcore"], "dependency_manager": "cli-package", "init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-dotnet"), "build": True @@ -81,3 +83,6 @@ RUNTIMES = set(itertools.chain(*[c['runtimes'] for c in list( itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values())))])) INIT_RUNTIMES = RUNTIMES.union(RUNTIME_DEP_TEMPLATE_MAPPING.keys()) + +# NOTE(TheSriram): Default Runtime Choice when runtime is not chosen +DEFAULT_RUNTIME = RUNTIME_DEP_TEMPLATE_MAPPING['nodejs'][0]['runtimes'][0] diff --git a/samcli/local/init/__init__.py b/samcli/local/init/__init__.py index 89e4bc52c9..84ec28c6b9 100644 --- a/samcli/local/init/__init__.py +++ b/samcli/local/init/__init__.py @@ -14,7 +14,7 @@ def generate_project( - location=None, runtime="nodejs", dependency_manager=None, + location=None, runtime="nodejs10.x", dependency_manager=None, output_dir=".", name='sam-sample-app', no_input=False): """Generates project using cookiecutter and options given @@ -51,11 +51,9 @@ def generate_project( for mapping in list(itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values()))): if runtime in mapping['runtimes'] or any([r.startswith(runtime) for r in mapping['runtimes']]): - if not dependency_manager: + if not dependency_manager or dependency_manager == mapping['dependency_manager']: template = mapping['init_location'] break - elif dependency_manager == mapping['dependency_manager']: - template = mapping['init_location'] if not template: msg = "Lambda Runtime {} does not support dependency manager: {}".format(runtime, dependency_manager)