Search code examples
jenkinsamazon-ec2virtual-machine

How do I start an Amazon EC2 VM from a saved AMI using Jenkins?


I'm trying to create a Jenkins job to spin up a VM on Amazon EC2 based on an AMI that I currently have saved. I've done my searching and can't find an easy way to do this other than through Amazon's GUI. This isn't very ideal as there are a lot of manual steps involved and it's time-consuming.

If anyone's had any luck doing this or could point me in the right direction that would be great.


Solution

  • Unless I'm misunderstanding the question this should be possible using the cli, assuming you can install and configure the cli on your jenkins server you can just run the command as a shell script as part of the build.

    Create an instance with CLI.

    The command would be something along the lines of:

    [path to cli]/aws ec2 run-instances --image-id ami-xyz 
    

    If your setup is too complicated for a single cli command, I would recommend creating a simple cloudformation template.

    If you are unable to install the cli, you could use any number of sdk's e.g. java to make a simple application you could run with jenkins.