Jira Ticket To Upgrade Instance

Before starting with this guide, follow all steps given here

  1. Open a filter node, and select the input as data from the Resource Node. We will filter out only the EC2 instances that we've received from the Jira Ticket.

    • Select Tags as the filter type

    • Select condition as Has.

    • Enter $.<CustomNodeID>.data.InstanceTagKey as the Key and $.<CustomNodeID>.data.InstanceTagValue as Value (referring to the first custom node in the workflow)

      • Eg. Key: $.node-38d67602-custom.data.InstanceTagKey; Value: $.node-38d67602-custom.data.InstanceTagValue

    • Click Add Condition, and select Param as filter type

      • Set Key as '$.State..Name', Operator as '==' and Value as 'running'

    • Click Save

2. Add a Custom Node. We will use this to mention the order in which to upgrade instances.

  • Select the output of the Filter Node from the drop-down

  • Select custom as predefined logic

  • Paste the following code under Enter custom code:

function upgradeEc2Instances(instanceType)
{
const sizes = ["nano", "micro", "small", "medium", "large", "xlarge", "2xlarge"]
let splitInstanceType= instanceType.split(".")
let indexOfLargerSize= sizes.indexOf(splitInstanceType[1])
let largerSize = sizes[indexOfLargerSize+1]
let upgradedInstance = splitInstanceType[0]+"."+largerSize
return upgradedInstance
}
async function process(){
let {collection,region} = context;
let result = [];
for(let i = 0;i< collection.length; i++){
const instance = collection[i];
const instanceType = instance.InstanceType
const nextInstanceType= upgradeEc2Instances(instanceType);
print(nextInstanceType);
result.push({...instance, nextInstanceType: nextInstanceType});
}
exit(null,result)
}
process().catch(exit);

3. Add an Action Node. We will use this to stop the instances before changing the instance type.

  • Select the output of the second Custom Node from the drop-down

  • Select EC2 as service and Stop Instances as action

  • Check the box Wait for stopInstances to finish

  • Click Save

4. Add another Action Node. We will use this to change the instance type.

  • Select the output of the second Custom Node from the drop-down

  • Select EC2 as service and Modify Instance Attribute as action

  • Paste the following code in the Params Mapping box

{/*---------- required params ----------*/ "InstanceId": "obj.InstanceId",/*---------- optional params ----------*/ "InstanceType": {
"Value": "obj.nextInstanceType"
}
}

5. Add another Action Node. We will use this to restart the instances after changing the instance type.

  • Select the output of the Filter Node from the drop-down (this will ensure that we restart only the filtered instances that were in running state)

  • Select EC2 as service and Start Instances as action

  • Check the box Wait for startInstances to finish

  • Click Save

6. Add a Report Node. We will use this to send a report to our email once the instance is upgraded.

  • Select the output of the last Action Node from the drop-down (Start Instances)

  • Select Email, and enter the email on which you want to be notified

  • Select the box Only send report if data is available

  • Select Input Transformer, and enter the parameters you want included in your report

  • Click Save

Instances that have the tag mentioned in the Jira Ticket will have their process upgraded