add aws_lamba.invoke_async method
This commit is contained in:
parent
ace54787c0
commit
a379d76cfc
@ -33,6 +33,13 @@ class LambdaResponse(BaseResponse):
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Cannot handle request")
|
raise ValueError("Cannot handle request")
|
||||||
|
|
||||||
|
def invoke_async(self, request, full_url, headers):
|
||||||
|
self.setup_class(request, full_url, headers)
|
||||||
|
if request.method == 'POST':
|
||||||
|
return self._invoke_async(request, full_url)
|
||||||
|
else:
|
||||||
|
raise ValueError("Cannot handle request")
|
||||||
|
|
||||||
def _invoke(self, request, full_url):
|
def _invoke(self, request, full_url):
|
||||||
response_headers = {}
|
response_headers = {}
|
||||||
lambda_backend = self.get_lambda_backend(full_url)
|
lambda_backend = self.get_lambda_backend(full_url)
|
||||||
@ -48,6 +55,20 @@ class LambdaResponse(BaseResponse):
|
|||||||
else:
|
else:
|
||||||
return 404, response_headers, "{}"
|
return 404, response_headers, "{}"
|
||||||
|
|
||||||
|
def _invoke_async(self, request, full_url):
|
||||||
|
response_headers = {}
|
||||||
|
lambda_backend = self.get_lambda_backend(full_url)
|
||||||
|
|
||||||
|
path = request.path if hasattr(request, 'path') else request.path_url
|
||||||
|
function_name = path.split('/')[-3]
|
||||||
|
if lambda_backend.has_function(function_name):
|
||||||
|
fn = lambda_backend.get_function(function_name)
|
||||||
|
fn.invoke(self.body, self.headers, response_headers)
|
||||||
|
response_headers['Content-Length'] = str(0)
|
||||||
|
return 202, response_headers, ""
|
||||||
|
else:
|
||||||
|
return 404, response_headers, "{}"
|
||||||
|
|
||||||
def _list_functions(self, request, full_url, headers):
|
def _list_functions(self, request, full_url, headers):
|
||||||
lambda_backend = self.get_lambda_backend(full_url)
|
lambda_backend = self.get_lambda_backend(full_url)
|
||||||
return 200, {}, json.dumps({
|
return 200, {}, json.dumps({
|
||||||
|
@ -11,4 +11,5 @@ url_paths = {
|
|||||||
'{0}/(?P<api_version>[^/]+)/functions/?$': response.root,
|
'{0}/(?P<api_version>[^/]+)/functions/?$': response.root,
|
||||||
'{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/?$': response.function,
|
'{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/?$': response.function,
|
||||||
'{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/invocations/?$': response.invoke,
|
'{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/invocations/?$': response.invoke,
|
||||||
|
'{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/invoke-async/?$': response.invoke_async,
|
||||||
}
|
}
|
||||||
|
@ -469,3 +469,28 @@ def test_invoke_lambda_error():
|
|||||||
|
|
||||||
assert 'FunctionError' in result
|
assert 'FunctionError' in result
|
||||||
assert result['FunctionError'] == 'Handled'
|
assert result['FunctionError'] == 'Handled'
|
||||||
|
|
||||||
|
@mock_lambda
|
||||||
|
def test_invoke_async_function():
|
||||||
|
conn = boto3.client('lambda', 'us-west-2')
|
||||||
|
conn.create_function(
|
||||||
|
FunctionName='testFunction',
|
||||||
|
Runtime='python2.7',
|
||||||
|
Role='test-iam-role',
|
||||||
|
Handler='lambda_function.handler',
|
||||||
|
Code={
|
||||||
|
'ZipFile': get_test_zip_file1(),
|
||||||
|
},
|
||||||
|
Description='test lambda function',
|
||||||
|
Timeout=3,
|
||||||
|
MemorySize=128,
|
||||||
|
Publish=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
success_result = conn.invoke_async(
|
||||||
|
FunctionName='testFunction',
|
||||||
|
InvokeArgs=json.dumps({ 'test': 'event' })
|
||||||
|
)
|
||||||
|
|
||||||
|
print(success_result)
|
||||||
|
success_result['Status'].should.equal(202)
|
||||||
|
Loading…
Reference in New Issue
Block a user