In this tutorial you will learn how to Stop and Start AWS Ec2 instance from Jenkins
Steps:1
Create an IAM User with Acess and Secret Key
Steps:2
Create an IAM policy
{
"Version":
"2012-10-17",
"Statement":
[
{
"Sid":
"VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:StartInstances",
"ec2:StopInstances"
],
"Resource": "*"
}
]
}
Step: 3
Assing IAM policy to IAM user
Steps: 4
Configure IAM Access and Secret in Jenkins Server
Install package on
Ubuntu Server
$ sudo apt-get
install awscli
# sudo su –
jenkins
$ aws configure
Steps: 5
Create Jenkins Job to start and Stop Ec2 instance
Step: 6 Create
Write Shell script in Build Step
Write Shell script in Shell Excute
if [ "$State"
= "Start" ]
then
aws ec2
start-instances --instance-ids $InstanceID
echo Instance
$InstanceID Started
elif [ "$State"
= "Stop" ]
then
aws ec2
stop-instances --instance-ids $InstanceID
echo Instance
$InstanceID Stopped
fi
Steps: 7 Now Start your Jenkins Build to Stop and Start Ec2 Instance
0 comments:
Post a Comment