From 74da41d3307854f3df897b101da4fb22fb80c7ee Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Fri, 2 Apr 2021 19:20:54 +0500 Subject: [PATCH] lambda memory can be configured in 1 MB increments now (#1886) * lamba memory can be configured in 1 MB increments now https://aws.amazon.com/blogs/aws/new-for-aws-lambda-functions-with-up-to-10-gb-of-memory-and-6-vcpus/ --- examples/Lambda.py | 5 +- tests/examples_output/Lambda.template | 163 +------------------------- tests/test_awslambda.py | 12 +- troposphere/awslambda.py | 11 +- 4 files changed, 12 insertions(+), 179 deletions(-) diff --git a/examples/Lambda.py b/examples/Lambda.py index e579b7f1c..b10eed545 100644 --- a/examples/Lambda.py +++ b/examples/Lambda.py @@ -1,5 +1,5 @@ from troposphere import FindInMap, GetAtt, Join, Output, Parameter, Ref, Template -from troposphere.awslambda import MEMORY_VALUES, Code, Function +from troposphere.awslambda import MINIMUM_MEMORY, MAXIMUM_MEMORY, Code, Function from troposphere.cloudformation import CustomResource from troposphere.constants import NUMBER from troposphere.ec2 import Instance, SecurityGroup @@ -42,7 +42,8 @@ Type=NUMBER, Description="Amount of memory to allocate to the Lambda Function", Default="128", - AllowedValues=MEMORY_VALUES, + MinValue=MINIMUM_MEMORY, + MaxValue=MAXIMUM_MEMORY, ) ) diff --git a/tests/examples_output/Lambda.template b/tests/examples_output/Lambda.template index 73a762b7b..ab45af314 100644 --- a/tests/examples_output/Lambda.template +++ b/tests/examples_output/Lambda.template @@ -85,169 +85,10 @@ "Type": "String" }, "LambdaMemorySize": { - "AllowedValues": [ - 128, - 192, - 256, - 320, - 384, - 448, - 512, - 576, - 640, - 704, - 768, - 832, - 896, - 960, - 1024, - 1088, - 1152, - 1216, - 1280, - 1344, - 1408, - 1472, - 1536, - 1600, - 1664, - 1728, - 1792, - 1856, - 1920, - 1984, - 2048, - 2112, - 2176, - 2240, - 2304, - 2368, - 2432, - 2496, - 2560, - 2624, - 2688, - 2752, - 2816, - 2880, - 2944, - 3008, - 3072, - 3136, - 3200, - 3264, - 3328, - 3392, - 3456, - 3520, - 3584, - 3648, - 3712, - 3776, - 3840, - 3904, - 3968, - 4032, - 4096, - 4160, - 4224, - 4288, - 4352, - 4416, - 4480, - 4544, - 4608, - 4672, - 4736, - 4800, - 4864, - 4928, - 4992, - 5056, - 5120, - 5184, - 5248, - 5312, - 5376, - 5440, - 5504, - 5568, - 5632, - 5696, - 5760, - 5824, - 5888, - 5952, - 6016, - 6080, - 6144, - 6208, - 6272, - 6336, - 6400, - 6464, - 6528, - 6592, - 6656, - 6720, - 6784, - 6848, - 6912, - 6976, - 7040, - 7104, - 7168, - 7232, - 7296, - 7360, - 7424, - 7488, - 7552, - 7616, - 7680, - 7744, - 7808, - 7872, - 7936, - 8000, - 8064, - 8128, - 8192, - 8256, - 8320, - 8384, - 8448, - 8512, - 8576, - 8640, - 8704, - 8768, - 8832, - 8896, - 8960, - 9024, - 9088, - 9152, - 9216, - 9280, - 9344, - 9408, - 9472, - 9536, - 9600, - 9664, - 9728, - 9792, - 9856, - 9920, - 9984, - 10048, - 10112, - 10176, - 10240 - ], "Default": "128", "Description": "Amount of memory to allocate to the Lambda Function", + "MaxValue": 10240, + "MinValue": 128, "Type": "Number" }, "LambdaTimeout": { diff --git a/tests/test_awslambda.py b/tests/test_awslambda.py index 44eb0925e..7888bcd7a 100644 --- a/tests/test_awslambda.py +++ b/tests/test_awslambda.py @@ -226,7 +226,7 @@ def test_validate_working_directory_too_long(self): ImageConfig(WorkingDirectory="x" * 1001).validate() def test_validate_memory_size_boundaries(self): - for var in ["128", "10240"]: + for var in ["128", "129", "10240"]: validate_memory_size(var) def test_validate_memory_size_throws(self): @@ -234,15 +234,11 @@ def test_validate_memory_size_throws(self): with self.assertRaises(ValueError) as context: validate_memory_size(var) - self.assertTrue( - "Lambda Function memory size must be one of:" - in context.exception.args[0] + self.assertEqual( + context.exception.args[0], + "Lambda Function memory size must be between 128 and 10240" ) - self.assertTrue("128," in context.exception.args[0]) - - self.assertTrue(", 10240" in context.exception.args[0]) - if __name__ == "__main__": unittest.main() diff --git a/troposphere/awslambda.py b/troposphere/awslambda.py index d98aa6ec8..84fbb0c87 100644 --- a/troposphere/awslambda.py +++ b/troposphere/awslambda.py @@ -5,11 +5,6 @@ MINIMUM_MEMORY = 128 MAXIMUM_MEMORY = 10240 -MEMORY_INCREMENT = 64 -MEMORY_VALUES = [ - x - for x in range(MINIMUM_MEMORY, MAXIMUM_MEMORY + MEMORY_INCREMENT, MEMORY_INCREMENT) -] PACKAGE_TYPES = ["Image", "Zip"] RESERVED_ENVIRONMENT_VARIABLES = [ @@ -40,10 +35,10 @@ def validate_memory_size(memory_value): :return: The provided memory size if it is valid """ memory_value = int(positive_integer(memory_value)) - if memory_value not in MEMORY_VALUES: + if not MINIMUM_MEMORY <= memory_value <= MAXIMUM_MEMORY: raise ValueError( - "Lambda Function memory size must be one of:\n %s" - % ", ".join(str(mb) for mb in MEMORY_VALUES) + "Lambda Function memory size must be between %d and %d" + % (MINIMUM_MEMORY, MAXIMUM_MEMORY) ) return memory_value