diff --git a/builtin/aws/lambda/platform.go b/builtin/aws/lambda/platform.go index b2d2cd26af2..5b7c02918a4 100644 --- a/builtin/aws/lambda/platform.go +++ b/builtin/aws/lambda/platform.go @@ -81,6 +81,18 @@ func (p *Platform) ConfigSet(config interface{}) error { } } + // validate storage - value between 512 and 10240 + if c.StorageMB != 0 { + if err := utils.Error(validation.ValidateStruct(c, + validation.Field(&c.StorageMB, + validation.Min(512).Error("Storage must a value between 512 and 10240"), + validation.Max(10240).Error("Storage must a value between 512 and 10240"), + ), + )); err != nil { + return err + } + } + return nil } @@ -281,7 +293,7 @@ func (p *Platform) Deploy( architecture = DockerArchitectureMapper(img.Architecture, log) } - storage := int64(p.config.Storage) + storage := int64(p.config.StorageMB) if storage == 0 { storage = DefaultStorageSize } @@ -875,7 +887,7 @@ deploy { ) doc.SetField( - "storage", + "storagemb", "The storage size (in MB) of the Lambda function's `/tmp` directory. Must be a value between 512 and 10240.", docs.Default("512"), ) @@ -910,7 +922,7 @@ type Config struct { // The storage size (in MB) of the Lambda function's `/tmp` directory. // Must be a value between 512 and 10240. // Defaults to 512 MB. - Storage int `hcl:"storage,optional"` + StorageMB int `hcl:"storagemb,optional"` } var ( diff --git a/builtin/aws/lambda/platform_test.go b/builtin/aws/lambda/platform_test.go index ec7d8cb0bf5..d304061212b 100644 --- a/builtin/aws/lambda/platform_test.go +++ b/builtin/aws/lambda/platform_test.go @@ -38,4 +38,21 @@ func TestPlatformConfig(t *testing.T) { require.EqualError(t, p.ConfigSet(cfg), "rpc error: code = InvalidArgument desc = Timeout: Timeout must not be negative.") } }) + + t.Run("disallows invalid storagemb", func(t *testing.T) { + var p Platform + { + cfg := &Config{ + StorageMB: 100, + } + require.EqualError(t, p.ConfigSet(cfg), "rpc error: code = InvalidArgument desc = StorageMB: Storage must a value between 512 and 10240.") + } + + { + cfg := &Config{ + StorageMB: 20000, + } + require.EqualError(t, p.ConfigSet(cfg), "rpc error: code = InvalidArgument desc = StorageMB: Storage must a value between 512 and 10240.") + } + }) } diff --git a/website/content/partials/components/platform-aws-lambda.mdx b/website/content/partials/components/platform-aws-lambda.mdx index 8bc6febfa35..cee9d21bcce 100644 --- a/website/content/partials/components/platform-aws-lambda.mdx +++ b/website/content/partials/components/platform-aws-lambda.mdx @@ -56,7 +56,7 @@ The amount of memory, in megabytes, to assign the function. - **Optional** - Default: 265 -#### storage +#### storagemb The storage size (in MB) of the Lambda function's `/tmp` directory. Must be a value between 512 and 10240.