From 6f99a3fb60c696d3f2a93ff4fb8bbf16e89fdd75 Mon Sep 17 00:00:00 2001 From: Francisco Trillo Date: Mon, 26 Sep 2022 11:20:04 +0200 Subject: [PATCH 1/3] Update 02_logs_cloudwatch_imds2.config --- .ebextensions/02_logs_cloudwatch_imds2.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ebextensions/02_logs_cloudwatch_imds2.config b/.ebextensions/02_logs_cloudwatch_imds2.config index 0550b37..80c29fd 100644 --- a/.ebextensions/02_logs_cloudwatch_imds2.config +++ b/.ebextensions/02_logs_cloudwatch_imds2.config @@ -51,6 +51,6 @@ # } # } -# container_commands: +# commands: # start_cloudwatch_agent: # command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/laravel_logs.json From 4b786a25dfe6c4051ae3e52f845dde415df812c5 Mon Sep 17 00:00:00 2001 From: Francisco Trillo Date: Mon, 26 Sep 2022 14:09:13 +0200 Subject: [PATCH 2/3] fix: logs cloudwatch 2 with hooks --- .ebextensions/02_logs_cloudwatch_imds2.config | 44 ++++--------------- .../hooks/postdeploy/logs_cloudwatch_imds2.sh | 20 +++++++++ 2 files changed, 29 insertions(+), 35 deletions(-) create mode 100644 .platform/hooks/postdeploy/logs_cloudwatch_imds2.sh diff --git a/.ebextensions/02_logs_cloudwatch_imds2.config b/.ebextensions/02_logs_cloudwatch_imds2.config index 80c29fd..872624a 100644 --- a/.ebextensions/02_logs_cloudwatch_imds2.config +++ b/.ebextensions/02_logs_cloudwatch_imds2.config @@ -19,38 +19,12 @@ # Before uncommenting this, please update to match yours, or name it as you wish # option_settings: -# - namespace: aws:elasticbeanstalk:cloudwatch:logs -# option_name: StreamLogs -# value: true -# - namespace: aws:elasticbeanstalk:cloudwatch:logs -# option_name: DeleteOnTerminate -# value: false -# - namespace: aws:elasticbeanstalk:cloudwatch:logs -# option_name: RetentionInDays -# value: 7 - -# files: -# "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/laravel_logs.json" : -# mode: "000644" -# owner: root -# group: root -# content: | -# { -# "logs": { -# "logs_collected": { -# "files": { -# "collect_list": [ -# { -# "file_path": "/var/app/current/storage/logs/*.log", -# "log_group_name": "/aws/elasticbeanstalk//var/app/current/storage/logs/", -# "log_stream_name": "{instance_id}" -# } -# ] -# } -# } -# } -# } - -# commands: -# start_cloudwatch_agent: -# command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/laravel_logs.json +# - namespace: aws:elasticbeanstalk:cloudwatch:logs +# option_name: StreamLogs +# value: true +# - namespace: aws:elasticbeanstalk:cloudwatch:logs +# option_name: DeleteOnTerminate +# value: false +# - namespace: aws:elasticbeanstalk:cloudwatch:logs +# option_name: RetentionInDays +# value: 7 diff --git a/.platform/hooks/postdeploy/logs_cloudwatch_imds2.sh b/.platform/hooks/postdeploy/logs_cloudwatch_imds2.sh new file mode 100644 index 0000000..1e25af5 --- /dev/null +++ b/.platform/hooks/postdeploy/logs_cloudwatch_imds2.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# echo '{ +# "logs": { +# "logs_collected": { +# "files": { +# "collect_list": [ +# { +# "file_path": "/var/app/current/storage/logs/*.log", +# "log_group_name": "/aws/elasticbeanstalk//var/app/current/storage/logs/", +# "log_stream_name": "{instance_id}" +# } +# ] +# } +# } +# } +# }' > "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/mycustomlogs.json" +# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config +# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop +# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a start From 191291af75cc4a1cbd2cd9fac1e48367811230a1 Mon Sep 17 00:00:00 2001 From: Francisco Trillo <72965099+Frtrillo@users.noreply.github.com> Date: Wed, 15 May 2024 13:21:25 +0200 Subject: [PATCH 3/3] Added comments to clarify file correlation. --- .ebextensions/02_logs_cloudwatch_imds2.config | 3 ++- .platform/hooks/postdeploy/logs_cloudwatch_imds2.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.ebextensions/02_logs_cloudwatch_imds2.config b/.ebextensions/02_logs_cloudwatch_imds2.config index 872624a..d8f8117 100644 --- a/.ebextensions/02_logs_cloudwatch_imds2.config +++ b/.ebextensions/02_logs_cloudwatch_imds2.config @@ -16,7 +16,8 @@ # Usually, the option_settings with enabled Stream Logs should be uncommented if you are not using IaaC, like Chef or Terraform. # If you created the environment manually, uncomment the following lines and set the amount of retention in days. -# Before uncommenting this, please update to match yours, or name it as you wish +# Before uncommenting this, please update to match yours, or name it as you wish. +# Also don't forget to uncomment as well .platform/hooks/postdeploy/logs_cloudwatch_imds2.sh # option_settings: # - namespace: aws:elasticbeanstalk:cloudwatch:logs diff --git a/.platform/hooks/postdeploy/logs_cloudwatch_imds2.sh b/.platform/hooks/postdeploy/logs_cloudwatch_imds2.sh index 1e25af5..6e823c1 100644 --- a/.platform/hooks/postdeploy/logs_cloudwatch_imds2.sh +++ b/.platform/hooks/postdeploy/logs_cloudwatch_imds2.sh @@ -1,3 +1,4 @@ +# Before uncommenting this please don't forget to also uncomment .ebextensions/02_logs_cloudwatch_imds2.config #!/bin/bash # echo '{