Jordan Morris
Jordan Morris

Reputation: 2301

What are the most restrictive aws resource name limitations (e.g. characters and length)?

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

Answers (1)

mostafazh
mostafazh

Reputation: 4197

1. AWS Lambda

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.

2. S3 Bucket:

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.

3. RDS

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.

Regex #1 (for advanced regex engines w/ lookahead support)

 /(?=.{3,63}$)(?!-)(?!.*--)[a-z0-9-]+(?<!-)/

Read this and this for better understand the regex above.

Regex #2

 /(^[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

Related Questions