Jenkins submit CloudFormation template to AWS

In this article, we will configure Jenkins to use AWS via slave nodes to deploy some CloudFormation template. Before starting to work you need to create some AWS keys with programmatic access and one key pair to connect to the Linux machine. If you want to configure Jenkins with the slave nodes please use this link.

To create ‘Access Key ID‘ and ‘Secret Access Key‘ login to AWS console and then in the IAM service create a new user with Programmatic access. Then copy to some place this keys:

Select Administrator Access:

Then press ‘Create user‘ buton.

At the end copy ‘Access key ID‘ and ‘Secret Access key‘ to keep in some secure place. In the next steps we will use them.

We need to create key pair which will be used to connect to the EC2 linux instanse. In the AWS console go to the ‘EC2‘ -> In the left side select ‘Key Pairs‘ -> Press ‘Create Key Pair‘ button and Enter name and press button to create

Then in the Jenkins console we need to configure new credentials for AWS. In the main console go to the Credentials -> Press (global) button

Then press Add Credentials button to add new credentials:

Add AWS ‘Access Key ID‘ which created before and press ‘OK‘ button:

Add AWS ‘Secret Access Key‘ which created before and press ‘OK‘ button:

Create new Project. In the main page press New Item :

Select Freestyle project -> Enter some name (in my case: DeployCloudFormationTemplate) -> Press OK button

In the opened page click in the check box ‘Restrict where this project can be run‘ and input ‘swarm‘ (It is group of slave servers) in the ‘Label Expression‘ then press ‘Apply‘button.

Then go to down in the ‘Build‘ section press ‘Add build step‘ and select ‘Execute shell‘ :

In the opened command place enter the following command and press ‘Apply‘ button. This command will download template file with parameters which will select instance type, KeyPair name and our Public IP to give as parameter to open in the Firewall(it is for SSH access):

$ aws cloudformation create-stack --stack-name JenkinsToAWSDeploy --template-url --parameters ParameterKey=InstanceType,ParameterValue=t2.micro ParameterKey=KeyName,ParameterValue=fromJenkinstoAWS ParameterKey=SSHLocation,ParameterValue=$(curl -s


In the ‘Build Environment‘ section select ‘Use secret text(s) or file(s)

In the opened ‘Bindings‘ section press ‘Add‘ and ‘Secret text‘ button (This step must be repeated for ‘Access Key ID‘, ‘Secret Access Key‘)

Add new variables for ‘Access Key ID‘ and ‘Secret Access Key‘ and press ‘Apply‘ button:

Go to the up in the ‘General‘ tab and select checkbox ‘This project is parameterized‘ -> Press ‘Add Parameter‘ -> ‘String Parameter

Input parameter name, value and description and then press ‘Apply‘ and ‘Save‘ button:

Press ‘Build with Parameters‘ -> then ‘Build‘ button

Press little icon in down at the left side to see the log output:

Look at the result:

Look to the CloudFormation status in the AWS side:

Go to the EC2 instance and take the name of linux instance. We will use this name to connect to out Linux machine.

From GitBash console try to login to the Linux instance with key which created before:

$ ssh -i fromJenkinstoAWS.pem



2 thoughts on “Jenkins submit CloudFormation template to AWS

  1. Hi jamal was follow your procedure build aws cf through jenkins,however i got ended with below error-

    “Creating Cloud Formation stack: drupalstack
    Failed to create stack: drupalstack. Reason: Detailed Message: Parameters: [SiteEMail] must have values (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 46896b4a-f860-11e8-bc69-51652643d6ff)
    Status Code: 400
    Error Code: ValidationError”

    P.S-kindly suggest what went wrong as per above error so that i can fix the same.

    can you please help me to send the steps to build cf stack from jenkins ,i have the templete link-


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s