Python 创建amazon ec2实例无法分配给操作员错误boto3

Python 创建amazon ec2实例无法分配给操作员错误boto3,python,python-3.x,amazon-web-services,amazon-ec2,boto3,Python,Python 3.x,Amazon Web Services,Amazon Ec2,Boto3,我试图在AmazonEC2上创建两个linux实例,有一个实例是我用脚本启动的 import sys import boto3 instance_id = "i-03e7f6391a0f523ee" action = 'ON' ec2 = boto3.client('ec2') if action == 'ON': response = ec2.start_instances(InstanceIds=[instance_id], DryRun=False) x2=boto3.

我试图在AmazonEC2上创建两个linux实例,有一个实例是我用脚本启动的

import sys
import boto3


instance_id = "i-03e7f6391a0f523ee"
action = 'ON'

ec2 = boto3.client('ec2')

if action == 'ON':
   response = ec2.start_instances(InstanceIds=[instance_id], DryRun=False)
   x2=boto3.resource('ec2')
   instance=x2.Instance(instance_id)
   foo=instance.wait_until_running('self',Filters=[{'Name':'instance-state-name','Values':['running']}])
   print ("instance is now running")
else:
    response = ec2.stop_instances(InstanceIds=[instance_id], DryRun=False)
print(response)

ec2 = boto3.resource('ec2', region_name="ap-south-1")
ami-ImageId="ami-00b6a8a2bd28daf19"
#creating instances
ec2.create_instances(ImageId=ami-ImageId,MinCount=1,MaxCount=2,KeyName="datastructutre key",InstanceType="t2.micro")
#using filter to retrive instance status
instances = ec2.instances.filter(Filters=[{'Name': 'instance-state-name', 'Values': ['running']}])
for instance in instances:
    print(instance.id, instance.instance_type)
#Checking health status of instances
for status in ec2.meta.client.describe_instance_status()['InstanceStatuses']:
    print(status)
但是这条线

ami-ImageId="ami-00b6a8a2bd28daf19"
是给我错误而不是双引号我也试过单引号

ami-ImageId='ami-00b6a8a2bd28daf19'
但在这两种情况下,错误是相同的,错误是

Syntax error: can't assign to operator

以这种方式分配ami id的错误是什么?它是分配给变量的普通字符串。

问题不在分配中。它在变量名中。ami ImageId中的-是一个运算符。使用不同的变量名,例如ami_ImageId

表达式ami ImageId是ami和ImageId变量的减法,但不是正确的单个变量名。例如,使用ami_ImageId正确的名称