-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support !Ref of template parameters #657
Conversation
- Provide values for template parameters - Automatically picks up default values - Assigns sane defaults for CFN pseudo-parameters like AWS::Region
@@ -85,6 +86,13 @@ def __init__(self, | |||
Additional arguments passed to the debugger | |||
debugger_path str | |||
Path to the directory of the debugger to mount on Docker | |||
aws_profile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the type to aws_profile
and aws_region
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
AWS Credential profile to use | ||
aws_region | ||
AWS region to use | ||
parameter_overrides : dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove the :
to remain consistent with the other docstrings.
@@ -103,6 +104,12 @@ def invoke_common_options(f): | |||
type=click.Path(exists=True), | |||
help="JSON file containing values for Lambda function's environment variables."), | |||
|
|||
click.option("--parameter-overrides", | |||
type=CfnParameterOverridesType(), | |||
help="Optional. A string that contains CloudFormation parameter overrides encoded as key-value " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be key=value
instead of key-value
? You have an example but keeping this consistent will help communicate what we are expecting.
@@ -116,3 +118,48 @@ def test_invoke_raises_exception_with_noargs_and_event(self): | |||
process_stderr = b"".join(process.stderr.readlines()).strip() | |||
error_output = process_stderr.decode('utf-8') | |||
self.assertIn("no_event and event cannot be used together. Please provide only one.", error_output) | |||
|
|||
def test_invoke_with_timeout_set_by_parameters(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost identical to the 'test_invoke_with_timeout_set' test. Can we parameterize them into one test? This will be help as we build out the tests more to cover different cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea. will do
) | ||
|
||
]) | ||
def test_successful_parsing(self, input, expected): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this!
tests/unit/cli/test_types.py
Outdated
]) | ||
def test_successful_parsing(self, input, expected): | ||
result = self.param_type.convert(input, None, None) | ||
print(input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove prints from tests.
"AWS::AccountId": "123456789012", | ||
"AWS::Partition": "aws", | ||
|
||
# There is not much value in inferring actual AWS region here. These values are just placeholders to help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this comment, to reflect the AWS::Region override change.
|
||
default_values = {} | ||
|
||
parameter_definition = sam_template.get("Parameters", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not default this to{}
?
samcli/cli/types.py
Outdated
Removes wrapping double quotes and any '\ ' characters. They are usually added to preserve spaces when passing | ||
value thru shell. | ||
|
||
Ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nit:
Making it look like in the docstring, looks nice in the editor, because it interprets it as a python prompt. https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard
Examples
----------
>>> _unquote('val\ ue')
value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I will add it..
@@ -98,6 +106,7 @@ def __init__(self, | |||
self._debug_port = debug_port | |||
self._debug_args = debug_args | |||
self._debugger_path = debugger_path | |||
self._parameter_overrides = parameter_overrides or {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We set this to be None
by default everywhere else, should we do that here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is set as None everywhere else, but as a good practice I set to empty dictionary if customers don't specify any value.
Yay for this one. Just started using SAM, and this is a blocker. Thanks for adding it! |
I have the following issue with !Ref:
When executing via
only the first Function receives the value in the .env file (process.env.CLIENT_ID=="ABCD"). Am I using this wrong? |
Issue #, if available:
#573, #572, #528, #490
Description of changes:
Still very much a work in progress. This PR supports resolving !Ref of template parameters anywhere within a SAM template. It does not yet support other intrinsic functions like !Sub or !FindInMap.
--parameter-overrides
CLI option--parameter-overrides
CLI optionRemaining:
Thanks to @jfuss for providing the initial version of implementation. This PR is a cleaned up version of Jacob's implementation.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.