Add/improve Lambda coverage - no functionality changes
This commit is contained in:
parent
1f6b600d49
commit
42311c40ad
@ -3977,46 +3977,46 @@
|
|||||||
- [ ] update_resource
|
- [ ] update_resource
|
||||||
|
|
||||||
## lambda
|
## lambda
|
||||||
0% implemented
|
41% implemented
|
||||||
- [ ] add_layer_version_permission
|
- [ ] add_layer_version_permission
|
||||||
- [ ] add_permission
|
- [ ] add_permission
|
||||||
- [ ] create_alias
|
- [ ] create_alias
|
||||||
- [ ] create_event_source_mapping
|
- [X] create_event_source_mapping
|
||||||
- [ ] create_function
|
- [X] create_function
|
||||||
- [ ] delete_alias
|
- [ ] delete_alias
|
||||||
- [ ] delete_event_source_mapping
|
- [X] delete_event_source_mapping
|
||||||
- [ ] delete_function
|
- [X] delete_function
|
||||||
- [ ] delete_function_concurrency
|
- [ ] delete_function_concurrency
|
||||||
- [ ] delete_layer_version
|
- [ ] delete_layer_version
|
||||||
- [ ] get_account_settings
|
- [ ] get_account_settings
|
||||||
- [ ] get_alias
|
- [ ] get_alias
|
||||||
- [ ] get_event_source_mapping
|
- [X] get_event_source_mapping
|
||||||
- [ ] get_function
|
- [X] get_function
|
||||||
- [ ] get_function_configuration
|
- [ ] get_function_configuration
|
||||||
- [ ] get_layer_version
|
- [ ] get_layer_version
|
||||||
- [ ] get_layer_version_by_arn
|
- [ ] get_layer_version_by_arn
|
||||||
- [ ] get_layer_version_policy
|
- [ ] get_layer_version_policy
|
||||||
- [ ] get_policy
|
- [ ] get_policy
|
||||||
- [ ] invoke
|
- [X] invoke
|
||||||
- [ ] invoke_async
|
- [ ] invoke_async
|
||||||
- [ ] list_aliases
|
- [ ] list_aliases
|
||||||
- [ ] list_event_source_mappings
|
- [X] list_event_source_mappings
|
||||||
- [ ] list_functions
|
- [X] list_functions
|
||||||
- [ ] list_layer_versions
|
- [ ] list_layer_versions
|
||||||
- [ ] list_layers
|
- [ ] list_layers
|
||||||
- [ ] list_tags
|
- [X] list_tags
|
||||||
- [ ] list_versions_by_function
|
- [X] list_versions_by_function
|
||||||
- [ ] publish_layer_version
|
- [ ] publish_layer_version
|
||||||
- [ ] publish_version
|
- [ ] publish_version
|
||||||
- [ ] put_function_concurrency
|
- [ ] put_function_concurrency
|
||||||
- [ ] remove_layer_version_permission
|
- [ ] remove_layer_version_permission
|
||||||
- [ ] remove_permission
|
- [ ] remove_permission
|
||||||
- [ ] tag_resource
|
- [X] tag_resource
|
||||||
- [ ] untag_resource
|
- [X] untag_resource
|
||||||
- [ ] update_alias
|
- [ ] update_alias
|
||||||
- [ ] update_event_source_mapping
|
- [X] update_event_source_mapping
|
||||||
- [ ] update_function_code
|
- [X] update_function_code
|
||||||
- [ ] update_function_configuration
|
- [X] update_function_configuration
|
||||||
|
|
||||||
## lex-models
|
## lex-models
|
||||||
0% implemented
|
0% implemented
|
||||||
|
@ -979,6 +979,32 @@ class LambdaBackend(BaseBackend):
|
|||||||
def add_policy(self, function_name, policy):
|
def add_policy(self, function_name, policy):
|
||||||
self.get_function(function_name).policy = policy
|
self.get_function(function_name).policy = policy
|
||||||
|
|
||||||
|
def update_function_code(self, function_name, qualifier, body):
|
||||||
|
fn = self.get_function(function_name, qualifier)
|
||||||
|
|
||||||
|
if fn:
|
||||||
|
if body.get("Publish", False):
|
||||||
|
fn = self.publish_function(function_name)
|
||||||
|
|
||||||
|
config = fn.update_function_code(body)
|
||||||
|
return config
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def update_function_configuration(self, function_name, qualifier, body):
|
||||||
|
fn = self.get_function(function_name, qualifier)
|
||||||
|
|
||||||
|
return fn.update_configuration(body) if fn else None
|
||||||
|
|
||||||
|
def invoke(self, function_name, qualifier, body, headers, response_headers):
|
||||||
|
fn = self.get_function(function_name, qualifier)
|
||||||
|
if fn:
|
||||||
|
payload = fn.invoke(body, headers, response_headers)
|
||||||
|
response_headers["Content-Length"] = str(len(payload))
|
||||||
|
return response_headers, payload
|
||||||
|
else:
|
||||||
|
return response_headers, None
|
||||||
|
|
||||||
|
|
||||||
def do_validate_s3():
|
def do_validate_s3():
|
||||||
return os.environ.get("VALIDATE_LAMBDA_S3", "") in ["", "1", "true"]
|
return os.environ.get("VALIDATE_LAMBDA_S3", "") in ["", "1", "true"]
|
||||||
|
@ -168,10 +168,10 @@ class LambdaResponse(BaseResponse):
|
|||||||
function_name = self.path.rsplit("/", 2)[-2]
|
function_name = self.path.rsplit("/", 2)[-2]
|
||||||
qualifier = self._get_param("qualifier")
|
qualifier = self._get_param("qualifier")
|
||||||
|
|
||||||
fn = self.lambda_backend.get_function(function_name, qualifier)
|
response_header, payload = self.lambda_backend.invoke(
|
||||||
if fn:
|
function_name, qualifier, self.body, self.headers, response_headers
|
||||||
payload = fn.invoke(self.body, self.headers, response_headers)
|
)
|
||||||
response_headers["Content-Length"] = str(len(payload))
|
if payload:
|
||||||
return 202, response_headers, payload
|
return 202, response_headers, payload
|
||||||
else:
|
else:
|
||||||
return 404, response_headers, "{}"
|
return 404, response_headers, "{}"
|
||||||
@ -337,26 +337,23 @@ class LambdaResponse(BaseResponse):
|
|||||||
def _put_configuration(self, request):
|
def _put_configuration(self, request):
|
||||||
function_name = self.path.rsplit("/", 2)[-2]
|
function_name = self.path.rsplit("/", 2)[-2]
|
||||||
qualifier = self._get_param("Qualifier", None)
|
qualifier = self._get_param("Qualifier", None)
|
||||||
|
resp = self.lambda_backend.update_function_configuration(
|
||||||
|
function_name, qualifier, body=self.json_body
|
||||||
|
)
|
||||||
|
|
||||||
fn = self.lambda_backend.get_function(function_name, qualifier)
|
if resp:
|
||||||
|
return 200, {}, json.dumps(resp)
|
||||||
if fn:
|
|
||||||
config = fn.update_configuration(self.json_body)
|
|
||||||
return 200, {}, json.dumps(config)
|
|
||||||
else:
|
else:
|
||||||
return 404, {}, "{}"
|
return 404, {}, "{}"
|
||||||
|
|
||||||
def _put_code(self):
|
def _put_code(self):
|
||||||
function_name = self.path.rsplit("/", 2)[-2]
|
function_name = self.path.rsplit("/", 2)[-2]
|
||||||
qualifier = self._get_param("Qualifier", None)
|
qualifier = self._get_param("Qualifier", None)
|
||||||
|
resp = self.lambda_backend.update_function_code(
|
||||||
|
function_name, qualifier, body=self.json_body
|
||||||
|
)
|
||||||
|
|
||||||
fn = self.lambda_backend.get_function(function_name, qualifier)
|
if resp:
|
||||||
|
return 200, {}, json.dumps(resp)
|
||||||
if fn:
|
|
||||||
if self.json_body.get("Publish", False):
|
|
||||||
fn = self.lambda_backend.publish_function(function_name)
|
|
||||||
|
|
||||||
config = fn.update_function_code(self.json_body)
|
|
||||||
return 200, {}, json.dumps(config)
|
|
||||||
else:
|
else:
|
||||||
return 404, {}, "{}"
|
return 404, {}, "{}"
|
||||||
|
@ -7,16 +7,18 @@ import boto3
|
|||||||
|
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
alternative_service_names = {'lambda': 'awslambda'}
|
||||||
|
|
||||||
|
|
||||||
def get_moto_implementation(service_name):
|
def get_moto_implementation(service_name):
|
||||||
service_name_standardized = service_name.replace("-", "") if "-" in service_name else service_name
|
service_name = service_name.replace("-", "") if "-" in service_name else service_name
|
||||||
if not hasattr(moto, service_name_standardized):
|
alt_service_name = alternative_service_names[service_name] if service_name in alternative_service_names else service_name
|
||||||
|
if not hasattr(moto, alt_service_name):
|
||||||
return None
|
return None
|
||||||
module = getattr(moto, service_name_standardized)
|
module = getattr(moto, alt_service_name)
|
||||||
if module is None:
|
if module is None:
|
||||||
return None
|
return None
|
||||||
mock = getattr(module, "mock_{}".format(service_name_standardized))
|
mock = getattr(module, "mock_{}".format(service_name))
|
||||||
if mock is None:
|
if mock is None:
|
||||||
return None
|
return None
|
||||||
backends = list(mock().backends.values())
|
backends = list(mock().backends.values())
|
||||||
|
Loading…
Reference in New Issue
Block a user