【发布时间】:2022-02-15 01:14:52
【问题描述】:
知道如何修改它以将实例 ID 作为参数传递而不是将其放入脚本中吗?
import boto3
def stop_instance(instance_id):
ec2 = boto3.client("ec2", region_name="us-west-1")
response = ec2.stop_instances(InstanceIds=[instance_id])
print(response)
stop_instance()
【问题讨论】:
-
添加command line parsing,例如使用 argparse 或单击。
-
如果你想从命令行停止一个实例,你可以使用AWS Command-Line Interface (CLI)命令:
aws ec2 stop-instances --instance-ids <instance-id> -
我想用python。事实上我只想有一个脚本来启动和停止实例
标签: amazon-web-services amazon-ec2 boto3