An internal AWS SDK utility for generating Node.js user agent strings with runtime environment information
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
An internal AWS SDK utility for generating Node.js user agent strings with runtime environment information.
@aws-sdk/util-user-agent-nodenpm install @aws-sdk/util-user-agent-node// ESM import
import {
createDefaultUserAgentProvider,
defaultUserAgent,
crtAvailability,
DefaultUserAgentOptions,
PreviouslyResolved,
UA_APP_ID_ENV_NAME,
UA_APP_ID_INI_NAME,
NODE_APP_ID_CONFIG_OPTIONS
} from "@aws-sdk/util-user-agent-node";
// CommonJS import
const {
createDefaultUserAgentProvider,
defaultUserAgent,
crtAvailability,
DefaultUserAgentOptions,
PreviouslyResolved,
UA_APP_ID_ENV_NAME,
UA_APP_ID_INI_NAME,
NODE_APP_ID_CONFIG_OPTIONS
} = require("@aws-sdk/util-user-agent-node");import { createDefaultUserAgentProvider } from "@aws-sdk/util-user-agent-node";
// Create a user agent provider for a specific AWS service
const userAgentProvider = createDefaultUserAgentProvider({
serviceId: "s3",
clientVersion: "3.879.0"
});
// Generate user agent with optional app ID configuration
const userAgent = await userAgentProvider({
userAgentAppId: async () => "my-application-id"
});
// Returns: [["aws-sdk-js", "3.879.0"], ["ua", "2.1"], ["os/linux", "5.4.0"], ...]The primary functionality for creating user agent strings with runtime metadata.
function createDefaultUserAgentProvider(options: DefaultUserAgentOptions): (config?: PreviouslyResolved) => Promise<UserAgent>;
interface DefaultUserAgentOptions {
serviceId?: string;
clientVersion: string;
}
interface PreviouslyResolved {
userAgentAppId: Provider<string | undefined>;
}Basic service user agent:
const provider = createDefaultUserAgentProvider({
serviceId: "dynamodb",
clientVersion: "3.879.0"
});
const userAgent = await provider();
// Generates: [["aws-sdk-js", "3.879.0"], ["ua", "2.1"], ["os/darwin", "22.1.0"], ["lang/js"], ["md/nodejs", "18.19.0"], ["api/dynamodb", "3.879.0"]]With application ID:
const provider = createDefaultUserAgentProvider({
serviceId: "s3",
clientVersion: "3.879.0"
});
const userAgent = await provider({
userAgentAppId: async () => "my-app-v1.0"
});
// Adds: ["app/my-app-v1.0"] to the user agent arrayWithout service ID (generic client):
const provider = createDefaultUserAgentProvider({
clientVersion: "3.879.0"
});
const userAgent = await provider();
// Excludes the ["api/{serviceId}", clientVersion] sectionThe user agent is returned as an array of string pairs (UserAgent type from @smithy/types):
["aws-sdk-js", clientVersion] - SDK identification["ua", "2.1"] - User agent version["os/{platform}", release] - Operating system info (e.g., ["os/linux", "5.4.0"])["lang/js"] - Language identification["md/nodejs", nodeVersion] - Runtime metadata["md/crt-avail"] - Added if AWS CRT is available["api/{serviceId}", clientVersion] - Service API (if serviceId provided)["exec-env/{AWS_EXECUTION_ENV}"] - Execution environment (if env var set)["app/{appId}"] - Application ID (if provided via config)Utilities for detecting AWS Common Runtime (CRT) availability.
const crtAvailability: {
isCrtAvailable: boolean;
};CRT Availability Object:
import { crtAvailability } from "@aws-sdk/util-user-agent-node";
// Check if CRT is available
if (crtAvailability.isCrtAvailable) {
console.log("AWS CRT is available");
}
// This object is mutated by aws-crt package when loaded
// Default value: { isCrtAvailable: false }Constants and configuration selectors for user agent app ID loading.
const UA_APP_ID_ENV_NAME: string;
const UA_APP_ID_INI_NAME: string;
const NODE_APP_ID_CONFIG_OPTIONS: LoadedConfigSelectors<string | undefined>;import { UA_APP_ID_ENV_NAME, UA_APP_ID_INI_NAME } from "@aws-sdk/util-user-agent-node";
console.log(UA_APP_ID_ENV_NAME); // "AWS_SDK_UA_APP_ID"
console.log(UA_APP_ID_INI_NAME); // "sdk_ua_app_id"import { NODE_APP_ID_CONFIG_OPTIONS } from "@aws-sdk/util-user-agent-node";
// Used internally by AWS SDK for loading app ID from:
// 1. Environment variable: AWS_SDK_UA_APP_ID
// 2. INI config file: sdk_ua_app_id (or deprecated sdk-ua-app-id)
// 3. Default fallback value
// The configuration object provides standardized loading behavior
// for the @smithy/node-config-provider systemfunction defaultUserAgent(options: DefaultUserAgentOptions): (config?: PreviouslyResolved) => Promise<UserAgent>;Deprecated alias:
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
// ⚠️ Deprecated - use createDefaultUserAgentProvider instead
const provider = defaultUserAgent({
serviceId: "s3",
clientVersion: "3.879.0"
});Required external types from dependencies:
// From @smithy/types
type UserAgent = UserAgentPair[];
type UserAgentPair = [string, string];
type Provider<T> = () => Promise<T> | T;
// From @smithy/node-config-provider
interface LoadedConfigSelectors<T> {
environmentVariableSelector: (env: NodeJS.ProcessEnv) => T | undefined;
configFileSelector: (profile: any) => T | undefined;
default: T;
}aws-crt (optional) - When installed, enables CRT availability detectionAWS_SDK_UA_APP_ID - Optional application identifierAWS_EXECUTION_ENV - Optional execution environment identifierThis package is designed for internal AWS SDK usage. All exports are marked @internal in the source code, indicating they are not intended for direct external consumption. The package automatically collects runtime metadata including: