Registry / devops / aws-arn

aws-arn

JSON →
library2.1.2jsnpmunverified

AWS ARN parser and utilities for Node.js and browser. Current stable version 2.1.2, released as a TypeScript rewrite in v2.0.0. Parses ARN strings into structured objects, supports creating ARNs from components, and formatting back to strings. Lightweight with no external dependencies. Differentiates from alternatives (e.g., @aws-sdk/util-arn-parser) by providing a fluent API, broader resource part parsing (including qualifiers), and optional strict mode with error throwing.

npm install aws-arn
INSTALL
IMPORT
SIG · AWS-ARN
A
aws-arn
devopsjavascriptv2.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Arn
import Arn from 'aws-arn'
const Arn = require('aws-arn')
Default ESM import; the type is a class. CJS require works but TypeScript may need esModuleInterop.
Arn
import { Arn } from 'aws-arn'
import { Arn as ArnClass } from 'aws-arn'
Both default and named exports exist; default import is preferred.
Arnit
import type { Arni } from 'aws-arn'
TypeScript type for Arn instance; not exported as value. Use import type for type-only imports.

Demonstrates parsing, creating, formatting ARNs, and accessing resource parts with strict mode.

import Arn from 'aws-arn'; // Parse an ARN (strict mode: throws on invalid) const arn = Arn.parse('aws:arn:s3:eu-west-1:123456789:bucket/path/object', true); console.log(arn.service); // 's3' console.log(arn.region); // 'eu-west-1' console.log(arn.accountId); // '123456789' // Resource info console.log(arn.resource); // { type: 'bucket', id: 'path/object' } // Format back to string console.log(arn.format()); // 'aws:arn:s3:eu-west-1:123456789:bucket/path/object' // Create ARN from components const arn2 = new Arn({ service: 'lambda', region: 'eu-west-1', accountId: '123456789', resourcePart: 'Layer:my-layer:42' }); console.log(arn2.resource); // { type: 'Layer', id: 'my-layer', qualifier: '42' }
Debug
Known issues
breakingV2 changed return type of Arn.parse: no longer returns null by default; use second argument `true` to throw on invalid ARN.
fix
Update code to handle Arn | null or pass true as second argument to throw.
affects: >=2.0.0
deprecatedV1's Arn.parse returned null for invalid ARNs; V2 deprecated that behavior.
fix
Migrate to V2 and use strict mode or check for null.
affects: <=1.x
gotchaThe `resource` property is read-only and only available after parsing; constructing with new Arn({...}) will not automatically parse resourcePart into resource - you must pass resourcePart as a string.
fix
Access `resource` after parsing only; when constructing, use `resourcePart` string.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Arn.parse(...) is not a function
Importing incorrectly: using named import instead of default.
fix
Use `import Arn from 'aws-arn'` or `const { default: Arn } = require('aws-arn')`.
Cannot read property 'service' of null
Using Arn.parse on invalid ARN without strict mode (returns null).
fix
Pass true as second argument: Arn.parse(arnStr, true) or check for null.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
aws-arn — npm install aws-arn · libregistry