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