I want to allow users to start an EC2 instance only when necessary.
So, I created a Lambda function for this:
import boto3 def lambda_handler(event, context): ec2 = boto3.resource('ec2', region_name='eu-central-1') return ec2.instances.filter(InstanceIds=['i-abc123']).start()
I also added the following IAM permissions:
{ "Effect": "Allow", "Action": [ "ec2:StartInstances" ], "Resource": "arn:aws:ec2:*" }, { "Effect": "Allow", "Action": [ "ec2:DescribeInstances" ], "Resource": "*" }
The problem is that when I run Lambda I get a timeout.
BTW runs the same code from EC2 within the same VPC and the same permissions, returns immediately.
Any idea?
source share