in samtranslator/plugins/application/serverless_app_plugin.py [0:0]
def on_before_transform_resource(self, logical_id, resource_type, resource_properties): # type: ignore[no-untyped-def]
"""
Hook method that gets called before "each" SAM resource gets processed
Replaces the ApplicationId and Semantic Version pairs with a TemplateUrl.
:param string logical_id: Logical ID of the resource being processed
:param string resource_type: Type of the resource being processed
:param dict resource_properties: Properties of the resource
"""
if not self._resource_is_supported(resource_type): # type: ignore[no-untyped-call]
return
# Sanitize properties
self._check_for_dictionary_key(logical_id, resource_properties, [self.LOCATION_KEY]) # type: ignore[no-untyped-call]
# If location isn't a dictionary, don't modify the resource.
if not isinstance(resource_properties[self.LOCATION_KEY], dict):
resource_properties[self.TEMPLATE_URL_KEY] = resource_properties[self.LOCATION_KEY]
return
# If it is a dictionary, check for other required parameters
self._check_for_dictionary_key( # type: ignore[no-untyped-call]
logical_id, resource_properties[self.LOCATION_KEY], [self.APPLICATION_ID_KEY, self.SEMANTIC_VERSION_KEY]
)
app_id = resource_properties[self.LOCATION_KEY].get(self.APPLICATION_ID_KEY)
app_id = sam_expect(app_id, logical_id, "ApplicationId").to_not_be_none()
if isinstance(app_id, dict):
raise InvalidResourceException(
logical_id,
"Property 'ApplicationId' cannot be resolved. Only FindInMap "
"and Ref intrinsic functions are supported.",
)
semver = resource_properties[self.LOCATION_KEY].get(self.SEMANTIC_VERSION_KEY)
if not semver:
raise InvalidResourceException(logical_id, "Property 'SemanticVersion' cannot be blank.")
if isinstance(semver, dict):
raise InvalidResourceException(
logical_id,
"Property 'SemanticVersion' cannot be resolved. Only FindInMap "
"and Ref intrinsic functions are supported.",
)
key = self._make_app_key(app_id, semver)
# Throw any resource exceptions saved from the before_transform_template event
if isinstance(self._applications[key], InvalidResourceException):
raise self._applications[key]
# validation does not resolve an actual template url
if not self._validate_only:
resource_properties[self.TEMPLATE_URL_KEY] = self._applications[key]