MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / start

Method start

python/example_code/ec2/instance.py:191–217  ·  view source on GitHub ↗

Starts instances and waits for them to be in a running state. :return: The response to the start request.

(self)

Source from the content-addressed store, hash-verified

189
190 # snippet-start:[python.example_code.ec2.StartInstances]
191 def start(self) -> Optional[Dict[str, Any]]:
192 """
193 Starts instances and waits for them to be in a running state.
194
195 :return: The response to the start request.
196 """
197 if not self.instances:
198 logger.info("No instances to start.")
199 return None
200
201 instance_ids = [instance["InstanceId"] for instance in self.instances]
202 try:
203 start_response = self.ec2_client.start_instances(InstanceIds=instance_ids)
204 waiter = self.ec2_client.get_waiter("instance_running")
205 waiter.wait(InstanceIds=instance_ids)
206 return start_response
207 except ClientError as err:
208 logger.error(
209 f"Failed to start instance(s): {','.join(map(str, instance_ids))}"
210 )
211 error_code = err.response["Error"]["Code"]
212 if error_code == "IncorrectInstanceState":
213 logger.error(
214 "Couldn't start instance(s) because they are in an incorrect state. "
215 "Ensure the instances are in a stopped state before starting them."
216 )
217 raise
218
219 # snippet-end:[python.example_code.ec2.StartInstances]
220

Callers 9

recursive_queryMethod · 0.45
infinite_infer_runFunction · 0.45
publish_basic_messageFunction · 0.45
inferFunction · 0.45
extractMethod · 0.45

Calls 2

joinMethod · 0.80
waitMethod · 0.45

Tested by

no test coverage detected