AWS Certified Developer – Associate — Question 105
A developer is creating a command line script to launch an Amazon EC2 instance at a preset time with a cron job. The developer will provide a user data script to start a task and then terminate the instance. The task cannot be interrupted and must run to completion.
How should the developer launch the EC2 instance?
Answer options
- A. Use the ec2 start-instances command.
- B. Use the ec2 request-spot-instances command.
- C. Use the ec2 run-instances command.
- D. Use the ec2 purchase-scheduled-instances command.
Correct answer: C
Explanation
The correct answer is C, as the ec2 run-instances command is specifically designed to launch new EC2 instances, which is necessary for the developer's requirement to start a task. Option A is incorrect because ec2 start-instances is used to start instances that are already in a stopped state, not to create new ones. Option B is not suitable since ec2 request-spot-instances is for requesting spot instances, which may be terminated by AWS at any time, contradicting the need for uninterrupted task execution. Option D is irrelevant as ec2 purchase-scheduled-instances is used for scheduling instances in advance but does not apply to immediate launches.