@@ -96,47 +96,35 @@ def __init__(
9696 self .container_host_interface = container_host_interface
9797 self .extra_hosts = extra_hosts
9898
99- def invoke (
100- self ,
101- function_identifier : str ,
102- event : str ,
103- tenant_id : Optional [str ] = None ,
104- stdout : Optional [StreamWriter ] = None ,
105- stderr : Optional [StreamWriter ] = None ,
106- override_runtime : Optional [str ] = None ,
107- invocation_type : str = "RequestResponse" ,
108- durable_execution_name : Optional [str ] = None ,
109- ) -> Optional [Dict [str , str ]]:
99+ def get_function (self , function_identifier : str , tenant_id : Optional [str ] = None ) -> Function :
110100 """
111- Find the Lambda function with given name and invoke it. Pass the given event to the function and return
112- response through the given streams.
113-
114- This function will block until either the function completes or times out.
101+ Get a Lambda function by identifier, raising FunctionNotFound if not found.
115102
116103 Parameters
117104 ----------
118- function_identifier str
119- Identifier of the Lambda function to invoke, it can be logicalID, function name or full path
120- event str
121- Event data passed to the function. Must be a valid JSON String.
122- stdout samcli.lib.utils.stream_writer.StreamWriter
123- Stream writer to write the output of the Lambda function to.
124- stderr samcli.lib.utils.stream_writer.StreamWriter
125- Stream writer to write the Lambda runtime logs to.
126- Runtime: str
127- To use instead of the runtime specified in the function configuration
128- durable_execution_name: str
129- Optional name for the durable execution (for durable functions only)
130-
105+ function_identifier : str
106+ Identifier of the Lambda function, it can be logicalID, function name or full path
107+ tenant_id : Optional[str]
108+ Optional tenant ID for multi-tenant functions
131109 Returns
132110 -------
133- Optional[Dict[str, str]]
134- HTTP headers dict if this was a durable function invocation, None otherwise
111+ Function
112+ The Lambda function configuration
135113
136114 Raises
137115 ------
138- FunctionNotfound
139- When we cannot find a function with the given name
116+ InvalidFunctionNameException
117+ When the function identifier doesn't match AWS Lambda's validation pattern
118+ FunctionNotFound
119+ When we cannot find a function with the given identifier
120+ TenantIdValidationError
121+ When the tenant ID is not provided for multi-tenant functions
122+ UnsupportedInlineCodeError
123+ When the function has inline code and is being invoked locally
124+ InvalidIntermediateImageError
125+ When the function has an intermediate image and is being invoked locally
126+ UnsupportedRuntimeArchitectureError
127+ When the function runtime and architecture are not compatible
140128 """
141129 # Normalize function identifier from ARN if provided
142130 normalized_function_identifier = normalize_sam_function_identifier (function_identifier )
@@ -182,6 +170,55 @@ def invoke(
182170 "Remove the tenant ID from your request and try again."
183171 )
184172
173+ return function
174+
175+ def invoke (
176+ self ,
177+ function_identifier : str ,
178+ event : str ,
179+ tenant_id : Optional [str ] = None ,
180+ stdout : Optional [StreamWriter ] = None ,
181+ stderr : Optional [StreamWriter ] = None ,
182+ override_runtime : Optional [str ] = None ,
183+ invocation_type : str = "RequestResponse" ,
184+ durable_execution_name : Optional [str ] = None ,
185+ function : Optional [Function ] = None ,
186+ ) -> Optional [Dict [str , str ]]:
187+ """
188+ Find the Lambda function with given name and invoke it. Pass the given event to the function and return
189+ response through the given streams.
190+
191+ This function will block until either the function completes or times out.
192+
193+ Parameters
194+ ----------
195+ function_identifier str
196+ Identifier of the Lambda function to invoke, it can be logicalID, function name or full path
197+ event str
198+ Event data passed to the function. Must be a valid JSON String.
199+ stdout samcli.lib.utils.stream_writer.StreamWriter
200+ Stream writer to write the output of the Lambda function to.
201+ stderr samcli.lib.utils.stream_writer.StreamWriter
202+ Stream writer to write the Lambda runtime logs to.
203+ Runtime: str
204+ To use instead of the runtime specified in the function configuration
205+ durable_execution_name: str
206+ Optional name for the durable execution (for durable functions only)
207+
208+ Returns
209+ -------
210+ Optional[Dict[str, str]]
211+ HTTP headers dict if this was a durable function invocation, None otherwise
212+
213+ Raises
214+ ------
215+ FunctionNotfound
216+ When we cannot find a function with the given name
217+ """
218+ # Get the function configuration
219+ if not function :
220+ function = self .get_function (function_identifier , tenant_id )
221+
185222 config = self .get_invoke_config (function , override_runtime )
186223
187224 if (
0 commit comments