The Twelve Days of AWS: CloudWatch

12 Days of AWS Day 8 written around snowflakes with a penguin wearing a red beanie hat

Speaking of CloudWatch… all things logging belong here. CloudWatch will track metrics on your EC2 instances, SQS, SNS entries and more. You will have graphing of data, and be able to keep track of everything happening on your AWS stack.

Out of the box it already tracks a lot, but if you set up a Serverless Lambda, CloudFormation will configure CloudWatch Log Groups for each of your Lambda environments.

Within a Log Group, you will have Log Streams, which contain Log Events.

When a Lambda kicks off it will initiate a Log Stream, then any logged event such as a print() will appear in the stream.

If the Lambda is not triggered for a certain amount of time it will shut down, and then the Log Stream is closed.

Within a Stream, you can filter by specific events if you need to monitor a certain event of your code, which can help when you have a rather verbose logging.

For logging of data that is possibly more data related you can also fire off custom metrics from within a Lambda, which is reported in the Metrics section of CloudWatch.

For example, you might log the response of an API call, which would be visible in the Log Stream, and then set a Metric for the number of records updated in a Custom Metric, which can be graphed to see the trends over time.

One thing to be aware of if you are using Serverless is that if you delete a LogGroup it doesn’t get refreshed on the next deployment of your code. You need to re-build the whole stack from scratch.

Get comfortable with CloudWatch as any responsible developer should be spending a lot of time poking about logs.