I’m running Python code on an instance and I’m trying to start an EC2 instance using boto3 start_instances
. The code works and gives the following response:
Response: {'StartingInstances': [{'CurrentState': {'Code': 0, 'Name': 'pending'}, 'InstanceId': 'i-<id>', 'PreviousState': {'Code': 80, 'Name': 'stopped'}}], [..]
But in the UI it’s not up, not even pending. I’ve run the code 7 times and its the same thing. To make a test, I tried the opposite: I started the instance using the UI and used the stop_instances
function and it worked!
The permissions are these:
"ec2:StartInstances",
"ec2:StopInstances"
What might be happening?
2
Answers
The problem was that the instance that I was trying to start have an encrypted EBS volume. Then, it is necessary to give some KMS permissions, I found them here: https://nqbao.medium.com/aws-correct-permission-to-start-an-ec2-instance-with-encrypted-ebs-507933c01511
It is weird that the console don't show an error in this case.
The Python code I am using works fine. It creates an EC2 instance that shows up in the AWS Management Console. Here is output in PyCharm.
Here is instance in the Console
Python code is:
Make sure you enter a valid ID value in the above code.
Try that code and you will see the instance in the console. Set a break point after you start it.