Merge pull request #2595 from bblommers/feature/2317

Add CF update/delete methods for Lambda
This commit is contained in:
Mike Grima 2019-12-09 14:04:49 -08:00 committed by GitHub
commit 76aaa2df0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 152 additions and 0 deletions

View file

@ -363,6 +363,8 @@ class LambdaFunction(BaseModel):
self.code_bytes = key.value
self.code_size = key.size
self.code_sha_256 = hashlib.sha256(key.value).hexdigest()
self.code["S3Bucket"] = updated_spec["S3Bucket"]
self.code["S3Key"] = updated_spec["S3Key"]
return self.get_configuration()
@ -526,6 +528,15 @@ class LambdaFunction(BaseModel):
return make_function_arn(self.region, ACCOUNT_ID, self.function_name)
raise UnformattedGetAttTemplateException()
@classmethod
def update_from_cloudformation_json(
cls, new_resource_name, cloudformation_json, original_resource, region_name
):
updated_props = cloudformation_json["Properties"]
original_resource.update_configuration(updated_props)
original_resource.update_function_code(updated_props["Code"])
return original_resource
@staticmethod
def _create_zipfile_from_plaintext_code(code):
zip_output = io.BytesIO()
@ -535,6 +546,9 @@ class LambdaFunction(BaseModel):
zip_output.seek(0)
return zip_output.read()
def delete(self, region):
lambda_backends[region].delete_function(self.function_name)
class EventSourceMapping(BaseModel):
def __init__(self, spec):