I've been encountering an issue with my Filebeat setup on AWS Elastic Beanstalk. I'm trying to dynamically set the environment name in my Filebeat configuration using an environment variable ($ENVIRONMENT). However, it seems that the changes are not being applied when I deploy my configuration.
###################### Filebeat Configuration #########################
commands:
01_stop_filebeat:
test: "[ -x /usr/bin/filebeat ]"
command: "systemctl stop filebeat"
02_remove_filebeat:
test: "[ -x /usr/bin/filebeat ]"
command: "yum remove -y filebeat"
03_remove_directories:
command: "sudo rm -rf /etc/filebeat"
04_download_filebeat:
command: "curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.10.3-x86_64.rpm"
cwd: /home/ec2-user
05_install_filebeat:
command: "sudo rpm -vi filebeat-8.10.3-x86_64.rpm"
cwd: /home/ec2-user
06_set_filebeat_config:
command: |
if [[ "$ENVIRONMENT" == "staging" ]]; then
NAME="BlueAPI-Staging"
ENV="staging"
elif [[ "$ENVIRONMENT" == "production" ]]; then
NAME="BlueAPI-Production"
ENV="production"
fi
echo "filebeat.inputs:
- type: filestream
id: my-filestream-id
enabled: true
paths:
- /var/log/web.stdout.log
fields:
server: "blueapi"
env: '${ENV}'
name: '${NAME}'
output.logstash:
hosts: ['XX:5044']" | sudo tee /etc/filebeat/filebeat.yml
command: "systemctl enable filebeat"
08_start_filebeat:
command: "systemctl start filebeat"