Socket
Socket
Sign inDemoInstall

aws-arn

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    aws-arn

AWS ARN parser/utils


Version published
Weekly downloads
511
decreased by-34.06%
Maintainers
1
Install size
32.7 kB
Created
Weekly downloads
 

Readme

Source

aws-arn

NPM version Build Status

Parser/utils for AWS ARN:s.

This module provides a simple AWS ARN parser.

Note: v2.0.0 rewritten in TypeScript

Installation

Node.JS:

npm install aws-arn

Then within the application do

import Arn from 'aws-arn';

API reference

https://henhal.github.io/aws-arn/

Usage

Parse an ARN string

NOTE: V1 always returned null if attempting to parse invalid ARNs. V2 however supports passing a second argument fail with the value true to instead throw an error. This avoids having to deal with the return type Arn | null, which simplifies TypeScript usage:

const arn = Arn.parse('aws:arn:s3:eu-west-1:123456789:bucket/path/object');
// arn is of type Arn | null

const arn = Arn.parse('aws:arn:s3:eu-west-1:123456789:bucket/path/object', false);
// arn is of type Arn | null

const arn = Arn.parse('aws:arn:s3:eu-west-1:123456789:bucket/path/object', true);
// arn is of type Arn, or the call threw an error
const arn = Arn.parse('aws:arn:s3:eu-west-1:123456789:bucket/path/object', true);

console.log(arn);

> Arn {
    scheme: 'aws',
    partition: 'arn',
    service: 's3',
    region: 'eu-west-1',
    accountId: '123456789',
    resourcePart: 'bucket/path/object' }

Since the resource part of ARNs may have several formats, Arn objects also supply a read-only resource property that returns a parsed representation of the resource part:

const arn = Arn.parse('aws:arn:s3:eu-west-1:123456789:bucket/path/object', true);
console.log(arn.resource);

> { type: 'bucket', id: 'path/object'}

const arn = Arn.parse('aws:arn:lambda:eu-west-1:123456789:Layer:my-layer:42', true);
console.log(arn.resource);

> { type: 'Layer', id: 'my-layer', qualifier: '42'}

Create ARN from components

const arn = new Arn({
  service: 'lambda',
  region: 'eu-west-1',
  accountId: '123456789',
  resourcePart: 'Layer:my-layer:42'
});

console.log(arn);

> Arn {
    scheme: 'aws',
    partition: 'arn',
    service: 'lambda',
    region: 'eu-west-1',
    accountId: '123456789',
    resourcePart: 'Layer:my-layer:42' }

Format ARN into string

const arn = Arn.parse('aws:arn:s3:eu-west-1:123456789:bucket/path/object', true);

console.log(arn.format());

> aws:arn:s3:eu-west-1:123456789:bucket/path/object

Keywords

FAQs

Last updated on 24 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc