> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Efs resources protected by backup plan remediation

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the misconfiguration of not having a backup plan for Elastic File System (EFS) in AWS EC2 using the AWS Management Console, follow these steps:

        1. **Sign in to the AWS Management Console**: Go to [https://aws.amazon.com/](https://aws.amazon.com/) and sign in to your AWS account.

        2. **Navigate to the Elastic File System (EFS) Service**: Click on the "Services" dropdown in the top navigation bar and select "Elastic File System" under the "Storage" category.

        3. **Select the EFS File System**: From the list of EFS file systems, select the EFS file system that you want to create a backup plan for by clicking on its name.

        4. **Create a Backup Plan**:
           * Click on the "Backup" tab on the EFS file system details page.
           * Click on the "Create Backup Plan" button.

        5. **Configure Backup Plan**:
           * Enter a name for the backup plan.
           * Choose the backup frequency and retention policy that suits your requirements. For example, you can set up daily backups with a retention period of 30 days.
           * Configure any lifecycle policies if needed.

        6. **Review and Create Backup Plan**:
           * Review the backup plan configuration to ensure it meets your requirements.
           * Click on the "Create" or "Save" button to create the backup plan for the EFS file system.

        7. **Monitor Backup Plan**:
           * Once the backup plan is created, you can monitor the backups and their status from the "Backup" tab on the EFS file system details page.
           * Ensure that backups are running as per the configured schedule and that you can restore data if needed.

        By following these steps, you have successfully remediated the misconfiguration by creating a backup plan for your Elastic File System in AWS EC2 using the AWS Management Console. This will help ensure data protection and availability in case of any unexpected events or data loss situations.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration of not having a backup plan for Elastic File System (EFS) in AWS EC2 using AWS CLI, you can follow these steps:

        1. **Create a Backup Plan**:
           * Use the AWS CLI command `create-backup-plan` to create a backup plan for your EFS file system.
           * Specify the backup plan details such as name, schedule, retention policy, and backup vault.
           * Example command:
             ```
             aws backup create-backup-plan --backup-plan "Name=MyBackupPlan,BackupPlanRule={RuleName=DailyBackup,ScheduleExpression=\"cron(0 0 * * ? *)\",TargetBackupVaultName=MyBackupVault,StartWindowMinutes=60,CompletionWindowMinutes=120,Lifecycle={MoveToColdStorageAfterDays=30,DeleteAfterDays=90}}"
             ```

        2. **Assign Backup Plan to EFS File System**:
           * Use the AWS CLI command `put-backup-vault-access-policy` to assign the created backup plan to your EFS file system.
           * Specify the EFS file system ID and the ARN of the backup plan.
           * Example command:
             ```
             aws backup put-backup-vault-access-policy --backup-vault-name MyBackupVault --policy "{\"BackupPlanId\":\"arn:aws:backup:us-west-2:123456789012:backup-plan:MyBackupPlan\"}"
             ```

        3. **Enable Backup for EFS File System**:
           * Use the AWS CLI command `start-backup-job` to initiate the backup process for your EFS file system.
           * Specify the EFS file system ID and the backup vault name.
           * Example command:
             ```
             aws backup start-backup-job --backup-vault-name MyBackupVault --resource-arn arn:aws:elasticfilesystem:us-west-2:123456789012:file-system/fs-12345678
             ```

        4. **Verify Backup Status**:
           * Use the AWS CLI command `describe-backup-job` to check the status of the backup job for your EFS file system.
           * Monitor the progress and ensure that the backup is successfully completed.
           * Example command:
             ```
             aws backup describe-backup-job --backup-job-id abcdef12-3456-7890-abcd-1234567890ab
             ```

        By following these steps, you can remediate the misconfiguration of not having a backup plan for your EFS file system in AWS EC2 using AWS CLI. This will help you ensure data protection and recovery in case of any unexpected data loss or corruption.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration of not having a backup plan for Elastic File System (EFS) in AWS EC2 using Python, you can follow these steps:

        1. **Install Boto3**: Boto3 is the AWS SDK for Python. You can install it using pip:
           ```bash theme={null}
           pip install boto3
           ```

        2. **Create a Backup Plan**: You can create a backup plan using AWS Backup service. Here's an example Python script to create a backup plan for your EFS:

           ```python theme={null}
           import boto3

           # Initialize the AWS Backup client
           backup_client = boto3.client('backup')

           # Define the resource ARN for your EFS file system
           resource_arn = 'arn:aws:elasticfilesystem:us-east-1:123456789012:file-system/fs-12345678'

           # Define the backup plan name and backup rule
           backup_plan_name = 'EFS-Backup-Plan'
           backup_rule = {
               'RuleName': 'EFS-Backup-Rule',
               'TargetBackupVaultName': 'MyBackupVault',
               'ScheduleExpression': 'cron(0 12 * * ? *)',  # Daily backup at 12:00 PM UTC
               'StartWindowMinutes': 60,
               'CompletionWindowMinutes': 60
           }

           # Create a backup plan
           response = backup_client.create_backup_plan(
               BackupPlan = {
                   'BackupPlanName': backup_plan_name,
                   'BackupPlanRule': backup_rule
               }
           )

           print('Backup plan created successfully!')
           ```

           Make sure to replace the `resource_arn` with the ARN of your EFS file system and customize the backup plan name, rule, and schedule as needed.

        3. **Run the Python Script**: Save the above Python script in a file (e.g., `create_backup_plan.py`) and run it using Python:
           ```bash theme={null}
           python create_backup_plan.py
           ```

        4. **Verify Backup Plan**: You can verify the backup plan by checking the AWS Backup console or by listing the backup plans using the AWS CLI:
           ```bash theme={null}
           aws backup list-backup-plans
           ```

        By following these steps, you can create a backup plan for your EFS file system in AWS EC2 using Python and ensure that you have a backup strategy in place for your data.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        # Existing (or separately-managed) EFS file system
        resource "aws_efs_file_system" "THIS_EFS" {
          # ...existing config...
        }

        # OPTIONAL: data source for an existing backup plan (if you know its ID)
        # Replace BACKUP_PLAN_ID with the actual backup plan ID, or remove this
        # data block and hardcode the ID directly in aws_backup_selection.
        data "aws_backup_plan" "TARGET_PLAN" {
          backup_plan_id = "BACKUP_PLAN_ID" # <-- replace with your existing Backup Plan ID
        }

        # OPTIONAL: data source for the existing AWS Backup service role
        # If you do not already have a role, create one with the AWSBackupServiceRolePolicyForBackup policy.
        data "aws_iam_role" "backup_role" {
          name = "AWSBackupDefaultServiceRole" # or another suitable role name
        }

        # Attach the EFS file system to the backup plan (equivalent to aws backup create-backup-selection)
        resource "aws_backup_selection" "efs_backup_selection" {
          name         = "efs-THIS_EFS-selection" # arbitrary selection name
          iam_role_arn = data.aws_iam_role.backup_role.arn
          plan_id      = data.aws_backup_plan.TARGET_PLAN.id

          resources = [
            aws_efs_file_system.THIS_EFS.arn,
          ]
        }
        ```

        This change does not replace the EFS file system; it only creates a new AWS Backup selection attaching it to an existing backup plan.

        To verify, `terraform plan` should show creation of an `aws_backup_selection` resource referencing your existing backup plan ID, backup IAM role ARN, and the target EFS file system ARN, with no changes to the EFS resource itself.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
