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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@onivoro/server-aws-credential-providers

v24.33.4

Published

AWS credential management for NestJS applications with profile support.

Readme

@onivoro/server-aws-credential-providers

AWS credential management for NestJS applications with profile support.

Installation

npm install @onivoro/server-aws-credential-providers

Overview

This library provides a simple AWS credential resolution system for NestJS applications. It resolves AWS credentials from either environment variables or AWS profile configuration.

Usage

Module Setup

Import and configure the module in your NestJS application:

import { ServerAwsCredentialProvidersModule } from '@onivoro/server-aws-credential-providers';

@Module({
  imports: [
    ServerAwsCredentialProvidersModule.configure()
  ]
})
export class AppModule {}

Configuration

The module uses environment-based configuration:

export class ServerAwsCredentialProvidersConfig {
  AWS_PROFILE?: string;  // Optional: AWS profile name from ~/.aws/credentials
}

Credential Resolution

The module provides a function to resolve AWS credentials:

import { resolveAwsCredentialProvidersByProfile } from '@onivoro/server-aws-credential-providers';

// Resolve credentials based on profile
const credentials = await resolveAwsCredentialProvidersByProfile('my-profile');

// credentials will have:
// {
//   accessKeyId: string,
//   secretAccessKey: string
// }

AWS Credentials Class

The library exports a simple credentials class:

import { AwsCredentials } from '@onivoro/server-aws-credential-providers';

const creds: AwsCredentials = {
  accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
  secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
};

How It Works

The credential resolution follows this priority:

  1. Environment Variables: If AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set, these are used
  2. AWS Profile: If an AWS profile is specified (via AWS_PROFILE env var or parameter), credentials are loaded from the AWS credentials file

Example

import { Injectable } from '@nestjs/common';
import { 
  resolveAwsCredentialProvidersByProfile,
  AwsCredentials 
} from '@onivoro/server-aws-credential-providers';

@Injectable()
export class AwsService {
  private credentials: AwsCredentials;

  async initialize() {
    // Use default profile from AWS_PROFILE env var
    this.credentials = await resolveAwsCredentialProvidersByProfile();
    
    // Or specify a profile explicitly
    // this.credentials = await resolveAwsCredentialProvidersByProfile('production');
  }

  getCredentials(): AwsCredentials {
    return this.credentials;
  }
}

Environment Variables

# Optional: Specify AWS profile to use
AWS_PROFILE=my-profile

# Direct credentials (takes precedence over profile)
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

AWS Configuration Files

The module reads from standard AWS configuration files:

  • ~/.aws/credentials - AWS credentials file
  • ~/.aws/config - AWS configuration file

Example ~/.aws/credentials:

[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

[production]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE2
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY2

Integration with AWS SDK

Use the resolved credentials with AWS SDK v3:

import { S3Client } from '@aws-sdk/client-s3';
import { resolveAwsCredentialProvidersByProfile } from '@onivoro/server-aws-credential-providers';

async function createS3Client() {
  const credentials = await resolveAwsCredentialProvidersByProfile();
  
  return new S3Client({
    region: 'us-east-1',
    credentials: {
      accessKeyId: credentials.accessKeyId,
      secretAccessKey: credentials.secretAccessKey
    }
  });
}

Notes

  • This is a simple credential provider that doesn't support advanced features like:
    • Session tokens
    • AssumeRole operations
    • Credential refresh
    • MFA authentication
  • For more complex credential scenarios, consider using AWS SDK's built-in credential providers directly

License

MIT