Ruta Borkar
Ruta Borkar

Reputation: 41

How to create an EC2 Instance using Jenkinsfile

I want to create an EC2 AWS instance using Jenkins pipeline. Do I need to do it through Cloud Formation Json file

Upvotes: 0

Views: 2949

Answers (2)

Shawn
Shawn

Reputation: 9402

You have many options, so no, you don't need to use CloudFormation. While you don't need to use CloudFormation, it is good practice to build infrastructure-as-code, and CloudFormation gives that option very nicely. It also useful for future updates and if you find you need other types of resources, which you likely will.

I recommend you use the AWS Steps Jenkins plugin and use something like cfnUpdate to create/update a CloudFormation stack. See https://plugins.jenkins.io/pipeline-aws/ for more details on the capabilities this Jenkins plugin gives. Doing it with this plugin makes your code Jenkinsfile code so you don't need to add another flavor of code/script.

Upvotes: 2

Hiteshwar Sharma
Hiteshwar Sharma

Reputation: 191

Its very easy by using shell kind of build step as :-

You can install awscli on your Jenkins server and create instance with a simple shell script inside your Jenkins job as:

aws ec2 run-instances --image-id ami-abc

you can also parametrise it by defining bunch of parameters in Job and using them as:

aws ec2 run-instances --image-id $ami --instance-type $type --ssh-key-name $key 

to install aws cli and to configure it follow aws's official documentation here:

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

Upvotes: 1

Related Questions