This rule ensures that EC2 stopped instances are removed within a 30-day timeframe.
Rule | EC2 stopped instances should be removed in 30 days |
Framework | Federal Financial Institutions Examination Council (FFIEC) |
Severity | ✔ Low |
EC2 Stopped Instances Removal Policy for FFIEC Compliance
Overview
Financial institutions regulated by the Federal Financial Institutions Examination Council (FFIEC) must adhere to stringent guidelines regarding data integrity, protection, and resource management. These guidelines include the proper handling of decommissioned or unused resources within their cloud environments. EC2 instances that have been stopped and are not in use should be removed within 30 days to align with cost optimization and security best practices.
Why Remove Stopped EC2 Instances?
Troubleshooting Steps
If an EC2 instance is not terminating as expected, consider the following troubleshooting steps:
Removal Policy Details
Instances that have been stopped and not restarted within 30 days should be identified and scheduled for removal. This ensures that resources are efficiently managed, and unnecessary charges are avoided.
Automation Script
You can automate the identification and removal process using AWS CLI commands in conjunction with scripting languages such as Python and AWS Lambda functions.
Script Requirements
Example Python Code for Automation
import boto3
from datetime import datetime, timedelta
ec2 = boto3.client('ec2')
def get_stopped_instances():
instances = ec2.describe_instances(
Filters=[
{'Name': 'instance-state-name', 'Values': ['stopped']},
]
)
return instances
def should_terminate(instance, days=30):
state_transition = next((x for x in instance['StateTransitionReason'] if 'stopped' in x), None)
if state_transition:
stop_time_str = state_transition.split('(')[1].strip(')')
stop_time = datetime.strptime(stop_time_str, "%Y-%m-%d %H:%M:%S %Z")
return datetime.now(stop_time.tzinfo) - stop_time > timedelta(days=days)
return False
def terminate_instances():
for reservation in get_stopped_instances()['Reservations']:
for instance in reservation['Instances']:
if should_terminate(instance):
print(f"Terminating instance {instance['InstanceId']}")
ec2.terminate_instances(InstanceIds=[instance['InstanceId']])
# Entry point for the script
if __name__ == "__main__":
terminate_instances()
AWS CLI Commands
To remove an EC2 instance using the AWS CLI:
# Terminate the specific EC2 instance aws ec2 terminate-instances --instance-ids i-1234567890abcdef0
Remediation Steps
Ensure that your removal process does not impact critical services and that there is a clear understanding of the instance usage. For optimal SEO, this guide utilizes targeted keywords relevant to the topic and provides actionable guidance that supports best practices in cloud resource management.