Skip to content

Commit

Permalink
fix: Give a more appropriate warning with Availability Dip (#3362)
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinZZ authored Oct 3, 2023
1 parent 1bd228c commit 9c59fc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samtranslator/plugins/application/serverless_app_plugin.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions tests/translator/input/error_sar_with_dynamic_reference.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Resources:
CLOUDDELIVERY:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: '{{resolve:ssm:/elw/test/sar-app}}'
SemanticVersion: 5.2.17
14 changes: 14 additions & 0 deletions tests/translator/output/error_sar_with_dynamic_reference.json
Original file line number Diff line number Diff line change
@@ -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."
}
]
}

0 comments on commit 9c59fc7

Please sign in to comment.