Need help with - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Need help with (/thread-39591.html) |
Need help with - hrp2030 - Mar-13-2023 Need help. trying to set below parameters with code listed below but throwing error. can you help me what is the correct syntax for condition listed below for EBS volume size. thank you ============================CODE ------ for volume in volumes: VolumeId = volume['VolumeId'] VolumeType = volume['VolumeType'] Size = volume['Size'] IOP = volume['Iops'] try: if VolumeType == 'gp2' or VolumeType == 'io1' and VolumeSize<=250: modify = client.modify_volume(VolumeId=VolumeId,VolumeType='gp3',IOPS='3000','Throughput=125',DryRun=DryRun) print(f"{VolumeId} changed to gp3") else: print(f"{VolumeId} does not fit criteria") except botocore.exceptions.ClientError as error: print(error) if VolumeType == 'gp2' or VolumeType == 'io1' and VolumeSize>=250 and =<1000: modify = client.modify_volume(VolumeId=VolumeId,VolumeType='gp3',IOPS='3000','Throughput=250',DryRun=DryRun) print(f"{VolumeId} changed to gp3") else: print(f"{VolumeId} does not fit criteria") except botocore.exceptions.ClientError as error: print(error) RE: Need help with - deanhystad - Mar-15-2023 "and <= 1000" is not valid Python. If testing that number is in a rande use 250 <= VolumeSize <= 1000 Should 'Throughput = 250' have the quotes removred? I don't see where you assign a value to DryRun. May be more errors. You should post your error message. I aso think you have some logic errors, or at least confusing logic. Is volume == 500 a valid crireria or not? if volume_type in ('iol', ,gp1'): try: If volume_size <= 250: # do <= 250 stuff elif volume_size <= 1000; # do 250 < x <= 1000 stuff else: print(volume_id, 'does not fit criteria') excrpt botcore.exceptions.ClientError as e: Print(e) |