[Python] aws lambda python function to reboot ec2 instances not working

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Lambda function to reboot instances:

    import boto3
    region = 'us-east-1'
    instances = ['i-xxxxxxxxxxxxxxxxxxxxxxxxxx']
    ec2 = boto3.client('ec2', region_name=region)

    def lambda_handler(event, context):
    response = ec2.reboot_instances(
    InstanceIds=[
    'i-xxxxxxxxxxxxxxxxxxxxxx',
    ],
    )
    print(response)


    It just refuses to work.

    The response when I trigger it:


    {'ResponseMetadata': {'RequestId': '12994c92-98ab-4b62-bc10-a0e0b4881aaa', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '12994c92-98ab-4b62-bc10-a0e0b4881aaa', 'content-type': 'text/xml;charset=UTF-8', 'content-length': '231', 'date': 'Sun, 30 Aug 2020 15:44:40 GMT', 'server': 'AmazonEC2'}, 'RetryAttempts': 0}}
    ​

    The interesting part: if I change ec2.reboot_instances to ec2.start_instances then it works.

    So I am trying to find out why would a reboot command be refused and a start/stop command be accepted?

    Note: I included the permission in IAM to reboot instances. The instance is a linux openvpn server AMI bundle

    Continue reading...

Compartilhe esta Página