![](/img/trans.png)
[英]key error while creating autoscaling group amazon ec2 using boto3
[英]creating amazon ec2 instance can't assign to operator error boto3
我正在嘗試在Amazon EC2上創建2個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正確的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.