Skip to content

Commit 2fd626b

Browse files
licjunroger-zhangg
andauthored
Fix tenant ID validation error handling in sam local start-api (#8453)
* Show the correct error message when user invoke multi-tenant function without tenant-id header when using sam local start-api * Add unit test for tenant ID validation error handling in sam local start-api * Update test_local_apigw_service.py --------- Co-authored-by: Chengjun Li <> Co-authored-by: Roger Zhang <ruojiazh@amazon.com>
1 parent 47bfe49 commit 2fd626b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

samcli/local/apigw/local_apigw_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from time import time
99
from typing import Any, Dict, List, Optional, Tuple, Union
1010

11-
from flask import Flask, Request, request
11+
from flask import Flask, Request, jsonify, make_response, request
1212
from werkzeug.datastructures import Headers
1313
from werkzeug.routing import BaseConverter
1414
from werkzeug.serving import WSGIRequestHandler
1515

16-
from samcli.commands.local.lib.exceptions import UnsupportedInlineCodeError
16+
from samcli.commands.local.lib.exceptions import TenantIdValidationError, UnsupportedInlineCodeError
1717
from samcli.commands.local.lib.local_lambda import LocalLambdaRunner
1818
from samcli.lib.providers.exceptions import MissingFunctionNameException
1919
from samcli.lib.providers.provider import Api, Cors
@@ -739,6 +739,9 @@ def _request_handler(self, **kwargs):
739739

740740
# invoke the route's Lambda function
741741
lambda_response = self._invoke_lambda_function(route.function_name, route_lambda_event, tenant_id)
742+
except TenantIdValidationError as e:
743+
response_data = jsonify({"message": str(e)})
744+
endpoint_service_error = make_response(response_data, 400) # HTTP 400 Bad Request
742745
except FunctionNotFound:
743746
endpoint_service_error = ServiceErrorResponses.lambda_not_found_response()
744747
except UnsupportedInlineCodeError:

0 commit comments

Comments
 (0)