Skip to content

Commit

Permalink
resolve pseudo region from command argument or envvar if available
Browse files Browse the repository at this point in the history
  • Loading branch information
elbayaaa committed May 15, 2021
1 parent 6863696 commit abc0b2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os

from samcli.cli.context import Context
from samcli.lib.intrinsic_resolver.intrinsic_property_resolver import IntrinsicResolver
from samcli.lib.intrinsic_resolver.invalid_intrinsic_exception import InvalidSymbolException

Expand Down Expand Up @@ -363,8 +364,14 @@ def handle_pseudo_region(self):
-------
The region from the environment or a default one
"""
try:
ctx = Context.get_current_context()
except RuntimeError:
ctx = None
ctx_aws_region = ctx.region if ctx else None
return (
self.logical_id_translator.get(IntrinsicsSymbolTable.AWS_REGION)
or ctx_aws_region
or os.getenv("AWS_REGION")
or IntrinsicsSymbolTable.DEFAULT_PSEUDO_PARAM_VALUES.get(IntrinsicsSymbolTable.AWS_REGION)
)
Expand Down
3 changes: 2 additions & 1 deletion samcli/lib/providers/sam_base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""

import logging

from typing import Any, Dict, Optional, cast, Iterable, Union

from samcli.commands._utils.resources import AWS_SERVERLESS_APPLICATION, AWS_CLOUDFORMATION_STACK
from samcli.lib.intrinsic_resolver.intrinsic_property_resolver import IntrinsicResolver
from samcli.lib.intrinsic_resolver.intrinsics_symbol_table import IntrinsicsSymbolTable
Expand Down Expand Up @@ -194,6 +194,7 @@ def _get_parameter_values(template_dict: Any, parameter_overrides: Optional[Dict
# override the defaults
parameter_values = {}
parameter_values.update(IntrinsicsSymbolTable.DEFAULT_PSEUDO_PARAM_VALUES)
parameter_values[IntrinsicsSymbolTable.AWS_REGION] = IntrinsicsSymbolTable().handle_pseudo_region()
parameter_values.update(default_values)
parameter_values.update(parameter_overrides or {})

Expand Down

0 comments on commit abc0b2b

Please sign in to comment.