In this task you will create a new Config rule that will check whether your EC2 instances are of the specified instance types and apply a remediation action in case of rule non compliant status.
In your left panel, click on Rules
Click on
In the AWS Manager Rules search box, type: desired-instance-type
Select the managed rule and click
Under the Trigger section -> Scope of changes, select Tags. In Resources by tag, type Compliance
as the Tag key, and in Value tag type Prod
In the Parameters section, type t3.small
as the value for the Key instanceType
Click on
Click on
Your rule will start evaluating resources compliance
Previous to enable an automated remediation action, you need to create an IAM role and assign it to the Config rule to be able to execute the instance resize remediation action. Go to Services search box > IAM
On the left pane, click on Roles
Click on
Under Use case, and Use cases for other AWS services:, select Systems Manager (Do not select Systems Manager - Inventory and Maintenance Windows)
Click on Next
In the Permissions policies search box type AmazonEC2FullAccess
, hit
Click Next
In Role name* type: config-resize-instance-role
Click
You will see Role config-resize-instance-role has been created. at the top of the screen. Click on View role button, right to that message.
Copy the Role ARN (i.e. arn:aws:iam::xxxxxxxxxxx:role/config-resize-instance-role) and paste it in a note pad, you will use it in a later step.
Now return to Config service. Services search box > Config
On the left pane, click on Rules
Look for the instance resize rule, and click on the rule
Click and select Manage remediation
In Select remediation method section, select Automatic remediation
Under Retries in type 5
and under Seconds typoe 60
.
In Remediation action details, section, expand the drop-down menu and select AWS-ResizeInstance
In the Rate Limits section, under Concurrent Execution Rate type 2
, and under Error Rate type 5
.
In Resource ID parameter select InstanceId
In the Parameters section, fill the InstanceType and AutomationAssumeRole ** parameters. In InstanceType, type t3.small
and paste the role ARN you copied in step 22 in AutomationAssumeRole.
Click
This automatic remediation action will start to evaluate EC2 resources configurations.
Now you will change the instance type so you could test the remediation action you just configured. Go to the EC2 service. Services search box > EC2
On the left pane, click on Instances
Look for the instance with the prefix “sc-web-” and select the checkbox next to it
Click on and select Stop instance and confirm your action.
Wait a few seconds until the instance state changes to Stopped
Change the instance type:
In the Change instance type window, below Instance type, select t3.xlarge
Click
Now start the EC2 instance, click Instance state -> Start instance
Copy the instance ID, we will use it in a later step
This change will trigger the Config rule remediation action, it will take a couple of minutes for the rule to start changing the instance status automatically, from shutting down, to resize back to t3.small
and finally start the instance again, so it can enter in a compliant state according to the rule we created. You could wait a couple of minutes in the EC2 console and refresh the page to see this automatic remediation actions.
Now we will use another Config feature, the capacity to keep track of changes in AWS resource.
AWS Config records details of changes to your AWS resources to provide you with a configuration history. You can use the AWS Management Console, API, or CLI to obtain details of what a resource’s configuration looked like at any point in the past. AWS Config will also automatically deliver a configuration history file to the Amazon S3 bucket you specify.
Return to Config console. Go to Services search box > Config
From the left pane, click on Resources
In the Resources section paste the EC2 instance ID into the search box, it will display the instance ID below the Resource identifier section. Click on the instance ID.
Click
You will see a list of events, feel free to explore the events displayed, you could expand each one of them but we recommend you to look into the Rule compliance and Configuration change events. You will find interesting information regarding the instance configuration changes, and compliance status updates.