EC2 Stop Instance

Objective

The goal of the tutorial is to stop AWS (Elastic Compute Cloud) EC2 instance(s) from FlexDeploy. This automation includes:

  • Stop a virtual machine using one or more instance ids using the AWS CLI

We will walk through each of the FlexDeploy features that will be created/configured to accomplish this goal and stop the instance in a very short amount of time.

Checklist

Checklist

Description

Checklist

Description

AWS Access Key

The access key found on the "Security Credentials" page of the AWS management console.

AWS Secret Key

The secret key found on the "Security Credentials" page of the AWS management console.

AWS Default Region

The default region found on the top right corner of the AWS management console.

Instance Id(s)

Provide either comma or space-separated IDs of the instances to stop.

AWS CLI installation

AWS CLI needs to be installed where the plugin operation shall run (FlexDeploy server)

AWS CLI in class path

AWS CLI should be added to class path on the FlexDeploy Server. Else the path can also be set under FlexDeploy environment level property.

Configure Cloud Account

First, an AWS account needs to be configured under Integrations. FlexDeploy will connect to the AWS account with provided details and stops the Instance(s).

  1. Select Integrations from the Menu.

  2. Navigate to the Cloud tab from the left-hand pane.

  3. Create a new Cloud account of the provider type “AWS” with the “+ Create” button.

It should have a AWS Access Key, AWS Secret Key, and AWS Default Region to be configured in it. The AWS Access Key must have relevant access to the Start/Stop Instance(s) and make other associated changes(Application Setting update etc).

  1. Secret Key is a password field and hence needs to be kept hidden. To update the same click on the pencil icon as shown below

  2. Update the Secret Key value under Secret Text. This is to make sure no one else can retrieve the password

After saving the credential, click on Save on the cloud instance. Test connection will not work for the AWS cloud.

Utility Workflow

Navigate to Workflows and create a workflow using the button as highlighted below.

Workflow Properties

From the Properties tab, create a workflow property with Project scope as shown below:

  1. Click + Create

  2. Properties must each have a unique code, give a meaningful code for the new property.

  3. A property display name does not have to be unique and can contain spaces. This is the name that will be displayed on the Project Properties screen

  4. Select the property scope, this defines where the property will be configured. We're using Project scope.

  5. Enter a good description for the property, this will make configuration easier in the future

  6. Save the new property

Workflow Definition

Going back to the Definition tab, here is a sample utility workflow.

The stopInstance operation returns three output variables. To capture them and use them for further processing/evaluation, one can create three variables and map them against the output parameters. Return As Output option should be checked in case we want to return them as Workflow output.

  1. First, click the X2 button to open the Variables popup

  2. Next, click the Create button and add three output variables.

Map the variables against the output of the StopInstance operation to capture the responses and also update the Workflow Input values.

We are also mapping the Project Property (AWS_EC2_INSTANCE_IDS) against the Instance IDs section to dynamically pass the Instance ID from Project property.

Note: You can also hard code the Instance IDs directly as a plugin input, or use Target/Environment level property to pass the Instance IDs.

Plugin Inputs

Property Name

Type

Description

Property Name

Type

Description

Instance Id(s)

Single instance

Provide comma or space separated Instance Id(s) to start.

(e.g. i-073d5fbf3e5766cf4 )

Multiple instances space separated

e.g. i-073d5fbf3e5766cf4 i-04ed696929f9074e2

Multiple instances comma separated

e.g. i-073d5fbf3e5766cf4,i-04ed696929f9074e2

Topology

For detailed steps on how to configure the topology and map the workflows manually, please refer to

Target Properties

Selecting the DEV environment mapped to the Target Group will display the configurable properties/Endpoint and allows to the configure the Target properties.

Provide the value for AWSEndpoint(optional), AWSCloudAccount, AWSRegion (optional but can be used to override the region defined in the AWS cloud instance), AWSCLIPath(optional,not needed if set in classPath), Number of Iterations (optional, default value is 6), and Interval Duration (optional default value is 30sec) and map the localhost as Endpoint as shown below.

Target Properties Info

Property Name

Mandatory

Values for this Tutorial

Description

Property Name

Mandatory

Values for this Tutorial

Description

AWS Endpoint

Optional

 

The AWS Endpoint to use.

AWS Cloud Account

Yes

AWSFlexDev

The AWS Cloud Account Name configured.

Absolute path of AWS CLI

Optional

/usr/local/bin

The path to the directory where Azure CLI is installed. (Optional)
eg: /usr/local/bin

AWS Region

Optional

 

The default region found on the top right corner of the AWS Management console. e.g. us-west-2

Number of Iterations

Optional (default is 6)

6

The number of iterations to perform the status check.

Interval between status check

Optional (default is 30)

15

The interval between EC2 instance status check.

Create the AWS EC2 Stop Instance Project

For details steps on how to configure the project and execution, please refer to

Reports

With the successful execution of the Utility workflow, a text (.txt) file is created, stored in the reports tab. Every execution will generate a new report with execution Id appended to the text file in the Reports tab.

Click on the text file generated to see the details. This file captures the details of each instance i.e., Instance Id, Instance State, Instance Status, and System Status. In the workflow, there were two EC2 Instance Id’s provided as input. Hence, the report contains the details of both the EC2 Instances. Also, user can download the report file generated.

Congratulations! You have successfully completed the EC2 Stop Instance tutorial.

Now that you have configured FlexDeploy for one EC2 Stop Instance, it is extremely easy to replicate the same for other EC2 Stop Instance. Simply use the Copy Project feature and a new project will be created with all of the configuration completed already. You just need to make the necessary configuration changes.

The following macros are not currently supported in the footer:
  • style