`sam build --parameter-overrides` fails to override
See original GitHub issueDescription
sam build --parameter-overrides
fails to override SAM template yaml Parameters
Setup
- Ubuntu 18.04.3 x86_64
- Python 3.7.3
- aws-cli/1.16.265 Python/3.6.8 Linux/5.0.0-32-generic botocore/1.13.1
- SAM CLI, version 0.23.0
- empty
requirements.txt
- arbitrary
app.py
- below
parampoof.yaml
parampoof.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: |
Repo of param override failing to override
Parameters:
GitTag:
Description: description field on lambda version
Type: String
Default: defaultgittag
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
AutoPublishAlias: test
VersionDescription: !Ref GitTag
Handler: app.lambda_handler
Runtime: python3.7
Timeout: 10
Steps to reproduce
sam build \
--template ./parampoof.yaml \
--manifest requirements.txt \
--parameter-overrides "ParameterKey=GitTag,ParameterValue=aabbccdd"
grep aabbccdd .aws-sam/build/template.yaml
Observed result
First…
Building resource 'MyFunction'
Running PythonPipBuilder:ResolveDependencies
Running PythonPipBuilder:CopySource
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Package: sam package --s3-bucket <yourbucket>
Then…
Nothing. grep
finds no value of aabbccdd
in the file
Expected result
grep
should find the value aabbccdd
in the file. Likely in Parameters:
section by overriding/replacing the default value defaultgittag
. This is needed because the next steps sam package
and sam deploy
in the workflow depend on this .aws-sam/build/template.yaml
transformed output of sam build
.
Debug output of sam build
Using SAM Template at **redacted**/parampoof.yaml
Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
'build' command is called
Collected default values for parameters: {'GitTag': 'defaultgittag'}
1 resources found in the template
Found Serverless function with name='MyFunction' and CodeUri='.'
Building resource 'MyFunction'
Loading workflow module 'aws_lambda_builders.workflows'
Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)'
Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)'
Running workflow 'PythonPipBuilder'
Running PythonPipBuilder:ResolveDependencies
calling pip download -r **redacted**/requirements.txt --dest /tmp/tmpk1rvadh4
Full dependency closure: set()
initial compatible: set()
initial incompatible: set()
Downloading missing wheels: set()
compatible wheels after second download pass: set()
Build missing wheels from sdists (C compiling True): set()
compatible after building wheels (no C compiling): set()
Build missing wheels from sdists (C compiling False): set()
compatible after building wheels (C compiling): set()
Final compatible: set()
Final incompatible: set()
Final missing wheels: set()
PythonPipBuilder:ResolveDependencies succeeded
Running PythonPipBuilder:CopySource
PythonPipBuilder:CopySource succeeded
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Package: sam package --s3-bucket <yourbucket>
Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 523, 'exitReason': 'success', 'exitCode': 0, 'requestId': '9f3a7fc1-3397-48a2-afe0-22848b8743b4', 'installationId': 'c648e689-e57c-4a3c-a26f-ca6d1fd13041', 'sessionId': 'd5aced2b-51ec-4288-aab8-a47317da031d', 'executionEnvironment': 'CLI', 'pyversion': '3.7.3', 'samcliVersion': '0.23.0'}}]}
HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Workaround
Don’t use sam build --parameter-overrides
. Instead use sed
to search/replace the base template.yaml for a known value to replace/override.
Related
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
sam build - AWS Serverless Application Model
Build an AWS SAM application using the sam build command from the AWS SAM CLI. ... AWS CloudFormation parameter overrides encoded as key-value...
Read more >How do I specify template parameters when running AWS ...
sam local start-api --parameter-overrides ParameterKey=Key1 ... was not loaded and the build failed upon a missing parameter SecretKey.
Read more >sam deploy - Amazon Serverless Application Model
The Amazon SAM CLI first tries to locate a template file built using the sam ... To override the Amazon SAM CLI's default...
Read more >sam deploy parameter-overrides example
Passing --parameter-overrides into sam build is purely for the process, we will not replace those in the template we produce. Customers tend to...
Read more >aws-sam-deploy:How to use parameter-overrides with...
sam deploy --template-file ./packaged-plm.yaml --parameter-overrides Env=dev. but paramter-overrides does not work on aws-sam-deploy.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This feature is extremely confusing, my expectations were that
sam build
is using the parameter overrides flag to create an output artifact that I can use for execution or deployment purposes.@diablodale You have a really good point.
sam build
should capture the flags provided earlier and pass it along to the next commands. Your mental model makes sense and in fact is more powerful IMO.I think #1503 is going to enable this capability. Please take a look at the design and provide comments. You have an interesting perspective and I think we can all benefit from it.
Closing this Issue because
sam
is working as expected