Assume synchronous Lambda invocation by default (#3615)
* Assume synchronous Lambda invocation by default * Support Python 2 with dict-unpacking
This commit is contained in:
parent
9324ca3b0c
commit
ddd3c0edc4
@ -621,7 +621,8 @@ class LambdaFunction(CloudFormationModel, DockerModel):
|
||||
|
||||
# Get the invocation type:
|
||||
res, errored, logs = self._invoke_lambda(code=self.code, event=body)
|
||||
if request_headers.get("x-amz-invocation-type") == "RequestResponse":
|
||||
inv_type = request_headers.get("x-amz-invocation-type", "RequestResponse")
|
||||
if inv_type == "RequestResponse":
|
||||
encoded = base64.b64encode(logs.encode("utf-8"))
|
||||
response_headers["x-amz-log-result"] = encoded.decode("utf-8")
|
||||
result = res.encode("utf-8")
|
||||
|
@ -103,8 +103,9 @@ def test_list_functions():
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
@pytest.mark.parametrize("invocation_type", [None, "RequestResponse"])
|
||||
@mock_lambda
|
||||
def test_invoke_requestresponse_function():
|
||||
def test_invoke_requestresponse_function(invocation_type):
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
@ -118,12 +119,15 @@ def test_invoke_requestresponse_function():
|
||||
Publish=True,
|
||||
)
|
||||
|
||||
# Only add invocation-type keyword-argument when provided, otherwise the request
|
||||
# fails to be validated
|
||||
kw = {}
|
||||
if invocation_type:
|
||||
kw["InvocationType"] = invocation_type
|
||||
|
||||
in_data = {"msg": "So long and thanks for all the fish"}
|
||||
success_result = conn.invoke(
|
||||
FunctionName="testFunction",
|
||||
InvocationType="RequestResponse",
|
||||
Payload=json.dumps(in_data),
|
||||
LogType="Tail",
|
||||
FunctionName="testFunction", Payload=json.dumps(in_data), LogType="Tail", **kw
|
||||
)
|
||||
|
||||
if "FunctionError" in success_result:
|
||||
@ -141,9 +145,7 @@ def test_invoke_requestresponse_function():
|
||||
|
||||
# Logs should not be returned by default, only when the LogType-param is supplied
|
||||
success_result = conn.invoke(
|
||||
FunctionName="testFunction",
|
||||
InvocationType="RequestResponse",
|
||||
Payload=json.dumps(in_data),
|
||||
FunctionName="testFunction", Payload=json.dumps(in_data), **kw
|
||||
)
|
||||
|
||||
success_result["StatusCode"].should.equal(200)
|
||||
|
Loading…
Reference in New Issue
Block a user