Regex for AWS ARN
Validates AWS Amazon Resource Names in arn:partition:service:region:account-id:resource format.
Pattern
/^arn:(aws|aws-cn|aws-us-gov):[a-zA-Z0-9_-]+:[a-z0-9-]*:\d{0,12}:.+$/ Live Tester
Enter a string to test
Examples
✓ arn:aws:s3:::my-bucket
✓ arn:aws:iam::123456789012:user/admin
✓ arn:aws:lambda:us-east-1:123456789012:function:my-func
✗ arn:azure:s3:::bucket
✗ not-an-arn
✗ arn:aws:
Pattern Breakdown
^arn: — literal ARN prefix
(aws|aws-cn|aws-us-gov) — partition
:[a-zA-Z0-9_-]+ — service name
:[a-z0-9-]* — region (can be empty)
:\d{0,12} — account ID (up to 12 digits, can be empty)
:.+$ — resource identifier
Code Snippets
Javascript
const regex = /^arn:(aws|aws-cn|aws-us-gov):[a-zA-Z0-9_-]+:[a-z0-9-]*:\d{0,12}:.+$/;
regex.test("arn:aws:iam::123456789012:user/admin"); // true Python
import re
pattern = r"^arn:(aws|aws-cn|aws-us-gov):[a-zA-Z0-9_-]+:[a-z0-9-]*:\d{0,12}:.+$"
bool(re.match(pattern, "arn:aws:iam::123456789012:user/admin")) # True Php
$pattern = '/^arn:(aws|aws-cn|aws-us-gov):[a-zA-Z0-9_-]+:[a-z0-9-]*:\d{0,12}:.+$/';
preg_match($pattern, "arn:aws:iam::123456789012:user/admin"); // 1 Related Patterns
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Frequently Asked Questions
What is the regex for AWS ARN?▾
The regex pattern for AWS ARN is /^arn:(aws|aws-cn|aws-us-gov):[a-zA-Z0-9_-]+:[a-z0-9-]*:\d{0,12}:.+$/. Validates AWS Amazon Resource Names in arn:partition:service:region:account-id:resource format.
How do I use the AWS ARN regex in JavaScript?▾
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the AWS ARN pattern match?▾
It matches strings like arn:aws:s3:::my-bucket; it rejects strings like arn:azure:s3:::bucket. See the Examples section above for the full list of matching and non-matching cases.