AWS ARN Parser
The `aws-arn-parser` package (version 1.0.1) offers a basic utility for parsing Amazon Resource Name (ARN) strings into a structured JavaScript object. It extracts common ARN components such as service, region, account ID, and resource identifier. The project's initial README explicitly stated it was in "early days," indicating a lack of robust validation and potential for future structural changes. It is a simple, dependency-free parser primarily for Node.js environments. The package under this specific name appears to be effectively unmaintained or abandoned, with no discernible release cadence. Developers are advised to consider actively maintained and more robust alternatives, such as `@aws-sdk/util-arn-parser` from the official AWS SDK, or potentially the re-scoped `@sandfox/arn` by the same author, which provides TypeScript support and a revised output structure.
Common errors
-
TypeError: parser is not a function
cause Attempting to import `aws-arn-parser` as a named export or using ESM `import` syntax in a CommonJS environment without a transpiler, where the package only exports a default function via `module.exports`.fixEnsure you are using the correct CommonJS `require` syntax for a default function export: `const parser = require('aws-arn-parser');` -
ARN parsing yields unexpected output fields (e.g., 'namespace' instead of 'accountID')
cause You are using `aws-arn-parser` (an older package) but expecting the output structure from a different, newer ARN parser (e.g., `@sandfox/arn` or `@aws-sdk/util-arn-parser`).fixRefer to the `aws-arn-parser` v1.0.1 documentation for its specific output format. If you need the newer structure, migrate to the corresponding package.
Warnings
- deprecated The `aws-arn-parser` package (specifically version 1.0.1 and likely all versions under this name) is effectively abandoned. Its author may have transitioned to `@sandfox/arn`, but this specific package is no longer actively maintained. Users should migrate to actively supported alternatives.
- gotcha This parser does not perform any validation on the input ARN string. It will attempt to parse any string provided, potentially leading to incorrect or unexpected output for malformed ARNs without throwing an error.
- breaking The output object structure of `aws-arn-parser` (v1.0.x) differs significantly from newer or alternative ARN parsers (e.g., `@sandfox/arn` or `@aws-sdk/util-arn-parser`). Specifically, it uses fields like `namespace` and `relativeId` instead of `accountID` and `resource` or `resourcePart`.
Install
-
npm install aws-arn-parser -
yarn add aws-arn-parser -
pnpm add aws-arn-parser
Imports
- parser
import parser from 'aws-arn-parser';
const parser = require('aws-arn-parser');
Quickstart
const parser = require('aws-arn-parser');
// Example IAM Server Certificate ARN
const myAwsString = "arn:aws:iam::123456789012:server-certificate/division_abc/subdivision_xyz/ProdServerCert";
const arn = parser(myAwsString);
console.log(arn);
/* Expected output for v1.0.1:
{
arn: 'arn',
aws: 'aws',
service: 'iam',
region: '',
namespace: '123456789012',
relativeId: 'server-certificate/division_abc/subdivision_xyz/ProdServerCert'
}
*/
// Example S3 Bucket ARN with no region/account
const s3ArnString = "arn:aws:s3:::my_bucket/path/to/object";
const s3Arn = parser(s3ArnString);
console.log(s3Arn);
/* Expected output for v1.0.1:
{
arn: 'arn',
aws: 'aws',
service: 's3',
region: '',
namespace: '',
relativeId: 'my_bucket/path/to/object'
}
*/