Reputation: 2301
Different resources in aws, such as S3 buckets, lambdas and roles, have different maximum lengths and different character sets which they accept.
Is there a very restrictive resource name, which, if you follow it, you will also be obeying the restrictions of all other resources?
I'm looking for a set of constraints which will obey every kind of restriction enforced by all resource groups, globally, yet also be as permissive as possible.
The ideal answer would be a nice, unambiguous regular expression.
Upvotes: 22
Views: 18993
Reputation: 4197
Function name must contain only letters, numbers, hyphens, or underscores
This field is too long. Maximum length is 140 characters.
This field is too short. Minimum length is 1 character.
source: AWS Lambda "Create Function" Page & API docs.
Bucket name must NOT contain uppercase characters or underscores
Bucket name must be between 3 and 63 characters long
source: AWS S3 "Create Bucket" Page & API docs.
Must contain 1 to 63 alphanumeric characters or hyphens.
First character must be a letter.
Cannot end with a hyphen or contain two consecutive hyphens.
source: AWS RDS docs
So adding only the 3 services above we can conclude that it's best to be:
Only lowercase alphanumeric characters and hyphens.
Minimum of 3 characters and maximum of 63.
First character must be a letter, cannot end with a hyphen or contain two consecutive hyphens.
I'd also suggest subtracting a common prefix (i.e. company name initials, "google-") from the maximum length to avoid running into issues when trying to create a bucket (or any AWS wide name) that could happen with a valid common name = "john"
Also looking at the IAM username and roles length restrictions (found here), nothing seems to conflict with the above conclusion.
/(?=.{3,63}$)(?!-)(?!.*--)[a-z0-9-]+(?<!-)/
Read this and this for better understand the regex above.
/(^[a-z\d]{1,2}((-[a-z\d])|([a-z\d]{1,2})){0,30}[a-z\d]$)|(^[a-z\d]((-[a-z\d])|([a-z\d]{1,2})){0,30}[a-z\d-]?[a-z\d]$)/
Upvotes: 29