-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable tags for Lambda functions #13352
Changes from all commits
71a97eb
4ffba0f
e8e6e4e
8912b7d
0eb8533
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,10 @@ package aws | |
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
"time" | ||
"unicode" | ||
"unicode/utf8" | ||
|
||
humanize "github.com/dustin/go-humanize" | ||
|
||
|
@@ -49,6 +51,7 @@ type LambdaConfig struct { | |
Timeout time.Duration `config:"timeout" validate:"nonzero,positive"` | ||
Role string `config:"role"` | ||
VPCConfig *vpcConfig `config:"virtual_private_cloud"` | ||
Tags map[string]string `config:"tags"` | ||
} | ||
|
||
// Validate checks a LambdaConfig | ||
|
@@ -65,7 +68,7 @@ func (c *LambdaConfig) Validate() error { | |
return fmt.Errorf("invalid role: '%s', name must match pattern %s", c.Role, arnRolePattern) | ||
} | ||
|
||
return nil | ||
return validateTags(c.Tags) | ||
} | ||
|
||
type deadLetterConfig struct { | ||
|
@@ -77,6 +80,27 @@ type vpcConfig struct { | |
SubnetIDs []string `config:"subnet_ids" validate:"required"` | ||
} | ||
|
||
func validateTags(tags map[string]string) error { | ||
for key, val := range tags { | ||
if strings.HasPrefix(key, "aws:") { | ||
return fmt.Errorf("key '%s' cannot be prefixed with 'aws:'", key) | ||
} | ||
if strings.HasPrefix(val, "aws:") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "aws:" is only a limitation for keys not the values. Limitation for the value is 255 not 127 (127 is only for the key) as mentioned in the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "aws:" is limitation for both key and value. But you are right about the lenghts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah crap you are right about the value, weird, things, I guess they scan the whole structure to make a decision. |
||
return fmt.Errorf("value '%s' cannot be prefixed with 'aws:'", val) | ||
} | ||
keyLen := utf8.RuneCountInString(key) | ||
if keyLen > 127 { | ||
return fmt.Errorf("too long key; expected 127 chars, but got %d", keyLen) | ||
} | ||
valLen := utf8.RuneCountInString(val) | ||
if valLen > 255 { | ||
return fmt.Errorf("too long value; expected 255 chars, but got %d", valLen) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// MemSizeFactor64 implements a human understandable format for bytes but also make sure that all | ||
// values used are a factory of 64. | ||
type MemSizeFactor64 int | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add validation on the tags see.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html
Looking at the documentation there are limit on lenght and they cannot start with
aws: