Stop EC2 instance

    0

    7

    AWS and boto3 recipes for Python

    The code tries to stop the specified EC2 instances. If the instances aren't stopped, the code prints an error and terminates.

    Library: boto3

    import boto3
    from botocore.exceptions import ClientError
    
    try:
      response = ec2.stop_instances(InstanceIds=[instanceid], DryRun=False)
      print(response)
    except ClientError as e:
      logging.error("Cannot stop EC2 instance")
      print(e)
    
    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.