AWS Mock Data is a Node.js library that provides realistic mock data for AWS services. It’s designed to streamline the development and testing of AWS-based applications by generating valid JWT tokens, JWKs, and other mock service data.
- 🔐 Generate valid Cognito JWT ID and access tokens
- 🔑 Create JWKS (JSON Web Key Sets) for token verification
- 📘 Written in TypeScript with full type safety
- 🧪 Ideal for unit/integration tests and local development
- 🚀 Zero-config setup – ready out of the box
Using npm:
npm install --save-dev aws-mock-dataOr with Yarn:
yarn add --dev aws-mock-dataimport { awsServices, utils, types } from "aws-mock-data";
const keyPair = utils.getAsymmetricKeys();
const user: types.User = {
emailId: "user@example.com",
givenName: "John",
familyName: "Doe",
emailVerified: true
};
// Create tokens with custom configuration
const tokens = awsServices.cognito.getCognitoTokens({
asymmetricKeys: keyPair,
user,
cognito: {
groups: ["admin", "users"],
roles: ["arn:aws:iam::123456789012:role/AdminRole"]
},
userPool: {
id: "us-east-1_ABC123",
region: "us-east-1"
},
jwtConfig: {
minutesToExpiry: 60,
authTimeInEpoch: Math.floor(Date.now() / 1000)
}
});Generates mock Cognito ID and Access tokens.
Parameters:
asymmetricKeys— Key pair used for signing JWTsuser— User information (required)cognito— Optional Cognito-specific data (e.g., groups, roles)userPool— Optional user pool settingsjwtConfig— Optional token timing configuration
Returns: CognitoTokens — { id_token, access_token }
Generates a JWKS (JSON Web Key Set) for token validation.
Parameters:
asymmetricKeys— RSA key pair for JWK generation
Returns: Single JWK object or null on failure
Generates an RSA key pair for signing and verification.
Options:
keyLength— Bit size of the key (default:2048)
Returns: AsymmetricKeys — Key ID, PEM strings, and JWK object
import jwt from "jsonwebtoken";
const keyPair = utils.getAsymmetricKeys();
const tokens = awsServices.cognito.getCognitoTokens({
asymmetricKeys: keyPair,
user: { emailId: "test@example.com" }
});
// Verify the token
const decoded = jwt.verify(tokens.id_token, keyPair.pem.publicKey);
console.log(decoded);const keyPair = utils.getAsymmetricKeys();
const jwks = awsServices.userPool.getUserPoolJwks({
asymmetricKeys: keyPair
});
// Mock JWKS endpoint response
const jwksResponse = {
keys: [jwks]
};- Not for production use — testing only
- Keep private keys out of source control
- Generate new keys per test suite when possible
- Reuse key pairs to speed up tests
- Cache tokens until expiry
- Avoid over-configuration – use sensible defaults
We welcome contributions! Please see CONTRIBUTING.md for:
- Project setup
- Running tests and linters
- PR guidelines and code style
See CHANGELOG.md for a detailed history of changes and releases.
MIT © Hanut Arora