Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove str type constrain in Fn:FindInMap to avoid the issue of … #7306

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def handle_find_in_map(self, intrinsic_value, ignore_errors):
)

second_level_value = top_level_value.get(second_level_key)
verify_intrinsic_type_str(
verify_non_null(
mndeveci marked this conversation as resolved.
Show resolved Hide resolved
second_level_value,
IntrinsicResolver.FN_FIND_IN_MAP,
message="The SecondLevelKey is missing in the Mappings dictionary in Fn::FindInMap "
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/local/start_lambda/test_start_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,28 @@ def test_invoke_with_function_timeout(self, use_full_path):
self.assertIsNone(response.get("FunctionError"))
self.assertEqual(response.get("StatusCode"), 200)

@parameterized.expand([("False"), ("True")])
@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_function_timeout_using_lookup_value(self, use_full_path):
"""
This behavior does not match the actually Lambda Service. For functions that timeout, data returned like the
following:
{"errorMessage":"<timestamp> <request_id> Task timed out after 5.00 seconds"}

For Local Lambda's, however, timeouts are an interrupt on the thread that runs invokes the function. Since the
invoke is on a different thread, we do not (currently) have a way to communicate this back to the caller. So
when a timeout happens locally, we do not add the FunctionError: Unhandled to the response and have an empty
string as the data returned (because no data was found in stdout from the container).
"""
response = self.lambda_client.invoke(
FunctionName=f"{self.parent_path if use_full_path == 'True' else ''}TimeoutFunctionUsingLookupValue"
)

self.assertEqual(response.get("Payload").read().decode("utf-8"), "")
self.assertIsNone(response.get("FunctionError"))
self.assertEqual(response.get("StatusCode"), 200)


class TestWarmContainersBaseClass(StartLambdaIntegBaseClass):
def setUp(self):
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/testdata/invoke/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Parameters:
Type: String
Default: "2"

Mappings:
common:
LambdaFunction:
Timeout: 5

Resources:
HelloWorldServerlessFunction:
Type: AWS::Serverless::Function
Expand Down Expand Up @@ -58,6 +63,14 @@ Resources:
CodeUri: .
Timeout: 5

TimeoutFunctionUsingLookupValue:
Type: AWS::Serverless::Function
Properties:
Handler: main.sleep_handler
Runtime: python3.9
CodeUri: .
Timeout: !FindInMap [common, LambdaFunction, Timeout]

HelloWorldSleepFunction:
Type: AWS::Serverless::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def setUp(self):
"Basic": {"Test": {"key": "value"}},
"value": {"anotherkey": {"key": "result"}},
"result": {"value": {"key": "final"}},
"NonStrValue": {"Test": {"key": 0}},
}
}
self.resolver = IntrinsicResolver(symbol_resolver=IntrinsicsSymbolTable(), template=template)
Expand All @@ -218,6 +219,11 @@ def test_basic_find_in_map(self):
result = self.resolver.intrinsic_property_resolver(intrinsic, True)
self.assertEqual(result, "value")

def test_basic_find_in_map_with_non_string_value(self):
intrinsic = {"Fn::FindInMap": ["NonStrValue", "Test", "key"]}
result = self.resolver.intrinsic_property_resolver(intrinsic, True)
self.assertEqual(result, 0)

def test_nested_find_in_map(self):
intrinsic_base_1 = {"Fn::FindInMap": ["Basic", "Test", "key"]}
intrinsic_base_2 = {"Fn::FindInMap": [intrinsic_base_1, "anotherkey", "key"]}
Expand Down
Loading