Lab Guide: Building an Optimization Workflow
1. Lab Briefing
This section provides an overview of the lab challenge and instructions for getting started.
1.1. Challenge Summary
In this challenge, you will create a workflow. Public cloud environments are often used by many different teams, and by using automation, you can create workflows to help enforce organizational policies.
1.2. What is Infrastructure Optimization?
While a lot of cloud automation focuses on provisioning and de-provisioning, we can also use automation to help tame our public cloud environments and keep them under control. This is often called Day-2 operations or infrastructure optimization.
This can include tasks like identifying non-compliant resources, scheduling instances to be turned off outside of business hours, or finding and removing orphaned resources.
2. Lab Guide: Hands-On Tasks
Estimated time to complete: 20 minutes
In this third challenge, you will create a workflow that uses your existing job template to find specific instances and then performs an action on them.
2.1. Task 1: Log into Ansible Automation Platform
First, you will log in to the automation controller to begin the lab exercises.
-
Navigate to the Automation Controller UI.
Click on the Automation Controller tab at the top of your lab window.
-
Log in with the provided credentials.
Username
adminPassword
ansible12-3!
After logging in, you will land on the main dashboard.
2.2. Task 2: Create the "Stop Instances" Job Template
You will start by creating a job template whose purpose is to stop EC2 instances.
-
Navigate to the Templates page.
In the left navigation menu, go to Automation Execution → Templates.
-
Initiate the creation of a new job template.
Click the Create template button, then select Create job template.

-
Enter the job template details.
Fill out the form with the following information:
Parameter
Value
Name
Stop instancesJob Type
RunInventory
Demo InventoryProject
AWS Demos ProjectExecution Environment
AWS Execution EnvironmentPlaybook
playbooks/stop_aws_ec2_instances.ymlCredentials
AWS_CredentialTo find the AWS_Credential, you may need to filter the Credential Type toAmazon Web Services. -
Save the job template.
Scroll to the bottom and click the blue Save button.
-
Understand the playbook.
This playbook contains a single task that uses the
amazon.aws.ec2_instancemodule to stop instances passed to it via theidentified_instancesvariable.- name: stop every un-tagged running instance in a region. amazon.aws.ec2_instance: region: "{{ ec2_region }}" state: stopped instance_ids: "{{ identified_instances }}" when: identified_instances | length > 0
| The Ansible Playbooks for this lab are sourced from the following project: ansible-cloud/aws_demos. |
2.3. Task 3: Build the AWS Optimization Workflow
Now, you will combine the template from the previous lab (Retrieve INSTANCES by tag) with the new Stop instances template into a single workflow.
-
Navigate to the Templates page and initiate workflow creation.
Go to Automation Execution → Templates, click the Create template button, and select Create workflow job template.

-
Enter the workflow details.
Parameter
Value
Name
AWS WorkflowOrganization
DefaultClick Save. The Workflow Visualizer will open.
-
Add the first node (Retrieve Instances).
Click the Start button to add the first step. Configure it as follows:
-
Node Type:
Job Template -
Job Template: Select
Retrieve INSTANCES by tag. Click Next. -
Survey: In the
Provide an EC2 filterfield, enter"tag:Name": "rhel1". -
Click Next, then Save to add the node.
-
-
Add the second node (Stop Instances).
Hover over the
Retrieve INSTANCES by tagnode, click the + icon, and select Add node. Configure it as follows:-
Node Type:
Job Template -
Run: Select
On Success. -
Job Template: Select
Stop instances. -
Click Next, then Save.
-
-
Save the workflow.
In the top right corner of the Visualizer, click Save. Your completed workflow should look like this:

2.4. Task 4: Launch the Workflow
Now you are ready to run the complete workflow.
-
Navigate to the Templates page.
Go to Automation Execution → Templates.
-
Launch the workflow.
Find the
AWS Workflowin the list and click the Launch icon (🚀).
-
Monitor the visualizer.
The workflow visualizer will show the real-time progress. The workflow will:
-
Run the
Retrieve instances by tagnode to identify therhel1instance. -
Upon success, run the
Stop instancesnode, which will turn off the instance identified in the first step.You can click on any node in the visualizer to view the
Outputtab for that specific job.
2.5. Task 5: Verify the Instance is Stopped
Finally, you will confirm the result in the AWS Management Console.
-
Navigate to the AWS Console.
Click on the AWS console tab in your lab environment and log in with the provided credentials.
Be careful to avoid extra spaces when copying and pasting the credentials. -
Go to the EC2 service.
In the top search bar, search for and select
EC2.
-
Check the instance status.
Go to the Instances page. Make sure you are in the N. Virginia / us-east-1 region. You should see one instance in the
Runningstate and therhel1instance in theStoppedstate.
3. Why Cloud Optimization is Important
You have successfully completed this challenge. This simple lab demonstrates a powerful concept for managing cloud costs and resources. Automation workflows can help you:
-
Turn off unused resources: Automatically shut down instances that are no longer needed.
-
Right-size cloud resources: Identify over-provisioned instances and adjust them.
-
Recover orphaned resources: Find and remove resources left behind by failed processes.
Imagine scheduling a workflow to run nightly, searching for any development instances left running for more than a few hours. This gives cloud teams peace of mind that their infrastructure is not incurring unnecessary charges.
