From ee31f5b70d5d0891e35545ba55ad551554c2fcde Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Wed, 19 Feb 2025 09:00:35 -0600 Subject: [PATCH] Add Find And Follow Server Logs as an AWS TIL --- README.md | 3 +- aws/find-and-follow-server-logs.md | 46 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 aws/find-and-follow-server-logs.md diff --git a/README.md b/README.md index dc4968d..98da4b5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1594 TILs and counting..._ +_1595 TILs and counting..._ See some of the other learning resources I work on: - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) @@ -109,6 +109,7 @@ See some of the other learning resources I work on: ### AWS - [AWS CLI Requires Groff Executable](aws/aws-cli-requires-groff-executable.md) +- [Find And Follow Server Logs](aws/find-and-follow-server-logs.md) - [Sign Up User With Email And Password](aws/sign-up-user-with-email-and-password.md) ### Brew diff --git a/aws/find-and-follow-server-logs.md b/aws/find-and-follow-server-logs.md new file mode 100644 index 0000000..c6db18e --- /dev/null +++ b/aws/find-and-follow-server-logs.md @@ -0,0 +1,46 @@ +# Find And Follow Server Logs + +Let's say you are authenticated with the AWS CLI and have the appropriate +CloudWatch permissions. You have a few services running in production with +associated logs. One of those is a Rails server. + +We want to run `aws logs tail`, but first we check how that command works. + +```bash +$ aws logs tail help +``` + +We see a bunch of options, but the only required one is `group_name` ("The name +of the CloudWatch Logs group."). We may also notice the `--follow` flag which +we'll want to use as well to keep incoming logs flowing. + +We need to determine the log group name for the Rails server. We can do that +from the CLI as well (no need to dig into the web UI). + +```bash +$ aws logs describe-log-groups + +{ + "logGroups": [ + { + "logGroupName": "/aws/codebuild/fc-rails-app-abcefg-123456", + "creationTime": 1739476650823, + "metricFilterCount": 0, + "arn": "arn:aws:logs:us-east-2:123456789:log-group:/aws/codebuild/fc-rails-app-abcefg-123456:*", + "storedBytes": 65617, + "logGroupClass": "STANDARD", + "logGroupArn": "arn:aws:logs:us-east-2:123456789:log-group:/aws/codebuild/fc-rails-app-abcefg-123456" + }, + ... + ] +} +``` + +Because the group name is descriptive enough, we can find the log group we are +interested in: `/aws/codebuild/fc-rails-app-abcefg-123456`. + +Now we know what we want to `tail`. + +```bash +$ aws logs tail /aws/codebuild/fc-rails-app-abcefg-123456 --follow +```