Skip to content

Instantly share code, notes, and snippets.

@ppsirius
Created July 10, 2019 08:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppsirius/74ac410634d5dba8f7566c5e20b5aad4 to your computer and use it in GitHub Desktop.
Save ppsirius/74ac410634d5dba8f7566c5e20b5aad4 to your computer and use it in GitHub Desktop.
aws s3 bucket name validation RegEx
{
bucketNameValidationRules: [
// rules from https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-s3-bucket-naming-requirements.html
v => !!v || 'Name is required',
v => (v && /^[\a-z\d\.\-]*$/.test(v)) || 'The bucket name can contain only lower-case characters, numbers, periods, and dashes.',
v => (v && /^[\a-z\d]/.test(v)) || 'The bucket name must start with a lowercase letter or number.',
v => (v && !/\-$/.test(v)) || `The bucket name can't end with a dash`,
v => (v && !/\.+\./.test(v)) || `The bucket name can't have consecutive periods`,
v => (v && !/\-+\.$/.test(v)) || `The bucket name can't end with dash adjacent to period`,
v => (v && !/^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$/.test(v)) || `The bucket name can't be formatted as an IP address`,
v => (v && (v.length >= 3 && v.length <= 63)) || 'The bucket name can be between 3 and 63 characters long.'
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment