AWS Lambda - Allow function deletions by ARN

This commit is contained in:
Bert Blommers 2019-10-22 09:31:37 +01:00
parent 21d2fac468
commit ce4bd5d64c
4 changed files with 36 additions and 5 deletions

View File

@ -645,8 +645,10 @@ class LambdaStorage(object):
self._arns[fn.function_arn] = fn
return fn
def del_function(self, name, qualifier=None):
if name in self._functions:
def del_function(self, name_or_arn, qualifier=None):
function = self.get_function_by_name_or_arn(name_or_arn)
if function:
name = function.function_name
if not qualifier:
# Something is still reffing this so delete all arns
latest = self._functions[name]['latest'].function_arn

View File

@ -266,7 +266,7 @@ class LambdaResponse(BaseResponse):
return 404, {}, "{}"
def _delete_function(self, request, full_url, headers):
function_name = self.path.rsplit('/', 1)[-1]
function_name = unquote(self.path.rsplit('/', 1)[-1])
qualifier = self._get_param('Qualifier', None)
if self.lambda_backend.delete_function(function_name, qualifier):

View File

@ -9,7 +9,7 @@ response = LambdaResponse()
url_paths = {
'{0}/(?P<api_version>[^/]+)/functions/?$': response.root,
r'{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/?$': response.function,
r'{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_:%-]+)/?$': response.function,
r'{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/versions/?$': response.versions,
r'{0}/(?P<api_version>[^/]+)/event-source-mappings/?$': response.event_source_mappings,
r'{0}/(?P<api_version>[^/]+)/event-source-mappings/(?P<UUID>[\w_-]+)/?$': response.event_source_mapping,

View File

@ -415,7 +415,6 @@ def test_get_function():
conn.get_function(FunctionName='junk', Qualifier='$LATEST')
@mock_lambda
@mock_s3
def test_delete_function():
@ -449,6 +448,36 @@ def test_delete_function():
success_result.should.equal({'ResponseMetadata': {'HTTPStatusCode': 204}})
function_list = conn.list_functions()
function_list['Functions'].should.have.length_of(0)
@mock_lambda
@mock_s3
def test_delete_function_by_arn():
bucket_name = 'test-bucket'
s3_conn = boto3.client('s3', 'us-east-1')
s3_conn.create_bucket(Bucket=bucket_name)
zip_content = get_test_zip_file2()
s3_conn.put_object(Bucket=bucket_name, Key='test.zip', Body=zip_content)
conn = boto3.client('lambda', 'us-east-1')
fnc = conn.create_function(FunctionName='testFunction',
Runtime='python2.7', Role='test-iam-role',
Handler='lambda_function.lambda_handler',
Code={'S3Bucket': bucket_name, 'S3Key': 'test.zip'},
Description='test lambda function',
Timeout=3, MemorySize=128, Publish=True)
conn.delete_function(FunctionName=fnc['FunctionArn'])
function_list = conn.list_functions()
function_list['Functions'].should.have.length_of(0)
@mock_lambda
def test_delete_unknown_function():
conn = boto3.client('lambda', 'us-west-2')
conn.delete_function.when.called_with(
FunctionName='testFunctionThatDoesntExist').should.throw(botocore.client.ClientError)