How solve Pyhton getting invalid syntax error

Viewed 28

I'm trying typing

command = "aws ec2 describe-instances --query "Reservations[*].Instances[].{ instance_id: InstanceId, type: InstanceType, stats: State.Name, disks: BlockDeviceMappings[*].Ebs.VolumeId, p_ip: NetworkInterfaces[*].PrivateIpAddresses[].PrivateIpAddress, name: Tags[?Key == `Name`].Value, cpu: CpuOptions.CoreCount, platform: PlatformDetails}" > output.json"
os.system(command)

I got an error when debbuging. Is there anyone correct this syntax.

1 Answers

You have to escape the double quotes:

command = "aws ec2 describe-instances --query \"Reservations[*].Instances[].{ instance_id: InstanceId, type: InstanceType, stats: State.Name, disks: BlockDeviceMappings[*].Ebs.VolumeId, p_ip: NetworkInterfaces[*].PrivateIpAddresses[].PrivateIpAddress, name: Tags[?Key == `Name`].Value, cpu: CpuOptions.CoreCount, platform: PlatformDetails}\" > out22.json"
os.system(command)
Related