### Start MERN Stack Client Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/mern-cdk-ci-cd/README.md Commands to install dependencies and start the frontend client for the MERN stack application. ```Shell cd mern/client npm install npm start ``` -------------------------------- ### Start MERN Stack Server Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/mern-cdk-ci-cd/README.md Commands to install dependencies and start the backend server for the MERN stack application. ```Shell cd mern/server npm install npm start ``` -------------------------------- ### Install MongoDB Atlas AWS CDK Library Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/README.md Installs the MongoDB Atlas AWS CDK library, which provides constructs for managing MongoDB Atlas resources within an AWS CDK application. ```bash npm install awscdk-resources-mongodbatlas ``` -------------------------------- ### Bootstrap AWS Account with CDK Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/README.md Bootsraps your AWS account to enable CDK deployments. This command sets up the necessary infrastructure for CDK to manage AWS resources. ```bash cdk bootstrap aws://ACCOUNT-NUMBER/REGION ``` -------------------------------- ### Install MongoDB Atlas AWS CDK Resources (PyPI) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/README.md Installs the MongoDB Atlas AWS CDK Resources package using pip. This is the package installer for Python. ```bash pip install awscdk-resources-mongodbatlas ``` -------------------------------- ### Run Unit Tests Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/mern-cdk-ci-cd/README.md Command to execute unit tests for the MERN stack application's API. ```Shell npm test tests/api.unit.test.js ``` -------------------------------- ### MongoDB Atlas Project Invitation CDK Construct Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/test/l1-resources/project-invitation/README.md Example of how to use the MongoDB::Atlas::ProjectInvitation CDK resource to invite a user to a MongoDB Atlas project. This requires the MongoDB Atlas CDK resources to be installed and configured. ```typescript import { ProjectInvitation } from '@aws-cdk/aws-cdk-resources-mongodbatlas'; import { Construct } from 'constructs'; interface ProjectInvitationProps { projectId: string; email: string; roleNames: string[]; } export class MyProjectInvitation extends Construct { constructor(scope: Construct, id: string, props: ProjectInvitationProps) { super(scope, id); new ProjectInvitation(this, 'ProjectInvitation', { projectId: props.projectId, email: props.email, roleNames: props.roleNames, }); } } ``` -------------------------------- ### Run Integration Tests Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/mern-cdk-ci-cd/README.md Command to execute integration tests for the MERN stack application's API. ```Shell npm test tests/api.integ.test.js ``` -------------------------------- ### Configure MongoDB Atlas Connection Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/mern-cdk-ci-cd/README.md This snippet shows how to set up the MongoDB Atlas connection string and server port in the `.env` file for the MERN stack application. ```Shell ATLAS_URI=mongodb+srv://:@sandbox.jadwj.mongodb.net/myFirstDatabase?retryWrites=true&w=majority PORT=5000 ``` -------------------------------- ### Start Release with Projen Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/RELEASING.md Initiates the release process using the Projen tool, which handles the generation of packages, versioning, and changelogs. ```bash npx projen release ``` -------------------------------- ### Initialize TypeScript CDK Application Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/README.md Initializes a new AWS CDK application with TypeScript as the programming language. This command sets up the basic project structure for a CDK application. ```bash cdk init app --language typescript ``` -------------------------------- ### Build CDK Application Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/README.md Builds the TypeScript application for the AWS CDK project. This command compiles the TypeScript code into JavaScript, preparing it for deployment. ```bash npm run build ``` -------------------------------- ### Install MongoDB Atlas AWS CDK Resources (npm) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/README.md Installs the MongoDB Atlas AWS CDK Resources package using npm. This is the package manager for Node.js and the JavaScript runtime. ```bash npm i awscdk-resources-mongodbatlas ``` -------------------------------- ### AWS CDK Python Example for Federated Settings Org Role Mapping Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/test/l1-resources/federated-settings-org-role-mapping/README.md This snippet illustrates the creation of a MongoDB Atlas Federated Settings Org Role Mapping using the AWS CDK in Python. Prerequisites include having the AWS CDK and the MongoDB Atlas resources library installed. ```python from aws_cdk import Stack from constructs import Construct from awscdk_resources_mongodbatlas import FederatedSettingsOrgRoleMapping, FederatedSettingsOrgRoleMappingProps, RoleMapping class MyStack(Stack): def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: super().__init__(scope, construct_id, **kwargs) FederatedSettingsOrgRoleMapping( self, 'MyFederatedSettingsOrgRoleMapping', project_id='YOUR_PROJECT_ID', org_id='YOUR_ORG_ID', role_mapping=RoleMapping( # Role mapping configuration details here # e.g., atlas_azure_ad_tenant_id, external_group_name, role_assignments, etc. ) ) ``` -------------------------------- ### Deploy CDK Application with Context Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/README.md Deploys the AWS CDK application, passing runtime context variables such as the organization ID for MongoDB Atlas. This allows for dynamic configuration during deployment. ```bash cdk deploy --context orgId= ``` -------------------------------- ### Install MongoDB Atlas AWS CDK Resources (.NET) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/README.md Adds the MongoDB Atlas AWS CDK Resources NuGet package to a .NET project. This allows using the constructs in C#. ```bash dotnet add package MongoDB.AWSCDKResourcesMongoDBAtlas --version 1.0.0 ``` -------------------------------- ### AWS CDK Go Example for Federated Settings Org Role Mapping Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/test/l1-resources/federated-settings-org-role-mapping/README.md This snippet provides an example of defining a MongoDB Atlas Federated Settings Org Role Mapping using the AWS CDK in Go. Ensure the AWS CDK and MongoDB Atlas resources library are correctly set up. ```go package main import ( "github.com/aws/aws-cdk-go/awscdk/v2" "github.com/aws/constructs-go/constructs/v10" mongodbatlas "github.com/mongodb/awscdk-resources-mongodbatlas/mongodbatlas" ) type MyStackProps struct { awscdk.StackProps } func NewMyStack(scope constructs.Construct, id string, props *MyStackProps) awscdk.Stack { stack := awscdk.NewStack(scope, id, props.StackProps) mongodbatlas.NewFederatedSettingsOrgRoleMapping(stack, "MyFederatedSettingsOrgRoleMapping", &mongodbatlas.FederatedSettingsOrgRoleMappingProps{ ProjectId: awscdk.String("YOUR_PROJECT_ID"), OrgId: awscdk.String("YOUR_ORG_ID"), RoleMapping: &mongodbatlas.RoleMappingProperties{ // Role mapping configuration details here // e.g., AtlasAzureAdTenantId, ExternalGroupName, RoleAssignments, etc. }, }) return stack } func main() { app := awscdk.NewApp(nil) NewMyStack(app, "MyStack", &MyStackProps{}) app.Synth(nil) } ``` -------------------------------- ### Minimal Atlas Bootstrap Configuration (TypeScript) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/src/l3-resources/atlas-bootstrap/README.md Example TypeScript code for setting up the `MongoAtlasBootstrap` construct within an AWS CDK stack. It defines necessary parameters like role name, secret profile, and API keys, then instantiates the bootstrap construct. ```typescript import * as cdk from 'aws-cdk-lib' import { Construct } from 'constructs' import { MongoAtlasBootstrap, MongoAtlasBootstrapProps, AtlasBasicResources } from 'awscdk-resources-mongodbatlas' export class AtlasBoostrapExample extends cdk.Stack { constructor (scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props) const mongoDBProfile = 'development' const roleName = 'MongoDB-Atlas-CDK-Excecution' const publicKey = new cdk.CfnParameter(this, 'atlasPublicKey', { noEcho: true, type: 'String' }) const privateKey = new cdk.CfnParameter(this, 'atlasPrivateKey', { noEcho: true, type: 'String' }) const bootstrapProperties: MongoAtlasBootstrapProps = { roleName: roleName, secretProfile: mongoDBProfile, typesToActivate: AtlasBasicResources, atlasPublicKey: publicKey, atlasPrivateKey: privateKey } new MongoAtlasBootstrap(this, 'cdk-bootstrap', bootstrapProperties) } } ``` -------------------------------- ### Create MongoDB Atlas Search Deployment with AWS CDK Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/src/l1-resources/search-deployment/README.md Example of creating a MongoDB Atlas Search Deployment using the CfnSearchDeployment construct from the awscdk-resources-mongodbatlas library in TypeScript. It configures the search deployment with specified instance size and node count. ```typescript import { CfnSearchDeployment } from 'awscdk-resources-mongodbatlas'; const searchDeployment = new CfnSearchDeployment(this, 'CfnSearchDeployment', { profile: atlasProps.profile, clusterName: atlasProps.clusterName, projectId: atlasProps.projectId, specs: [ { instanceSize: "S30_HIGHCPU_NVME", nodeCount: 2, }, ] }); ``` -------------------------------- ### Create MongoDB Atlas Serverless Instance (TypeScript) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/src/l1-resources/serverless-instance/README.md Example of creating a MongoDB Atlas serverless instance using the CfnServerlessInstance construct in TypeScript with AWS CDK. It configures project ID, profile, continuous backup, provider settings, and termination protection. ```typescript import { CfnServerlessInstance, ServerlessInstanceProviderSettingsProviderName} from 'awscdk-resources-mongodbatlas'; const myServerlessInstance = new CfnServerlessInstance(this, 'MyServerlessInstance', { projectId: atlasProps.projId, profile: atlasProps.profile, continuousBackupEnabled: atlasProps.continuousBackupEnabled, providerSettings: { providerName: ServerlessInstanceProviderSettingsProviderName.SERVERLESS }, terminationProtectionEnabled: atlasProps.terminationProtectionEnabled }); ``` -------------------------------- ### Create MongoDB Atlas Team with AWS CDK Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/src/l1-resources/teams/README.md This TypeScript example demonstrates how to create a new team in MongoDB Atlas using the `CfnTeams` construct from the `awscdk-resources-mongodbatlas` library. It configures the team with a name, project ID, profile, role names, and associated usernames. ```typescript import { CfnTeams, CfnTeamsPropsRoleNames} from 'awscdk-resources-mongodbatlas'; const meTeam = new CfnTeams(this, 'MyTeam', { projectId: atlasProps.projId, profile: atlasProps.profile, name: atlasProps.name, roleNames: [CfnTeamsPropsRoleNames.GROUP_CLUSTER_MANAGER], usernames: [atlasProps.username] }) ``` -------------------------------- ### Example: Custom Profile Secret Configuration Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/README.md This example shows how to configure a secret for a custom profile named 'testProfile' in AWS Secrets Manager. It includes the specific SecretName 'cfn/atlas/profile/testProfile' and placeholder values for the API keys. ```yaml ProfileName: testProfile SecretName: cfn/atlas/profile/testProfile SecretValue: {"PublicKey": "YourPublicKey", "PrivateKey": "YourPrivateKey"} ``` -------------------------------- ### Example: Default Profile Secret Configuration Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/README.md This example demonstrates how to configure a secret for a default profile in AWS Secrets Manager. It specifies the ProfileName as 'default', the SecretName as 'cfn/atlas/profile/default', and provides placeholder values for PublicKey and PrivateKey. ```yaml ProfileName: default SecretName: cfn/atlas/profile/default SecretValue: {"PublicKey": "YourPublicKey", "PrivateKey": "YourPrivateKey"} ``` -------------------------------- ### Initialize CDK App with TypeScript Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/src/l3-resources/atlas-basic/README.md Initializes a new AWS CDK application with TypeScript as the language. This command sets up the basic project structure for a CDK application. ```bash cdk init app --language=typescript ``` -------------------------------- ### Validate AWS Custom DNS Configuration via GET API Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/test/l1-resources/custom-dns-configuration-cluster-aws/README.md This snippet shows how to validate if AWS custom DNS is enabled for a MongoDB Atlas project by making a GET API call. It requires the ATLAS_PROJECT_ID to be substituted with the actual project ID. ```bash https://cloud-dev.mongodb.com/api/atlas/v1.0/groups//awsCustomDNS ``` -------------------------------- ### CDK Useful Commands Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/mern-cdk-ci-cd/cdk-pipeline/README.md Common commands for managing and deploying AWS CDK applications. These include building, testing, deploying, and synthesizing CloudFormation templates. ```Bash npm run build ``` ```Bash npm run watch ``` ```Bash npm run test ``` ```Bash cdk deploy ``` ```Bash cdk diff ``` ```Bash cdk synth ``` -------------------------------- ### Create Basic MongoDB Atlas Project with AWS CDK Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/src/README.md This L3 construct (pattern) simplifies the creation of a MongoDB Atlas Project, Cluster, DB User, and configures the IP Access List. It bundles multiple resource configurations into a single pattern. ```typescript import { AtlasBasic } from '@aws-cdk/aws-cdk-resources-mongodbatlas'; // Example usage: // const basicAtlasSetup = new AtlasBasic(this, 'BasicAtlasSetup', { // projectName: 'my-atlas-project', // // cluster configuration... // // dbUser configuration... // // ipAccessList configuration... // }); ``` -------------------------------- ### Run Unit Tests for CDK Constructs Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/TESTING.md Executes unit tests for CDK constructs. The command varies slightly depending on whether the construct is L1, L2, or L3, requiring navigation to the specific test directory. ```bash # if you created an L1 resource cd test/l1-resources/[resource-folder] # if you created an L2 resource cd test/l2-resources/[resource-folder] # if you created an L3 resource cd test/l3-resources/[resource-folder] npx projen test ``` -------------------------------- ### List Network Containers (Atlas CLI) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/test/l1-resources/network-container/README.md This snippet demonstrates how to list network containers using the Atlas CLI. It shows the command to execute and an example of the expected JSON output, including details like CIDR block, ID, provider, provisioned status, and region. ```bash atlas networking container ls --projectId 641d818e36e2eb47d038f8c2 [ { "atlasCidrBlock": "10.8.2.0/24", "id": "", "providerName": "AWS", "provisioned": false, "regionName": "US_EAST_1" } ] ``` -------------------------------- ### Create a CDK Test Application Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/TESTING.md Initializes a new AWS CDK application using TypeScript and builds it. This application will be used to test the custom CDK constructs. ```bash mkdir hello-cdk cd hello-cdk cdk init app --language typescript # build the app: npm run build ``` -------------------------------- ### Create FederatedSettingsOrgRoleMapping (TypeScript) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/src/l1-resources/federated-settings-org-role-mapping/README.md Example of creating a MongoDB Atlas FederatedSettingsOrgRoleMapping using the AWS CDK in TypeScript. This code defines a role mapping with specified group name, role, and federation settings ID. ```typescript import { CfnEncryptionAtRest } from 'awscdk-resources-mongodbatlas'; const federationSettings = new CfnFederatedSettingsOrgRoleMapping(this, 'FederationSettings', { profile: atlasProps.profile, orgId: atlasProps.projId, externalGroupName: atlasProps.groupName, roleAssignments: [ { role: atlasProps.role, projectId: atlasProps.projId } ], federationSettingsId: atlasProps.federationSettingsId }); ``` -------------------------------- ### Get MongoDB Atlas AWS CDK Resources Go Package Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/README.md Retrieves the Go package for MongoDB Atlas AWS CDK Resources. This command is used to download the package for use in Go projects. ```bash go get github.com/mongodb/awscdk-resources-mongodbatlas-go/awscdkresourcesmongodbatlas ``` -------------------------------- ### Publish to PyPI Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/RELEASING.md Publishes the package to the Python Package Index (PyPI). Requires setting TWINE_USERNAME and TWINE_PASSWORD environment variables. ```bash export TWINE_USERNAME=******** export TWINE_PASSWORD=******** npx -p publib@latest publib-pypi ``` -------------------------------- ### Define MongoDB Atlas Private Endpoint (TypeScript) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/test/l1-resources/private-endpoint-aws/README.md Example of how to define a MongoDB Atlas Private Endpoint using the AWS CDK. This involves specifying the Atlas Private Endpoint resource within your CDK stack. ```typescript import * as cdk from 'aws-cdk-lib'; import * as atlas from 'cdk-resources-mongodbatlas'; interface MyStackProps extends cdk.StackProps { readonly "atlas.domain": string; readonly "atlas.project.id": string; } export class MyStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props: MyStackProps) { super(scope, id, props); new atlas.PrivateEndpoint(this, 'PrivateEndpoint', { // input parameters "atlas.domain": props."atlas.domain", "atlas.project.id": props."atlas.project.id" }); } } ``` -------------------------------- ### Define MongoDB Atlas Private Endpoint (TypeScript) Source: https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/test/l1-resources/private-endpoint/README.md Example of how to define a MongoDB Atlas Private Endpoint using the AWS CDK. This involves specifying the Atlas Private Endpoint resource within your CDK stack. ```typescript import * as cdk from 'aws-cdk-lib'; import * as atlas from 'cdk-resources-mongodbatlas'; interface MyStackProps extends cdk.StackProps { readonly "atlas.domain": string; readonly "atlas.project.id": string; } export class MyStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props: MyStackProps) { super(scope, id, props); new atlas.PrivateEndpoint(this, 'PrivateEndpoint', { // input parameters "atlas.domain": props."atlas.domain", "atlas.project.id": props."atlas.project.id" }); } } ```