A developer provisions an ECS instance with proper security group rules to allow database connectivity, creates an RDS instance for the application backend, and sets up database accounts with appropriate permissions so the application can securely connect to the database.
When deploying a web application backend that requires persistent relational storage, developers must provision an ECS compute instance alongside an ApsaraDB RDS instance, then securely bridge them via VPC networking and least-privilege database accounts. This workflow ensures the application can authenticate and query the database without exposing credentials or ports to the public internet.
``bash aliyun ecs AuthorizeSecurityGroup --SecurityGroupId sg-xxx --IpProtocol tcp --PortRange 3306/3306 --SourceCidrIp 10.0.0.0/24 ``
``bash aliyun rds CreateDBInstance --Engine MySQL --EngineVersion 8.0 --DBInstanceClass rds.mysql.s2.large --VPCId vpc-xxx --VSwitchId vsw-xxx --SecurityIPList 10.0.0.0/24 ``
rds-manage-accounts).``bash aliyun rds CreateAccount --DBInstanceId rm-xxx --AccountName app_user --AccountPassword 'SecurePass123!' --AccountType Normal ``
``bash aliyun rds GrantAccountPrivilege --DBInstanceId rm-xxx --AccountName app_user --DBName app_db --AccountPrivilege ReadWrite ``
``bash aliyun ecs RunInstances --InstanceType ecs.t6-c1m2.large --ImageId aliyun_3_x64_20G_alibase_20230920.vhd --VSwitchId vsw-xxx --SecurityGroupId sg-xxx --InstanceName web-backend ``
``bash export DB_HOST=rm-xxx.mysql.rds.aliyuncs.com export DB_PORT=3306 export DB_USER=app_user export DB_PASS='SecurePass123!' ``
``bash nc -zv $DB_HOST $DB_PORT && mysql -h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASS -e "SELECT 1;" ``
The ECS instance runs the application runtime and acts as the database client. All traffic flows over the private VPC network to the RDS endpoint, which handles query execution, connection pooling, and automated backups. Security groups enforce network-layer isolation, while RDS account privileges enforce application-layer data access control.
aliyun) installed and authenticated with an AccessKey pairSecurityIPList: Setting 0.0.0.0/0 on RDS exposes the database to the internet. Always restrict to the ECS security group CIDR.GrantAccountPrivilege: Creating an account without explicitly granting schema access results in Access denied errors at runtime.