> ## 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.

# Beanstalk notification enabled remediation

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To enable alert notifications for Elastic Beanstalk events in AWS using the AWS console, follow these steps:

        1. Log in to the AWS Management Console.
        2. Navigate to Elastic Beanstalk.
        3. Select the application you want to remediate.
        4. Click on the "Configuration" tab in the left-hand menu.
        5. Scroll down to the "Notifications" section and click on "Edit".
        6. Select the events for which you want to receive notifications.
        7. Choose the notification method (e.g. email, SMS, etc.).
        8. Enter the email or phone number where you want to receive the notifications.
        9. Click on "Save" to save your changes.

        Once you have completed these steps, you will receive notifications for the selected Elastic Beanstalk events via the chosen notification method.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To enable alert notifications for Elastic Beanstalk events in AWS using AWS CLI, follow the below steps:

        1. Open the AWS CLI on your local machine or terminal.

        2. Run the following command to enable alert notifications for Elastic Beanstalk events:

        ```
        aws elasticbeanstalk update-environment --environment-name <environment-name> --option-settings Namespace=aws:elasticbeanstalk:sns:topics,OptionName=Notification Endpoint,Value=<email-address>
        ```

        Note: Replace `<environment-name>` with the name of the Elastic Beanstalk environment for which you want to enable alert notifications and `<email-address>` with the email address where you want to receive the notifications.

        3. After running the above command, you should receive a confirmation message that the environment has been updated.

        4. Now, whenever an Elastic Beanstalk event occurs in the specified environment, you will receive an email notification at the specified email address.

        That's it! You have successfully enabled alert notifications for Elastic Beanstalk events in AWS using AWS CLI.
      </Accordion>

      <Accordion title="Using Python">
        To enable alert notifications for Elastic Beanstalk events in AWS using Python, follow these steps:

        1. Import the necessary modules:

        ```python theme={null}
        import boto3
        ```

        2. Create an SNS topic:

        ```python theme={null}
        sns = boto3.client('sns')
        response = sns.create_topic(Name='elastic-beanstalk-notifications')
        topic_arn = response['TopicArn']
        ```

        3. Create a subscription to the SNS topic:

        ```python theme={null}
        response = sns.subscribe(
            TopicArn=topic_arn,
            Protocol='email',
            Endpoint='your-email@example.com'
        )
        subscription_arn = response['SubscriptionArn']
        ```

        4. Create a new CloudWatch alarm:

        ```python theme={null}
        cloudwatch = boto3.client('cloudwatch')
        response = cloudwatch.put_metric_alarm(
            AlarmName='elastic-beanstalk-notifications',
            AlarmDescription='Alarm for Elastic Beanstalk events',
            ActionsEnabled=True,
            AlarmActions=[topic_arn],
            MetricName='EnvironmentHealth',
            Namespace='AWS/ElasticBeanstalk',
            Statistic='Average',
            Dimensions=[
                {
                    'Name': 'EnvironmentName',
                    'Value': 'your-environment-name'
                }
            ],
            Period=60,
            EvaluationPeriods=1,
            Threshold=1,
            ComparisonOperator='GreaterThanOrEqualToThreshold'
        )
        ```

        5. Verify that the CloudWatch alarm was created:

        ```python theme={null}
        response = cloudwatch.describe_alarms(
            AlarmNames=['elastic-beanstalk-notifications']
        )
        print(response)
        ```

        These steps will create an SNS topic, subscribe an email address to it, and create a CloudWatch alarm that sends notifications to the SNS topic when an Elastic Beanstalk event occurs.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        # SNS topic to receive Elastic Beanstalk notifications
        resource "aws_sns_topic" "elasticbeanstalk_notifications" {
          name = "elasticbeanstalk-notifications-${ELASTICBEANSTALK_ENV_NAME}"
          # Replace ELASTICBEANSTALK_ENV_NAME with your environment name (no spaces)
        }

        # Email subscription to the SNS topic
        resource "aws_sns_topic_subscription" "elasticbeanstalk_notifications_email" {
          topic_arn = aws_sns_topic.elasticbeanstalk_notifications.arn
          protocol  = "email"

          endpoint = "ALERT_EMAIL_ADDRESS@example.com"
          # Replace ALERT_EMAIL_ADDRESS@example.com with the email to receive notifications
          # NOTE: The recipient must confirm the subscription via the email they receive.
        }

        # Elastic Beanstalk environment with SNS notification endpoint configured
        resource "aws_elastic_beanstalk_environment" "this" {
          name                = "ELASTICBEANSTALK_ENV_NAME"      # replace with your environment name
          application         = "ELASTICBEANSTALK_APP_NAME"      # replace with your EB application name
          solution_stack_name = "SOLUTION_STACK_NAME"            # e.g. "64bit Amazon Linux 2 v3.5.3 running Python 3.8"

          # ... your existing settings ...

          # Match: aws elasticbeanstalk update-environment --option-settings Namespace=aws:elasticbeanstalk:sns:topics,OptionName=Notification Endpoint,Value=<YOUR_SNS_TOPIC_ARN>
          setting {
            namespace = "aws:elasticbeanstalk:sns:topics"
            name      = "Notification Endpoint"
            value     = aws_sns_topic.elasticbeanstalk_notifications.arn
          }
        }
        ```

        This change updates the existing Elastic Beanstalk environment in place (no forced replacement); `terraform plan` should show one new `aws_sns_topic`, one new `aws_sns_topic_subscription`, and an in-place update to `aws_elastic_beanstalk_environment.this` adding the SNS notification `setting` block.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
