npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@janiscommerce/accounts-ids-by-service

v1.0.0

Published

Resolve the Janis serviceCode to AWS Account ID mapping from the shared Parameter Store

Readme

Accounts Ids By Service

Build Status Coverage Status npm version

Resolve, at runtime, the mapping between a Janis service code and its AWS Account ID.

The mapping lives in a single SSM Parameter Store parameter named accountsIdsByService, shared across accounts via AWS RAM. This package encapsulates the discovery (RAM) + read (SSM) + in-memory cache logic so consumers such as @janiscommerce/lambda (runtime) and sls-helper-plugin-janis (deploy-time) can resolve account IDs through a single dependency.

Installation

npm install @janiscommerce/accounts-ids-by-service

API

AccountsIdsByService.getAccountId(serviceCode)

async. Returns the AWS Account ID (string) for the given Janis serviceCode.

  • Throws an AccountsIdsByServiceError with code NO_SERVICE_ACCOUNT_ID when the service code is not present in the mapping.
  • In a local/dev environment it resolves to undefined instead of throwing (see Usage).
'use strict';

const { AccountsIdsByService } = require('@janiscommerce/accounts-ids-by-service');

const accountId = await AccountsIdsByService.getAccountId('catalog');
// '012345678901'

AccountsIdsByService.getMapping()

async. Returns the full mapping object { [serviceCode]: awsAccountId }. Used, for example, by the deploy-time plugin to build cross-account ARNs.

'use strict';

const { AccountsIdsByService } = require('@janiscommerce/accounts-ids-by-service');

const mapping = await AccountsIdsByService.getMapping();
// { catalog: '012345678901', wms: '109876543210', ... }

The mapping is fetched once and cached in memory permanently for the lifetime of the Lambda container (no TTL). Both getAccountId() and getMapping() share the same cache.

AccountsIdsByServiceError

Error class thrown by this package. Exposes static get codes():

| Code | Value | Meaning | |---|---|---| | NO_SERVICE_ACCOUNT_ID | 1 | The requested service code is not present in the mapping | | INVALID_MAPPING | 2 | The parameter value could not be parsed as JSON |

'use strict';

const { AccountsIdsByService, AccountsIdsByServiceError } = require('@janiscommerce/accounts-ids-by-service');

try {
	await AccountsIdsByService.getAccountId('unknown-service');
} catch(error) {
	if(error.code === AccountsIdsByServiceError.codes.NO_SERVICE_ACCOUNT_ID)
		console.error('Service is not mapped to any AWS account');
}

accountsIdsPermissions

An array of sls-helper IAM statement hooks (['iamStatement', {...}]) granting the permissions this package needs at runtime: ram:ListResources and ssm:GetParameter. Spread it into your service serverless.js.

Usage

Grant the runtime permissions by spreading accountsIdsPermissions into your service hooks:

'use strict';

const { helper } = require('sls-helper');

const { accountsIdsPermissions } = require('@janiscommerce/accounts-ids-by-service');

module.exports = helper({
	hooks: [

		// ...other service hooks

		...accountsIdsPermissions
	]
});

Local behaviour

When running locally the package never reaches AWS. It is considered a local/dev environment when any of these holds:

  • JANIS_ENV === 'local'
  • JANIS_LOCAL === '1'
  • NODE_ENV === 'dev'

In that case:

  • getMapping() resolves to an empty object {}.
  • getAccountId() resolves to undefined and does not throw NO_SERVICE_ACCOUNT_ID, mirroring the behaviour of @janiscommerce/lambda Invoker.getServiceAccountId().

Resolution algorithm

On the first resolution (cache miss, non-local):

  1. RAM discoveryram:ListResources with resourceOwner: 'OTHER-ACCOUNTS' and resourceType: 'ssm:Parameter', then find the resource whose ARN ends with :parameter/accountsIdsByService.
  2. SSM read — if the shared ARN is found, ssm:GetParameter by that ARN and JSON.parse its value. This is the common case.
  3. Fallback — if no share is found (i.e. the parameter lives in the same account, so it is not shared with itself), ssm:GetParameter by name (accountsIdsByService) in the local account.

The resolved mapping is cached in memory for the lifetime of the container.