Start EC2 instance

    0

    1

    AWS and boto3 recipes for Python

    When this line of code is executed, the DryRun flag is set to True, which tells the code to run the command without actually starting any instances. If an error occurs while trying to start instances, an exception is raised and the code prints out the error.

    Library: boto3

    import sys
    import boto3
    from botocore.exceptions import ClientError
    
    try:
      # Add DryRun first if you want to check the operation can be done
      response = ec2.start_instances(InstanceIds=[instanceid], DryRun=False)
      print(response)
    except ClientError as e:
      logging.info("Cannot start EC2 instance")
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.