Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[DocumentDB] Install MongoDB on AWS Cloud

Posted on April 25, 2024November 15, 2024 By nim No Comments on [DocumentDB] Install MongoDB on AWS Cloud

Contents

Toggle
  • Introduce DocumentDB.
  • Provisioning DocumentDB by Terraform.
  • DocumentDB Terraform module

Introduce DocumentDB.

DocumentDB mongoDB.

  • Aurora is an “AWS-implementation” of PostgreSQL/MYSQL…
  • DocumentDB is the same for MongoDB (which is a NoSQL database)
  • MongoDB is used to store, query, and index JSON data
  • Similar “deployment concepts” as Aurora
  • Fully Managed, highly available with replication across 3 AZ Aurora storage automatically grows in increments of 10GB, up to 64 TB.
  • Automatically scales to workloads with millions of requests per seconds1

Provisioning DocumentDB by Terraform.

để provision DocumentDB chúng ta chủ yếu tìm hiểu 2 resources này:
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/docdb_cluster
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/docdb_cluster_instance

chúng ta sẽ tìm hiểu 1 số value cần thiết thông qua config bên dưới:

resource "aws_docdb_cluster" "default" {
  count                           = module.this.enabled ? 1 : 0
  cluster_identifier              = module.this.id
  master_username                 = var.master_username
  master_password                 = var.master_password != "" ? var.master_password : random_password.password[0].result
  backup_retention_period         = var.retention_period
  preferred_backup_window         = var.preferred_backup_window
  preferred_maintenance_window    = var.preferred_maintenance_window
  final_snapshot_identifier       = lower(module.this.id)
  skip_final_snapshot             = var.skip_final_snapshot
  deletion_protection             = var.deletion_protection
  apply_immediately               = var.apply_immediately
  storage_encrypted               = var.storage_encrypted
  storage_type                    = var.storage_type
  kms_key_id                      = var.kms_key_id
  port                            = var.db_port
  snapshot_identifier             = var.snapshot_identifier
  vpc_security_group_ids          = concat([join("", aws_security_group.default[*].id)], var.external_security_group_id_list)
  db_subnet_group_name            = join("", aws_docdb_subnet_group.default[*].name)
  db_cluster_parameter_group_name = join("", aws_docdb_cluster_parameter_group.default[*].name)
  engine                          = var.engine
  engine_version                  = var.engine_version
  enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports
  tags                            = module.this.tags
}

cluster_identifier: This is the name you give to your DocumentDB cluster for identification
backup_retention_period: (Optional) parameter in the context of configuring an AWS DocumentDB cluster (or other database services) is crucial for defining how long your backups are retained (stored) before being automatically deleted. Default 1
preferred_backup_window: (Optional) specifies the daily time window during which automated backups are initiated, follows the format hh24:mi-hh24:mi.
– For example, 03:00-06:00 indicates a backup window that starts at 3:00 AM UTC and ends at 6:00 AM UTC.
– Time in UTC Default: A 30-minute window selected at random from an 8-hour block of time per regionE.g., 04:00-09:00
preferred_maintenance_window: (Optional) The weekly time range during which system maintenance can occur, in (UTC) e.g., wed:04:00-wed:04:30

skip_final_snapshot: (Optional) If set to true, no final snapshot is taken when the cluster is deleted. This can be risky because you won’t have a backup of your last state
final_snapshot_identifier: (Optional) A final snapshot is taken for backup before deleting the cluster. This setting specifies the name for that snapshot, which is set to a lowercase version of the cluster identifier.

deletion_protection: (Optional) If true, the cluster cannot be deleted, which helps prevent accidental loss of data. By default, deletion protection is disabled

apply_immediately: (Optional) Determines whether changes are applied immediately or during the next maintenance window. Default is false.

storage_encrypted: (Optional) When set to true, your data at rest in the cluster is encrypted. The default is false
storage_type: These settings configure the storage type. Valid values: standard, iopt1.
kms_key_id: (Optional) The ARN for the KMS encryption key. When specifying kms_key_id, storage_encrypted needs to be set to true.
port: (Optional) The port on which the DB accepts connections
snapshot_identifier: If specified, the cluster is created from this snapshot, effectively cloning or restoring from a backup.

Sau khi provisioning resource trên bạn sẽ được như dưới hình:

Sau khi chúng ta provisioning được con controller thì chúng ta tiếp tục provision các con instance:

resource "aws_docdb_cluster_instance" "default" {
 count                        = var.cluster_size
 identifier                   = "${var.cluster_name}-${count.index + 1}"
 cluster_identifier           = join("", aws_docdb_cluster.default[*].id)
 apply_immediately            = var.apply_immediately
 preferred_maintenance_window = var.preferred_maintenance_window
 instance_class               = var.instance_type
 engine                       = var.engine_db
 auto_minor_version_upgrade   = var.auto_minor_version_upgrade
 enable_performance_insights  = var.enable_performance_insights
 ca_cert_identifier           = var.ca_cert_identifier

}

identifier: Defines a unique identifier (name) for each cluster instance
instance_class: The instance class to use. For more details, see https://docs.aws.amazon.com/documentdb/latest/developerguide/db-instance-classes.html#db-instance-class-specs
engine: The name of the database engine to be used for this DB cluster. Defaults to `docdb`
enable_performance_insights: (Optional) A value that indicates whether to enable Performance Insights for the DB Instance. Default false. See docs about the details.

sau khi bạn tạo xong kết quả như bên dưới:

Có một chỗ này khi mình sài navicat:

với hướng dẫn của AWS thì chúng ta phải sài file .pem

mongodb://txxxxn:<insertYourPassword>@mongodb.cluster-xxxxxx.us-west-2.docdb.amazonaws.com:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false

Bạn có sài URL như thế này không cần file .pem
ssl=true là ok

mongodb://<username>:<pass_word>@mongodb.cluster-xxxxx.us-west-2.docdb.amazonaws.com:27017/?ssl=true&authSource=admin&tlsAllowInvalidCertificates=true&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false

DocumentDB Terraform module

https://registry.terraform.io/modules/mrnim94/documentdb-mongodb/aws/latest

data "aws_vpc" "selected" {
  tags = {
    Name = "dev-mdcl-nim-engine" # Replace with your VPC's tag name
  }
}

data "aws_subnets" "private_networks" {
  filter {
    name   = "vpc-id"
    values = [data.aws_vpc.selected.id]
  }

  filter {
    name   = "tag:kubernetes.io/role/internal-elb"
    values = ["1"]
  }
}


module "documentdb-mongodb" {
  source  = "mrnim94/documentdb-mongodb/aws"
  version = "0.0.8"
  vpc_id = data.aws_vpc.selected.id
  subnet_ids = data.aws_subnets.private_networks.ids
  cluster_name = "mongodb"
  engine_version = "5.0.0"
  cluster_family = "docdb5.0"
  allow_major_version_upgrade = true
  retention_period = 35
  instance_type = "db.t3.medium"
  cluster_size = 1
  allowed_cidr_blocks = [data.aws_vpc.selected.cidr_block,"10.195.8.0/21"]
}
AWS - Amazon Web Service

Post navigation

Previous Post: Gỡ lỗi chia sẻ link URL qua zalo, facebook…
Next Post: [Navicat] For development only

More Related Articles

[EKS windows] Using EKS terraform module to install K8S windows with manage node Group mode. AWS - Amazon Web Service
[MongoDB] Creating MongoDB Atlas to integrate with your workload on any Cloud AWS - Amazon Web Service
[Golang / EKS] Accessing AWS EKS with Go: A Comprehensive Guide to Interacting with Kubernetes APIs AWS - Amazon Web Service
[Github-Action] Let’s use GitHub Action to build and push the docker image to the docker hub. AWS - Amazon Web Service
[Karpenter] Using Karpenter instead of Autoscaling Group. AWS - Amazon Web Service
[AWS] Pull images from ECR AWS - Amazon Web Service

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Laravel] Laravel Helpful June 26, 2025
  • [VScode] Hướng dẫn điều chỉnh font cho terminal June 20, 2025
  • [WordPress] Hướng dấn gửi mail trên WordPress thông qua gmail. June 15, 2025
  • [Bitbucket] Git Clone/Pull/Push with Bitbucket through API Token. June 12, 2025
  • [Teamcity] How to transfer the value from pipeline A to pipeline B June 9, 2025

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.