Elastic Beanstalk ebextension config not running for instances created by autoscaling group thus not running cloudwatch cmds

43 Views Asked by At

Elastic beanstalk will run my ebextension config when I do a fresh deploy of the application but when I terminate one of the instance an auto scaling group will trigger and launch an instance to satisfy the min no. of instances to run.

When the instance is launched using the ASG it is not running the ebextensions config file

here is my ebextension cloudwatch.config file

 files:
  "/opt/aws/amazon-cloudwatch-agent/bin/config.json":
    mode: "000600"
    owner: root
    group: root
    content: |
      {
        "agent": {
          "metrics_collection_interval": 300,
          "run_as_user": "root"
        },
        "metrics": {
          "namespace": "Devops/Ec2/System",
          "append_dimensions": {
            "AutoScalingGroupName": "${aws:AutoScalingGroupName}",
            "InstanceId": "${aws:InstanceId}",
            "InstanceName": "${aws:InstanceName}"
          },
          "metrics_collected": {
            "disk": {
              "measurement": [
                "used_percent"
              ],
              "resources": [ "/" ]
            }
          }
        }
      }
container_commands:
  start_cloudwatch_agent:
    command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json

below is the CFT i used to create the infra

InitialVersion:
    Type: AWS::ElasticBeanstalk::ApplicationVersion
    Properties:
      Description: Initial Version
      ApplicationName: !Ref App
      SourceBundle:
        S3Bucket: !ImportValue
          Fn::Sub: ${DatabaseStackName}-releases
        S3Key: !Ref Artifact
  Env:
    Type: AWS::ElasticBeanstalk::Environment
    Properties:
      Description: app
      EnvironmentName:
        !Join
        - '-'
        - - !Select [ 0, !Split [ '-', !Ref AWS::StackName ] ]
          - !Select [ 1, !Split [ '-', !Ref AWS::StackName ] ]
          - !Select [ 2, !Split [ '-', !Ref AWS::StackName ] ]
          - !Select [ 3, !Split [ '-', !Ref AWS::StackName ] ]
      ApplicationName: !Ref App
      CNAMEPrefix:
        !Join
        - '-'
        - - !Select [ 0, !Split [ '-', !Ref AWS::StackName ] ]
          - !Select [ 1, !Split [ '-', !Ref AWS::StackName ] ]
          - !Select [ 2, !Split [ '-', !Ref AWS::StackName ] ]
          - !Select [ 3, !Split [ '-', !Ref AWS::StackName ] ]
      SolutionStackName: 64bit Amazon Linux 2 v3.6.1 running Corretto 11
      VersionLabel: !Ref InitialVersion
      Tier:
        Name: WebServer
        Type: Standard
        Version: 1.0
      OptionSettings:
        - Namespace: aws:autoscaling:launchconfiguration
          OptionName: ImageId
          Value: ami-xxx
        - Namespace: aws:autoscaling:launchconfiguration
          OptionName: InstanceType
          Value: m5.xlarge
        - Namespace: aws:autoscaling:launchconfiguration
          OptionName: RootVolumeSize
          Value: '24'
        - Namespace: aws:autoscaling:launchconfiguration
          OptionName: SecurityGroups
          Value: !ImportValue
            Fn::Sub: ${DatabaseStackName}
        - Namespace: aws:autoscaling:launchconfiguration
          OptionName: IamInstanceProfile
          Value: !ImportValue
            Fn::Sub: ${DatabaseStackName}-InstanceProfile
        - Namespace: aws:autoscaling:asg
          OptionName: MinSize
          Value: 3
        - Namespace: aws:autoscaling:asg
          OptionName: MaxSize
          Value: 9
        - Namespace: aws:autoscaling:trigger
          OptionName: MeasureName
          Value: CPUUtilization
        - Namespace: aws:autoscaling:trigger
          OptionName: Unit
          Value: Percent
        - Namespace: aws:autoscaling:trigger
          OptionName: UpperThreshold
          Value: 50
        - Namespace: aws:autoscaling:trigger
          OptionName: LowerThreshold
          Value: 20
        - Namespace: aws:autoscaling:updatepolicy:rollingupdate
          OptionName: RollingUpdateEnabled
          Value: true

when i connect to instance i should see something like this

cd /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/
[amazon-cloudwatch-agent.d]# ls
file_beanstalk.json  file_config.json

but this is what I am seeing

cd /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/
[amazon-cloudwatch-agent.d]# ls
default
0

There are 0 best solutions below