Registry / security / aws-secrets-parser

aws-secrets-parser

JSON →
library1.3.0jsnpmunverified

Fetch and parse JSON secrets from AWS Secrets Manager. Version 1.3.0. Provides a programmatic API (retrieve function) and a CLI for retrieving secrets as JSON objects, with options to format keys (constant, pascal, preserve), add prefixes, and output in JSON, shell export, or dotenv format. Includes built-in TypeScript type definitions. Release cadence: intermittent, mature stable. Differentiators: simple API, CLI with multiple output formats, no heavy abstraction layer.

npm install aws-secrets-parser
INSTALL
IMPORT
SIG · AWS-SECRETS-PARSER
A
aws-secrets-parser
securityjavascriptv1.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

retrieve
import { retrieve } from 'aws-secrets-parser'
const retrieve = require('aws-secrets-parser').retrieve
Default export is not available; use named import. Both ESM and CJS are supported but ESM is preferred in modern codebases.
default import
import * as secretsParser from 'aws-secrets-parser'
import secretsParser from 'aws-secrets-parser'
No default export: use namespace import or named import for retrieve.
CLI invocation
npx aws-secrets-parser <secret-name>
aws-secrets-parser-cli
CLI is invoked via the package name; no separate CLI package.

Demonstrates using the retrieve function to fetch and parse a JSON secret from AWS Secrets Manager.

import { retrieve } from 'aws-secrets-parser'; async function main() { try { const secret = await retrieve('my-secret', 'us-east-1'); console.log(secret); // { username: 'admin', password: 'secret123' } } catch (error) { console.error('Failed to retrieve secret:', error); } } main();
Debug
Known issues
gotchaThe secret must be valid JSON; otherwise the parse will throw without clear error message.
fix
Ensure your AWS secret is stored in JSON format. Use the CLI with output json to debug.
affects: >=1.0.0
deprecatedRequire('aws-sdk') is deprecated; this package uses @aws-sdk/client-secrets-manager v3.
fix
Ensure you have v3 of the AWS SDK installed as a peer dependency.
affects: >=1.0.0
gotchaThe retrieve function returns a parsed object of type unknown; TypeScript may require explicit typing.
fix
Use type assertion: const secret = await retrieve<{ username: string; password: string }>('...');
affects: >=1.0.0
gotchaCLI requires AWS credentials configured (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or IAM role).
fix
Set environment variables or use AWS profiles.
affects: >=1.0.0
gotchaOutput format 'export' prints to stdout; use source <(cmd) to set env vars.
fix
Run: source <(aws-secrets-parser secret --output export)
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: retrieve is not a function
Incorrect import: default import instead of named import.
fix
Use import { retrieve } from 'aws-secrets-parser'
Could not find AWS credentials
CLI or API invoked without AWS credentials configured.
fix
Set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION.
SyntaxError: Unexpected token u in JSON at position 0
Secret stored as plain text, not JSON, or undefined secret.
fix
Ensure the secret is JSON format in AWS Secrets Manager and the name is correct.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
@aws-sdk/client-secrets-managerrequiredRequired for fetching secrets from AWS Secrets Manager at runtime.
Agent activity
27 hits · last 30 days
node
24
Resources
aws-secrets-parser — npm install aws-secrets-parser · libregistry