@adastradev/serverless-discovery-sdk

中文文档
3.0.14发布于 2026/07/23MITTypeScriptCommonJS近 30 天下载 3730

Serverless Service Discovery API

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. Code Example

serverless-discovery-sdk-js

npm license The last serverless micro-service you'll ever wonder how to find

The AWS Serverless Discovery SDK interacts with a discovery microservice to discover endpoints for micro-services written for a serverless architecture. This is similar to clustered services such as Consul or ZooKeeper, but without the concept of instances or nodes that must be monitored for online state. This library is designed to support use both on the server side (for service-to-service lookups) and on the browser/client side.

This project contains the Typescript/Javascript bindings for the discovery service; Other bindings can be found in the AdAstraDev organization on GitHub

Installation

npm install @adastradev/serverless-discovery-sdk

Usage

Service/Cloud Dependencies

Semver versioning is supported by the discovery service 1.1.x. Pass a semver compatible value in the lookupService call to receive the newest compatible matching version. Services and their desired versions can also be specified in the cloudDependencies field of package.json.

{
  "cloudDependencies": {
    "service1": "1.x",
    "service2": "^1.2.8-testbranch", // A pre-release version for development purposes
    "service3": "3.x.x"
  }
}

Version Postfix values

In some testing environments, it can be useful to modify the lookup version to avoid collision with a production environment. If the VERSION_POSTFIX environment variable at runtime, it will always append this to the version of a lookup call.

If you are looking up services which are highly coupled or are not well isolated, and using them for system tests, you should:

  • Set the VERSION_POSTFIX environment variable set to -staging
  • Pass the environment variable through to the runtime where lookups are happening (lambda, docker, etc.)

If there is a lookup for serviceA, version 1.1.0, it will instead only talk to 1.1.0-staging. All lookup calls will follow a similar pattern while the environment variable is present.

TL;DR: If you are looking up services which are not well isolated, and rely on a staging environment to avoid operations on prod databases/resources, add the following to your pipeline in a staging deployment/testing step.

bitbucket-pipelines.yml:

- export VERSION_POSTFIX='-staging'
# Deployment steps follow...

serverless.yml

provider:
  environment:
    VERSION_POSTFIX: ${env:VERSION_POSTFIX, ''}

Code Example

I recommend setting up a utility function to handle construction of the SDK, and the lookup call - see below example.

import { DiscoverySdk } from '@adastradev/serverless-discovery-sdk';

export default async function lookup(serviceName) {

  const sdk = new DiscoverySdk(
    process.env.DISCOVERY_SERVICE_URL,
    process.env.DISCOVERY_SERVICE_REGION,
    // Non-versioned services will default to lookup via this stage
    process.env.DEFAULT_STAGE,
    undefined,
    // Create map of cloudDependencies from package.json
    new Map(Object.entries(require('../path/to/package.json')['cloudDependencies'])),
  );

  const endpoints = await sdk.lookupService(
    serviceName
  );

  return endpoints[0];

}

版本与发布记录

@adastradev/serverless-discovery-sdk 共发布 92 个版本,首次发布于 2018/08/07;过去 12 个月发布了 2 个版本。

版本发布日期距今
3.0.14latest2026/07/233 个月前
3.0.132026/02/178 个月前
3.0.122025/09/261.1 年前
3.0.112025/08/051.3 年前
3.0.11-beta.1754338560573beta2025/08/051.3 年前
3.0.102025/05/141.5 年前

关于 @adastradev/serverless-discovery-sdk 的常见问题

@adastradev/serverless-discovery-sdk 是什么?

Serverless Service Discovery API

如何安装 @adastradev/serverless-discovery-sdk?

在项目目录运行 npm install @adastradev/serverless-discovery-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@adastradev/astra-logger(>= 1.4.6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adastradev/serverless-discovery-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adastradev/serverless-discovery-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adastradev/serverless-discovery-sdk 可以商用吗?

@adastradev/serverless-discovery-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adastradev/serverless-discovery-sdk 的下载量有多少?

根据 npm 官方下载统计,@adastradev/serverless-discovery-sdk 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,730 次,日均约 124 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adastradev/serverless-discovery-sdk 还在维护吗?

最新版本 3.0.14 发布于 2026/07/23(3 个月前);至今共发布 92 个版本,其中过去 12 个月发布了 2 个;首次发布于 2018/08/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。