Closed binarymist closed 4 years ago
If I try:
Globals:
Function:
Timeout: !Ref LAMBDA_TIMEOUT # Default is 3 seconds
Runtime: nodejs8.10
Environment:
Variables: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
NODE_ENV: development
LAMBDA_TIMEOUT: 5 # Set the env var here, then ref it in code and subtract a little for internal timeout. Could also reference the env var from convict file.
Resources:
provisionAppSlaves:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: ./app-slave-provisioner
Handler: index.provisionAppSlaves
provisionSeleniumStandalones:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./selenium-standalone-provisioner
Handler: index.provisionSeleniumStandalones
Outputs:
provisionAppSlaves:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt provisionAppSlaves.Arn
provisionAppSlavesIamRole:
Description: "Implicit IAM Role created for provisionAppSlaves function"
Value: !GetAtt provisionAppSlavesRole.Arn
The !Ref LAMBDA_TIMEOUT
doesn't work here. sam local start-lambda ...
says:
2019-01-13 18:43:39 Starting a timer for {u'Ref': u'LAMBDA_TIMEOUT'} seconds for function 'provisionAppSlaves'
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 1071, in run
self.finished.wait(self.interval)
File "/usr/lib/python2.7/threading.py", line 614, in wait
self.__cond.wait(timeout)
File "/usr/lib/python2.7/threading.py", line 349, in wait
endtime = _time() + timeout
TypeError: unsupported operand type(s) for +: 'float' and 'dict'
So we have to duplicate the value like so:
Globals:
Function:
Timeout: 5 # !Ref LAMBDA_TIMEOUT # Default is 3 seconds # !Ref doesn't work here, so we have to duplicate the value.
Runtime: nodejs8.10
Environment:
Variables: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
NODE_ENV: development
LAMBDA_TIMEOUT: 5 # Set the env var here, then ref it in code and subtract a little for internal timeout. Could also reference the env var from convict file.
This issue does not appear to be limited to the number
type.
I have a template that utilizes intrinsic functions and Conditionals to define behavior for different environments.
When deployed to AWS the functionality works as intended however with SAM Local the defaults are used and any parameter-override
values appear to be ignored.
For anyone else experiencing this issue you can easily override the default values for testing. Of course in a local environment it defeats the purpose of the parameters :disappointed:, but it will keep you going while this hangs around (in the Backlog...).
Also if you are using Lambdas you have the alternative option of overriding environment variables directly (https://github.com/awslabs/aws-sam-cli/blob/develop/docs/advanced_usage.md#environment-variable-file). This doesn't accomplish all the utility of the template parameters but it may help!
As an aside SAM Local appears to ignore the conditionals entirely so careful when testing locally (https://github.com/awslabs/aws-sam-cli/issues/194).
This was released a long time ago in v0.30.0.
Closing
Description
--parameter-overrides
number not honoredSteps to reproduce
Run:
sam local start-lambda --parameter-overrides ParameterKey=TimeoutParameter,ParameterValue=3 --host 172.25.0.1 --docker-network compose_pt-net
Observed result
When I invoke the lambda via the aws-sdk in code, sam local says:
Expected result
Expect the
ParameterValue=3
to be honored (timeout the lambda function when invoked within 3 seonds) within the template.yaml when the lambda function is finally invoked.Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: 0.6.2Relevant part of template.yaml:
The
Default: 10
Timeout
is only honored If thesam local
command leaves out the--parameter-overrides ParameterKey=TimeoutParameter,ParameterValue=3