Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions AmazonQ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Runway Requirements

- Ensure you understand the codebase in ./runway before trying to make changes
- Docs for contributing are located at ./docs/source/developers
- If we add functionality, ensure we update ./docs appropriately.
- Ensure we add a commit to git when we add code/functionality
- NEVER commit URLs, secrets, or sensitive data like parameter/env values
113 changes: 113 additions & 0 deletions docs/source/sam/configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
############
Configuration
############

Standard `AWS SAM CLI <https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html>`__ rules apply but, we have some added functionality.

**Supported SAM CLI Versions:** ``>=1.0.0``

*************
Configuration
*************

Configuration options for AWS SAM modules can be specified as ``module_options`` or ``options``.

.. rubric:: Example
.. code-block:: yaml

deployments:
- modules:
- path: sampleapp.sam
options:
build_args:
- --use-container
deploy_args:
- --guided
skip_build: false

.. automodule:: runway.config.models.runway.options.sam
:members:
:exclude-members: model_config, model_fields

*****************
Runway Config Dir
*****************

Runway will change to the directory containing the SAM template file before executing SAM CLI commands.

*******************
Environment Support
*******************

Runway will look for SAM configuration files in the following order:

1. ``samconfig-<stage>-<region>.toml``
2. ``samconfig-<stage>.toml``
3. ``samconfig.toml``

Where ``<stage>`` is the current Runway environment name and ``<region>`` is the current AWS region.

*****************
Template Location
*****************

Runway will automatically detect SAM template files in the following order:

1. ``template.yaml``
2. ``template.yml``
3. ``sam.yaml``
4. ``sam.yml``

*****************
Parameter Support
*****************

Runway supports passing parameters to SAM deployments through the ``parameters`` configuration option. These parameters will be passed to the SAM CLI as ``--parameter-overrides``.

.. rubric:: Example
.. code-block:: yaml

deployments:
- modules:
- path: sampleapp.sam
parameters:
Stage: ${env DEPLOY_ENVIRONMENT}
BucketName: my-bucket-${env DEPLOY_ENVIRONMENT}

*************
Build Support
*************

By default, Runway will run ``sam build`` before deploying. This can be disabled by setting ``skip_build: true`` in the module options.

Additional build arguments can be passed using the ``build_args`` option.

.. rubric:: Example
.. code-block:: yaml

deployments:
- modules:
- path: sampleapp.sam
options:
build_args:
- --use-container
- --parallel
skip_build: false

**************
Deploy Support
**************

Additional deploy arguments can be passed using the ``deploy_args`` option.

.. rubric:: Example
.. code-block:: yaml

deployments:
- modules:
- path: sampleapp.sam
options:
deploy_args:
- --guided
- --capabilities
- CAPABILITY_IAM
3 changes: 3 additions & 0 deletions runway/_cli/commands/_gen_sample/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ._cdk_tsc import cdk_tsc
from ._cfn import cfn
from ._cfngin import cfngin
from ._sam import sam
from ._sls_py import sls_py
from ._sls_tsc import sls_tsc
from ._static_angular import static_angular
Expand All @@ -23,6 +24,7 @@
"cdk_tsc",
"cfn",
"cfngin",
"sam",
"sls_py",
"sls_tsc",
"static_angular",
Expand All @@ -36,6 +38,7 @@
cdk_tsc,
cfn,
cfngin,
sam,
sls_py,
sls_tsc,
static_angular,
Expand Down
29 changes: 29 additions & 0 deletions runway/_cli/commands/_gen_sample/_sam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""``runway gen-sample sam`` command."""

import logging
from pathlib import Path
from typing import TYPE_CHECKING, Any, cast

import click

from ... import options
from .utils import TEMPLATES, copy_sample

if TYPE_CHECKING:
from ...._logging import RunwayLogger

LOGGER = cast("RunwayLogger", logging.getLogger(__name__.replace("._", ".")))


@click.command("sam", short_help="AWS SAM (sampleapp.sam)")
@options.debug
@options.no_color
@options.verbose
@click.pass_context
def sam(ctx: click.Context, **_: Any) -> None:
"""Generate a sample AWS SAM project."""
src = TEMPLATES / "sam"
dest = Path.cwd() / "sampleapp.sam"

copy_sample(ctx, src, dest)
LOGGER.success("Sample AWS SAM module created at %s", dest)
2 changes: 1 addition & 1 deletion runway/config/models/runway/_type_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
RunwayEnvVarsType: TypeAlias = dict[str, Union[list[str], str]]
RunwayEnvVarsUnresolvedType: TypeAlias = Union[RunwayEnvVarsType, str]
RunwayModuleTypeTypeDef: TypeAlias = Literal[
"cdk", "cloudformation", "serverless", "static", "terraform"
"cdk", "cloudformation", "sam", "serverless", "static", "terraform"
]
22 changes: 22 additions & 0 deletions runway/config/models/runway/options/sam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Runway AWS SAM Module options."""

from __future__ import annotations

from pydantic import ConfigDict

from ...base import ConfigProperty


class RunwaySamModuleOptionsDataModel(ConfigProperty):
"""Model for Runway AWS SAM Module options."""

model_config = ConfigDict(
extra="ignore",
title="Runway AWS SAM Module options",
validate_default=True,
validate_assignment=True,
)

build_args: list[str] = []
deploy_args: list[str] = []
skip_build: bool = False
13 changes: 11 additions & 2 deletions runway/core/components/_module_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
LOGGER = logging.getLogger(__name__)


RunwayModuleTypeExtensionsTypeDef = Literal["cdk", "cfn", "sls", "tf", "web"]
RunwayModuleTypeExtensionsTypeDef = Literal["cdk", "cfn", "sam", "sls", "tf", "web"]


class RunwayModuleType:
Expand All @@ -45,6 +45,8 @@ class RunwayModuleType:
+--------------------+-----------------------------------------------+
| ``cloudformation`` | CloudFormation |
+--------------------+-----------------------------------------------+
| ``sam`` | AWS SAM |
+--------------------+-----------------------------------------------+
| ``serverless`` | Serverless Framework |
+--------------------+-----------------------------------------------+
| ``terraform`` | Terraform |
Expand All @@ -61,6 +63,7 @@ class RunwayModuleType:
EXTENSION_MAP: ClassVar[dict[str, str]] = {
"cdk": "runway.module.cdk.CloudDevelopmentKit",
"cfn": "runway.module.cloudformation.CloudFormation",
"sam": "runway.module.sam.Sam",
"sls": "runway.module.serverless.Serverless",
"tf": "runway.module.terraform.Terraform",
"web": "runway.module.staticsite.handler.StaticSite",
Expand All @@ -69,6 +72,7 @@ class RunwayModuleType:
TYPE_MAP: ClassVar[dict[str, str]] = {
"cdk": EXTENSION_MAP["cdk"],
"cloudformation": EXTENSION_MAP["cfn"],
"sam": EXTENSION_MAP["sam"],
"serverless": EXTENSION_MAP["sls"],
"static": EXTENSION_MAP["web"],
"terraform": EXTENSION_MAP["tf"],
Expand Down Expand Up @@ -143,7 +147,12 @@ def _set_class_path_based_on_extension(self) -> None:

def _set_class_path_based_on_autodetection(self) -> None:
"""Based on the files detected in the base path set the class_path."""
if (
if any(
(self.path / sam_template).is_file()
for sam_template in ["template.yaml", "template.yml", "sam.yaml", "sam.yml"]
) and any((self.path / sam_config).is_file() for sam_config in ["samconfig.toml"]):
self.class_path = self.TYPE_MAP.get("sam", None)
elif (
any(
(self.path / sls).is_file()
for sls in ["serverless.js", "serverless.ts", "serverless.yml"]
Expand Down
6 changes: 6 additions & 0 deletions runway/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def __reduce__(self) -> tuple[type[Exception], tuple[Any, ...]]:
return self.__class__, (self.invalid_lookup, self.concatenated_lookups)


class SamNotFound(RunwayError):
"""Raised when SAM CLI could not be executed or was not found in path."""

message: str = "AWS SAM CLI not found"


class NpmNotFound(RunwayError):
"""Raised when npm could not be executed or was not found in path."""

Expand Down
Loading
Loading