
With the criteria of zero trust and least privilege permission, deleting resources always needs to comply with very strict requirements such as:
In the framework of this lab, we will perform the part: only delete EC2 - when accessing the AWS account from the company’s IP address
Get IP address

Create IAM Policy
IAM
Policies
JSONNoted: in line aws:SourceIp instead of entering the number sequence 125.xxx.xxx.xxxx which is the IP address you took in step 1, you need to change it to another number sequence. For example: change 125.xxx.xxx.xxxx with 55.165.049.118 which is your home IP address - we do this to prove step 4
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ec2:TerminateInstances",
"Resource": "arn:aws:ec2:*:148922931563:instance/*"
},
{
"Sid": "VisualEditor1",
"Effect": "Deny",
"Action": "ec2:TerminateInstances",
"Resource": "arn:aws:ec2:*:148922931563:instance/*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "55.165.049.118"
}
}
}
]
}

IP_RestrictAllow IP address of company

Add policy IP_Restrict to group CostTest


IP_Restrict.

Check Permissions policies
EC2EC2_IP
t3.small




Check Permissions policies with correct IP address




Return to the EC2 interface
Check the box symbol to select the EC2 instance you created in step 4
Select Instance state
Select Terminate instance
Congratulations, you have successfully deleted EC2 when accessing your AWS account from the company’s IP address.
