使用Clioupformation在AWS上创建Amazon DocumentDB(MongoDB)数据库
本文帮助用户使用CloudFormation模板使用单个主实例创建文档数据库群集。
当用户想要在AWS(Amazon Web服务)上运行Mongo数据库工作负载时,文档数据库很重要。
Amazon DocumentDB(具有MongoDB兼容性)是一个可扩展,完全托管,快速且高度可用的文档数据库服务,支持MongoDB工作负载。
此托管的非关系数据库服务使得存储,查询和索引JSON数据更容易。
此数据库服务是从上占设计的,以保证在规模上操作任务关键的MongoDB工作负载时所需的可伸缩性,性能和可用性。
使用CloudFormation模板
请找到下面的CloudFormation模板。
模板将创建:数据库实例安全组.Database子网组。
数据库参数组.Document数据库Cluster.database实例。
-- AWSTemplateFormatVersion: "2010-09-09" Description: Template to Create a document DB parameter group, subnet group and cluster Parameters: VPC: Type: String Description: The VPC to create the cluster Default: vpc-ID PrivateSubnet01: Type: String Description: The subnet for the DB cluster Default: subnet-ID PrivateSubnet02: Type: String Description: The subnet for the DB cluster Default: subnet-ID MasterUsername: Type: String Description: The username for our database. MasterUserPassword: Type: String Description: The password for the database. "NoEcho": true Resources: DBSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: "DB instances security group" GroupName: "test-db-instance-SG" VpcId: !Ref VPC SecurityGroupIngress: - CidrIp: "*.*.*.*/32" FromPort: 22016 IpProtocol: "tcp" ToPort: 22016 SecurityGroupEgress: - CidrIp: "0.0.0.0/0" IpProtocol: "-1" DBSubnetGroup: Type: AWS::DocDB::DBSubnetGroup Properties: DBSubnetGroupDescription: "test document db subnet group" DBSubnetGroupName: "eu-central-1-test-db-subnet-group" SubnetIds: - !Ref PrivateSubnet01 - !Ref PrivateSubnet02 Tags: - Key: Name Value: eu-central-1-test-db-subnet-group - Key: createdBy Value: Maureen Barasa - Key: Project Value: test-blog - Key: Environment Value: test DBParameterGroup: Type: AWS::DocDB::DBClusterParameterGroup Properties: Description: "our test document db parameter group" Family: docdb3.6 Name: test-db-parameter-group Parameters: audit_logs: "disabled" tls: "enabled" ttl_monitor: "enabled" Tags: - Key: Name Value: eu-central-1-test-db-cluster - Key: createdBy Value: Maureen Barasa - Key: Project Value: test-blog - Key: Environment Value: test DBCluster: Type: AWS::DocDB::DBCluster Properties: BackupRetentionPeriod : 5 DBClusterIdentifier : eu-central-1-test-db-cluster DBClusterParameterGroupName : !Ref DBParameterGroup DBSubnetGroupName : !Ref DBSubnetGroup MasterUsername : !Ref MasterUsername MasterUserPassword : !Ref MasterUserPassword Port : "27017" PreferredBackupWindow : "23:00-23:59" PreferredMaintenanceWindow : "sun:00:00-sun:05:00" VpcSecurityGroupIds: - !Ref DBSecurityGroup StorageEncrypted : true Tags: - Key: Name Value: eu-central-1-test-db-cluster - Key: createdBy Value: Maureen Barasa - Key: Project Value: test-blog - Key: Environment Value: test DBInstance: Type: AWS::DocDB::DBInstance Properties: AutoMinorVersionUpgrade: true AvailabilityZone: "eu-west-1a" DBClusterIdentifier: !Ref DBCluster DBInstanceClass: "db.t3.medium" DBInstanceIdentifier: "test-cluster-instance-1" PreferredMaintenanceWindow: "sun:00:00-sun:05:00" Tags: - Key: Name Value: eu-central-1-test-db-instance - Key: createdBy Value: Maureen Barasa - Key: Project Value: test-blog - Key: Environment Value: test Outputs: Cluster: Description: The DB Cluster Name Value: !Ref DBCluster SubnetGroup: Description: The db subnet group name Value: !Ref DBSubnetGroup ParameterGroup: Description: The db subnet group name Value: !Ref DBParameterGroup
我们可以使用CloudFormation Stack部署CloudFormation模板。
模板解释说明
模板包含3个部分。
参数,资源和输出部分。
参数:
在"资源"部分中,我们要求用户输入其模板的动态变量。
对于我们的情况,用户应使用各自的VPC和子网ID替换VPC和子网ID。
此外,系统将提示用户输入其数据库主用户名和密码。
请确保我们不使用管理员作为主用户名。
资源:
其中用户定义了要创建的AWS资源。
对于我们的情况,我们首先创建数据库实例安全组。
用户应该更改安全组入口以反映他们希望访问数据库实例的CIDR IP块.Next,它创建了DB子网和参数组。
子网组定义了创建数据库群集和实例的子网。
参数组允许我们管理数据库引擎配置。
用户应该通过参数组属性并更改为特定要求。
此外,用户应注意根据需要进行自定义的名称和标记。
然后创建文档数据库群集。
就像上面一样,用户应该通过所有群集属性并更改它们以匹配它们的要求。
最后,创建数据库实例。
但是,用户应该通过模板,更改可用性区域,实例类以及首选维护需要匹配其特定需求。
此外,应自定义数据库实例标识符和标签以满足用户要求。
输出:
模板的输出部分指示CloudFormation输出所创建的资源的名称。
例如,在我们的情况下,我们指示模板输出群集,子网和参数组的名称。