Registry / database / awscdk-resources-mongodbatlas

awscdk-resources-mongodbatlas

JSON →
library4.0.0jsnpmunverified

The official AWS CDK Construct Library for provisioning MongoDB Atlas resources via AWS CloudFormation. Current stable version 4.0.0 (released 2025) supporting aws-cdk-lib ^2.200.1 and constructs ^10.0.5. Provides L1, L2, and L3 CDK constructs for defining Atlas clusters, database users, network peering, and more in TypeScript, Python, .NET, Java, and Go. Unlike community alternatives, this is maintained by MongoDB, ensuring compatibility with Atlas API and CDK evolution. Regular monthly releases with semantic versioning. Ships full TypeScript declarations and adheres to AWS CDK best practices.

npm install awscdk-resources-mongodbatlas
INSTALL
IMPORT
SIG · AWSCDK-RESOURCES-M
A
awscdk-resources-mongodbatlas
databasejavascriptv4.0.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.

CfnProject
import { CfnProject } from 'awscdk-resources-mongodbatlas'
const CfnProject = require('awscdk-resources-mongodbatlas').CfnProject
ESM-only since v4; CommonJS require is not supported. For CJS projects, use dynamic import.
CfnCluster
import { CfnCluster } from 'awscdk-resources-mongodbatlas'
import { Cluster } from 'awscdk-resources-mongodbatlas'
L1 resources use Cfn prefix; do not confuse with L2 constructs.
CfnDatabaseUser
import { CfnDatabaseUser } from 'awscdk-resources-mongodbatlas'
import { MongoDBUser } from 'awscdk-resources-mongodbatlas'
Named exports follow CloudFormation resource naming convention.
CfnNetworkContainer
import { CfnNetworkContainer } from 'awscdk-resources-mongodbatlas'
import { NetworkContainer } from 'awscdk-resources-mongodbatlas'
L1 only; L2 constructs may be available in future versions.
CfnPrivateEndpoint
import { CfnPrivateEndpoint } from 'awscdk-resources-mongodbatlas'
import { PrivateEndpoint } from 'awscdk-resources-mongodbatlas'
Ensure correct spelling: 'Endpoint' not 'Endpoint'.

Creates a MongoDB Atlas project, an M10 replica set cluster, and a database user with admin roles.

import { App, Stack, StackProps } from 'aws-cdk-lib'; import { CfnCluster, CfnProject, CfnDatabaseUser } from 'awscdk-resources-mongodbatlas'; import { Construct } from 'constructs'; const app = new App(); const stack = new Stack(app, 'MongoDBStack', { env: { region: 'us-east-1' } }); // Create project const project = new CfnProject(stack, 'AtlasProject', { name: 'my-atlas-project', orgId: process.env.MONGODB_ATLAS_ORG_ID ?? '', profile: 'default', }); // Create cluster const cluster = new CfnCluster(stack, 'AtlasCluster', { projectId: project.ref, name: 'my-cluster', providerSettings: { providerName: 'AWS', instanceSizeName: 'M10', regionName: 'US_EAST_1', }, clusterType: 'REPLICASET', }); // Create database user new CfnDatabaseUser(stack, 'DatabaseUser', { projectId: project.ref, username: 'admin', password: process.env.MONGODB_ATLAS_DB_PASSWORD ?? '', databaseName: 'admin', roles: [{ roleName: 'readWriteAnyDatabase', databaseName: 'admin' }], }); app.synth();
Debug
Known issues
breakingVersion 4.0.0 drops CJS support. Package is now ESM-only.
fix
Update your project to use ESM ('type': 'module' in package.json) or use dynamic import: const { CfnCluster } = await import('awscdk-resources-mongodbatlas');
affects: >=4.0.0
breakingStarting from v4, all exports are prefixed with 'Cfn' to align with AWS CDK naming conventions. Old names (e.g., 'Cluster', 'Project') no longer exist.
fix
Replace imports: import { Cluster } from 'awscdk-resources-mongodbatlas' → import { CfnCluster } from 'awscdk-resources-mongodbatlas'
affects: >=4.0.0
deprecatedThe 'profile' property on CfnProject is deprecated in favor of 'secretProfile' or direct API key settings.
fix
Use 'secretProfile' with AWS Secrets Manager or pass 'apiKeys.apiKeyId' and 'apiKeys.apiKey'.
affects: >=3.0.0
gotchaThe 'providerSettings.regionName' must use AWS region constants (e.g., 'US_EAST_1'), not standard AWS region strings (e.g., 'us-east-1').
fix
Use the region constants from the Atlas API: 'US_EAST_1', 'EU_WEST_1', etc.
affects: >=1.0.0
gotchaWhen using CfnCluster, you must set 'clusterType' to 'REPLICASET' or 'GEOSHARDED'. Default is not set and will cause deployment failure.
fix
Explicitly set clusterType: 'REPLICASET' for standard replica sets.
affects: >=1.0.0
deprecatedCfnProject 'orgId' is now required; older versions allowed it to be optional and used profile defaults.
fix
Always provide 'orgId' from environment or Secret Manager.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'awscdk-resources-mongodbatlas'
Package not installed or ESM/CJS mismatch in Node.js resolving the wrong module.
fix
Run npm install awscdk-resources-mongodbatlas@4.0.0. Ensure your project is ESM (type: module) or use dynamic require.
Property 'instanceSizeName' does not exist on type '{ providerName: string; ... }'
Missing a property in the providerSettings; the correct property is 'instanceSizeName' (note capital N) but TypeScript errors may point to type mismatch.
fix
Check your providerSettings object includes all required fields: providerName, instanceSizeName, regionName.
Resource handler returned message: "Project 'my-atlas-project' already exists"
Creating a project with the same name in the same Atlas organization.
fix
Use a unique project name or import an existing project using 'CfnProject.fromProjectId()'.
Profile not found: default
No Atlas profile configured in ~/.mongocli/mongosh.json or environment variables missing.
fix
Set MONGODB_ATLAS_PUBLIC_KEY and MONGODB_ATLAS_PRIVATE_KEY environment variables, or create a profile using mongocli.
Error: The 'clusterType' property is required
CfnCluster requires clusterType to be specified.
fix
Add clusterType: 'REPLICASET' (or 'GEOSHARDED') to the CfnCluster props.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
aws-cdk-librequiredCore CDK library for CloudFormation synthesis and stack management
constructsrequiredBase construct class required for all CDK constructs
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources