added UpdateFunctionCode and UpdateFunctionConfiguration and associated test cases

This commit is contained in:
Seth Black 2019-10-08 15:59:03 -05:00
commit 41af98c98b
4 changed files with 210 additions and 1 deletions

View file

@ -273,6 +273,71 @@ class LambdaFunction(BaseModel):
"Configuration": self.get_configuration(),
}
def update_configuration(self, config_updates):
for key, value in config_updates.items():
if key == "Description":
self.description = value
elif key == "Handler":
self.handler = value
elif key == "MemorySize":
self.memory_size = value
elif key == "Role":
self.role = value
elif key == "Runtime":
self.run_time = value
elif key == "Timeout":
self.timeout = value
elif key == "VpcConfig":
self.vpc_config = value
return self.get_configuration()
def update_function_code(self, spec):
if 'DryRun' in spec and spec['DryRun']:
return self.get_configuration()
if 'Publish' in spec and spec['Publish']:
self.set_version(self.version + 1)
if 'ZipFile' in spec:
# using the "hackery" from __init__" because it seems to work
# TODOs and FIXMEs included, because they'll need to be fixed
# in both places now
try:
to_unzip_code = base64.b64decode(
bytes(spec['ZipFile'], 'utf-8'))
except Exception:
to_unzip_code = base64.b64decode(spec['ZipFile'])
self.code_bytes = to_unzip_code
self.code_size = len(to_unzip_code)
self.code_sha_256 = hashlib.sha256(to_unzip_code).hexdigest()
# TODO: we should be putting this in a lambda bucket
self.code['UUID'] = str(uuid.uuid4())
self.code['S3Key'] = '{}-{}'.format(self.function_name, self.code['UUID'])
else:
key = None
try:
# FIXME: does not validate bucket region
key = s3_backend.get_key(spec['S3Bucket'], spec['S3Key'])
except MissingBucket:
if do_validate_s3():
raise ValueError(
"InvalidParameterValueException",
"Error occurred while GetObject. S3 Error Code: NoSuchBucket. S3 Error Message: The specified bucket does not exist")
except MissingKey:
if do_validate_s3():
raise ValueError(
"InvalidParameterValueException",
"Error occurred while GetObject. S3 Error Code: NoSuchKey. S3 Error Message: The specified key does not exist.")
if key:
self.code_bytes = key.value
self.code_size = key.size
self.code_sha_256 = hashlib.sha256(key.value).hexdigest()
return self.get_configuration()
@staticmethod
def convert(s):
try: