云服务器(Elastic Compute Service, ECS)是一种弹性可扩展的计算服务,用户可以根据需求快速创建、管理和释放服务器实例。ECS提供了弹性的计算资源,支持多种操作系统和应用程序,适用于各种规模的企业和个人开发者。
以下是一个简单的示例代码,展示如何在腾讯云上创建一个ECS实例:
import tencentcloud.common.credentials
import tencentcloud.common.profile.client_profile
import tencentcloud.common.profile.http_profile
import tencentcloud.cvm.v20170312.cvm_client
def create_instance():
cred = tencentcloud.common.credentials.Credential("YOUR_SECRET_ID", "YOUR_SECRET_KEY")
httpProfile = tencentcloud.common.profile.http_profile.HttpProfile()
httpProfile.endpoint = "cvm.tencentcloudapi.com"
clientProfile = tencentcloud.common.profile.client_profile.ClientProfile()
clientProfile.httpProfile = httpProfile
client = tencentcloud.cvm.v20170312.cvm_client.CvmClient(cred, "ap-guangzhou", clientProfile)
req = tencentcloud.cvm.v20170312.models.RunInstancesRequest()
params = {
"ImageId": "img-xxxxxx",
"InstanceType": "S2.SMALL1",
"InstanceChargeType": "POSTPAID_BY_HOUR",
"InternetAccessible": {
"InternetMaxBandwidthOut": 1,
"PublicIpAssigned": True
},
"Placement": {
"Zone": "ap-guangzhou-2"
},
"SecurityGroupIds": ["sg-xxxxxx"],
"SystemDisk": {
"DiskType": "CLOUD_PREMIUM",
"DiskSize": 50
},
"VirtualPrivateCloud": {
"VpcId": "vpc-xxxxxx",
"SubnetId": "subnet-xxxxxx"
}
}
req.from_json_string(params)
resp = client.RunInstances(req)
print(resp.to_json_string(indent=2))
if __name__ == "__main__":
create_instance()
领取专属 10元无门槛券
手把手带您无忧上云