diff --git a/samtranslator/plugins/application/serverless_app_plugin.py b/samtranslator/plugins/application/serverless_app_plugin.py index c8759d998..02d70d9f7 100644 --- a/samtranslator/plugins/application/serverless_app_plugin.py +++ b/samtranslator/plugins/application/serverless_app_plugin.py @@ -1,6 +1,7 @@ import copy import json import logging +import re from time import sleep from typing import Any, Callable, Dict, List, Optional, Tuple @@ -150,6 +151,14 @@ def on_before_transform_template(self, template_dict): # type: ignore[no-untype raise InvalidResourceException( logical_id, "Serverless Application Repository is not available in this region." ) + # SSM Pattern found here https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html + ssm_pattern = r"{{resolve:ssm:[a-zA-Z0-9_.\-/]+(:\d+)?}}" + if re.search(ssm_pattern, app_id): + raise InvalidResourceException( + logical_id, + "Serverless Application Repostiory does not support dynamic reference in 'ApplicationId' property.", + ) + self._make_service_call_with_retry(service_call, app_id, semver, key, logical_id) # type: ignore[no-untyped-call] except InvalidResourceException as e: # Catch all InvalidResourceExceptions, raise those in the before_resource_transform target. diff --git a/tests/translator/input/error_sar_with_dynamic_reference.yaml b/tests/translator/input/error_sar_with_dynamic_reference.yaml new file mode 100644 index 000000000..efefd3cca --- /dev/null +++ b/tests/translator/input/error_sar_with_dynamic_reference.yaml @@ -0,0 +1,7 @@ +Resources: + CLOUDDELIVERY: + Type: AWS::Serverless::Application + Properties: + Location: + ApplicationId: '{{resolve:ssm:/elw/test/sar-app}}' + SemanticVersion: 5.2.17 diff --git a/tests/translator/output/error_sar_with_dynamic_reference.json b/tests/translator/output/error_sar_with_dynamic_reference.json new file mode 100644 index 000000000..5d35d5703 --- /dev/null +++ b/tests/translator/output/error_sar_with_dynamic_reference.json @@ -0,0 +1,14 @@ +{ + "_autoGeneratedBreakdownErrorMessage": [ + "Invalid Serverless Application Specification document. ", + "Number of errors found: 1. ", + "Resource with id [CLOUDDELIVERY] is invalid. ", + "Serverless Application Repostiory does not support dynamic reference in 'ApplicationId' property." + ], + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [CLOUDDELIVERY] is invalid. Serverless Application Repostiory does not support dynamic reference in 'ApplicationId' property.", + "errors": [ + { + "errorMessage": "Resource with id [CLOUDDELIVERY] is invalid. Serverless Application Repostiory does not support dynamic reference in 'ApplicationId' property." + } + ] +}