Translator Wrapper defaults to `us-east-1` for SAR applications
See original GitHub issueDescription
sam build
does not replace the region properly when transforming the template. The region is defined as us-east-1
and that is the region used on transform in SamTranslatorWrapper regardless of AWS_DEFAULT_REGION
, .aws/config
, or region flag values
Steps to reproduce
Reproduction repo: https://github.com/NathanYocum/sam-sar-bug (requires changing account id’s and an s3 bucket in us-east-1 and us-east-2).
- pip install aws-sam-cli==0.53.0
- Publish a SAR application to us-east-1 and us-east-2
- Build or deploy a template that uses the SAR application with the following for example:
# template.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Mappings:
SAMBuildTest:
us-east-1:
# Replace AccountId
ApplicationId: arn:aws:serverlessrepo:us-east-1:854484851566:applications/sam-build-test
SemanticVersion: 0.0.2
us-east-2:
# Replace AccountId
ApplicationId: arn:aws:serverlessrepo:us-east-2:854484851566:applications/sam-build-test
SemanticVersion: 0.0.2
Resources:
SAMBuildSAR:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: !FindInMap [ SAMBuildTest, !Ref AWS::Region, ApplicationId ]
SemanticVersion: !FindInMap [ SAMBuildTest, !Ref AWS::Region, SemanticVersion ]
AWS_DEFAULT_REGION=us-east-1 sam build # passes
AWS_DEFAULT_REGION=us-east-2 sam build # fails
sam build --region us-east-2 # fails
Observed result
Command: AWS_DEFAULT_REGION=us-east-2 sam build --debug
samcli.commands.validate.lib.exceptions.InvalidSamDocumentException: [InvalidResourceException('SAMBuildSAR', 'Application with id arn:aws:serverlessrepo:us-east-1:854484851566:applications/sam-build-test could not be found.')] ('SAMBuildSAR', 'Application with id arn:aws:serverlessrepo:us-east-1:854484851566:applications/sam-build-test could not be found.')
Full output:
Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
'build' command is called
No Parameters detected in the template
Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 556, 'exitReason': 'InvalidSamDocumentException', 'exitCode': 255, 'requestId': '35a8bf9d-ccd4-4e22-8f8c-79b6a1987a79', 'installationId': 'e7ea7dd6-88c2-49c8-80b5-45f7634ac522', 'sessionId': '31e76f7b-98d6-4bf0-90d8-74962e5c565d', 'executionEnvironment': 'CLI', 'pyversion': '3.7.7', 'samcliVersion': '0.53.0'}}]}
Telemetry response: 200
Traceback (most recent call last):
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/lib/samlib/wrapper.py", line 77, in run_plugins
parser.parse(template_copy, all_plugins) # parse() will run all configured plugins
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/lib/samlib/wrapper.py", line 146, in parse
raise InvalidDocumentException(document_errors)
samtranslator.model.exceptions.InvalidDocumentException: [InvalidResourceException('SAMBuildSAR', 'Application with id arn:aws:serverlessrepo:us-east-1:854484851566:applications/sam-build-test could not be found.')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/sam", line 33, in <module>
sys.exit(load_entry_point('aws-sam-cli==0.53.0', 'console_scripts', 'sam')())
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 96, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 62, in wrapped
return_value = func(*args, **kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/commands/build/command.py", line 129, in cli
mode,
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/commands/build/command.py", line 179, in do_cli
mode=mode,
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/commands/build/build_context.py", line 62, in __enter__
self._function_provider = SamFunctionProvider(self._template_dict, self._parameter_overrides)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/lib/providers/sam_function_provider.py", line 40, in __init__
self.template_dict = SamFunctionProvider.get_template(template_dict, parameter_overrides)
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/lib/providers/sam_base_provider.py", line 126, in get_template
template_dict = SamTranslatorWrapper(template_dict, parameter_values=parameters_values).run_plugins()
File "/usr/local/Cellar/aws-sam-cli/0.53.0/libexec/lib/python3.7/site-packages/samcli/lib/samlib/wrapper.py", line 80, in run_plugins
functools.reduce(lambda message, error: message + " " + str(error), e.causes, str(e))
samcli.commands.validate.lib.exceptions.InvalidSamDocumentException: [InvalidResourceException('SAMBuildSAR', 'Application with id arn:aws:serverlessrepo:us-east-1:854484851566:applications/sam-build-test could not be found.')] ('SAMBuildSAR', 'Application with id arn:aws:serverlessrepo:us-east-1:854484851566:applications/sam-build-test could not be found.')
I was able to fix this by adding
self.parameter_values["AWS::Region"] = boto3.session.Session().region_name
to https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/lib/samlib/wrapper.py#L40 but I’m sure the region in context is encapsulated somewhere else better for a solution.
Expected result
Build/Deploy succeeds in us-east-2 and other regions aside from us-east-1
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: macOS 10.15.5
sam --version
: 0.53.0 (tried both the pip and brew versions to no success)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Translator Wrapper defaults to `us-east-1` for SAR applications
Description sam build does not replace the region properly when transforming the template. The region is defined as us-east-1 and that is ...
Read more >Language Translation Apps in Health Care Settings - NCBI - NIH
Very few studies have evaluated the use of translation apps in medical and health care settings and even fewer have compared multiple translation...
Read more >Using google translate in android application - java
I'm just adding to this question as it is still getting a fair number of views and hasn't seen an accept. The google-api-translate-java...
Read more >TRANSLATING SAR TO OPTICAL IMAGES FOR ASSISTED ...
registered SAR and optical images to translate SAR image to optical version for assisted SAR ... This could greatly promote the wide application...
Read more >Settings — Django Rosetta 0.9.9 documentation
ROSETTA_MESSAGES_PER_PAGE : Number of messages to display per page. Defaults to 10 . ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS : Enable AJAX translation ...
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
https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/plugins/application/serverless_app_plugin.py#L129 seems to be where the ApplicationId transformed to
us-east-1
is occurring in theon_before_transform
.The dict of params passed into the translator transforms
['SAMBuildTest', {'Ref': 'AWS::Region'}, 'ApplicationId'], ['SAMBuildTest', {'Ref': 'AWS::Region'}, 'SemanticVersion']
into['SAMBuildTest', 'us-east-1', 'ApplicationId'], ['SAMBuildTest', 'us-east-1', 'SemanticVersion']
.This works fine if I just do
aws cloudformation deploy
, since I think CF leaves the pseudo params unresolved until deployed, but this currently runs into issues withsam build
andsam deploy
. It would be ideal to just let CF do the resolution of the pseudo params but if not possible at least using the values from config/flags.⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.