T
ToolPrime

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

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.

Related Tools