{"id":9461,"date":"2024-03-27T18:14:31","date_gmt":"2024-03-27T16:14:31","guid":{"rendered":"https:\/\/www.viaboxx.de\/?p=9461"},"modified":"2024-03-27T18:29:09","modified_gmt":"2024-03-27T16:29:09","slug":"monitor-memory-consumption-on-aws","status":"publish","type":"post","link":"https:\/\/www.viaboxx.de\/en\/blog\/monitor-memory-consumption-on-aws\/","title":{"rendered":"Monitor Memory Consumption on AWS"},"content":{"rendered":"\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-6f82d389      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable of contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#preface-motivation\" class=\"uagb-toc-link__trigger\">Preface \/ Motivation<\/a><li class=\"uagb-toc__list\"><a href=\"#the-notification-solution-keep-track-on-elastic-beanstalk-environmental-health\" class=\"uagb-toc-link__trigger\">The Notification Solution &#8211; Keep Track on Elastic Beanstalk environmental Health<\/a><li class=\"uagb-toc__list\"><a href=\"#the-visualization-solution-display-custom-metrics-on-aws-cloudwatch\" class=\"uagb-toc-link__trigger\">The Visualization Solution &#8211; Display custom Metrics on AWS CloudWatch<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#overview-of-necessary-steps\" class=\"uagb-toc-link__trigger\">Overview of necessary Steps<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#create-a-new-data-source\" class=\"uagb-toc-link__trigger\">Create a new Data Source<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#adapt-lambda-function-to-request-health-data\" class=\"uagb-toc-link__trigger\">Adapt Lambda Function to request Health Data<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#1-adapt-settings-prepare-runtime\" class=\"uagb-toc-link__trigger\">1. Adapt Settings \/ Prepare runtime<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#2-add-missing-permissions\" class=\"uagb-toc-link__trigger\">2. Add missing permissions<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#3-adapt-python-code\" class=\"uagb-toc-link__trigger\">3. Adapt Python Code<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#4-test-the-implementation\" class=\"uagb-toc-link__trigger\">4. Test the implementation<\/a><\/li><\/ul><li class=\"uagb-toc__list\"><a href=\"#graph-custom-metrics\" class=\"uagb-toc-link__trigger\">Graph custom Metrics<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#trigger-lambda-function-periodically\" class=\"uagb-toc-link__trigger\">Trigger Lambda function periodically<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#show-memory-usage-on-a-dashboard\" class=\"uagb-toc-link__trigger\">Show Memory Usage on a Dashboard<\/a><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#links\" class=\"uagb-toc-link__trigger\">Links<\/a><\/ul><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<div class=\"wp-block-uagb-separator uagb-block-f0ed5e8c\"><div class=\"wp-block-uagb-separator__inner\" style=\"--my-background-image:url(&quot;data:image\/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http:\/\/www.w3.org\/2000\/svg'%3E%3Cpath d='M6.29312 16.9999L17 6.29302M14.2931 16.9999L17 14.293M-0.707031 15.9999L16.0002 -0.707153M8.00017 -0.707153L-0.706882 7.9999' stroke='black'\/%3E%3C\/svg%3E&quot;)\"><\/div><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-c2e1b3e16bd2eb86f64587eaea6f1a0d\" id=\"Preface-\/-Motivation\" style=\"padding-top:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20)\">Preface \/ Motivation<\/h4>\n\n\n\n<p>Recently, our production environment became unreachable due to our (Kotlin) application using up all available JVM memory. As up to then we did not monitor availability, we only got aware of the problem after a customer contacted support. So we had a quite significant downtime: starting from the moment the incident occurred plus recognition delay (customer report) plus reaction time by us developers (i.e. quick-fixing by giving more memory to the JVM &#8211; investigating the cause was then after-math).<\/p>\n\n\n\n<p>After the incident it was clear that we needed some kind of monitoring coupled with some notification mechanism in case of alarms (especially for memory surveillance) in order to react early &#8211; ideally <em>before<\/em> the customer even recognizes\/experiences problems.<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-29e09977ef2cbdf10a14b5a5ed67895a\" id=\"The-Notification-Solution---Keep-Track-on-Elastic-Beanstalk-[hardBreak]environmental-Health\">The Notification Solution &#8211; Keep Track on Elastic Beanstalk <br>environmental Health<\/h4>\n\n\n\n<p>We are hosting our booking application for bike parking facilities on an AWS EC2 instance, managed by Elastic Beanstalk service. Unfortunately AWS does not provide any solution to measure or display memory consumption.<\/p>\n\n\n\n<p>So the first thing we did was to customize our health endpoint and extend it with additional information concerning memory consumption of our Java process. The result mainly looks like this:<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-ccafde8a wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-092311.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-092311.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-092311.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-092311.png\" alt=\"\" class=\"uag-image-9462\" width=\"232\" height=\"285\" title=\"image-20240321-092311\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>As soon as the free value drops below the (configurable) threshold, the memory status goes to \u201c<em>OUT_OF_SERVICE<\/em>\u201d &#8211; which is also propagated to the overall health status.<\/p>\n\n\n\n<p>Afterwards, we added an alarm on our Elastic Beanstalk environment (go to AWS Console \u2192 <em>Elastic Beanstalk<\/em> \u2192 <em>Environments<\/em> \u2192 { <em>your environment<\/em> } \u2192 Tab <em>Alarms<\/em> \u2192 Button <em>Create a new Alarm<\/em>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Select your environment as resource<\/li>\n\n\n\n<li>Metric \u201cEnvironmentHealth\u201d<\/li>\n\n\n\n<li>As statistic we chose \u201cMinimum\u201d<\/li>\n\n\n\n<li>Period \u2192 the validation frequency, e.g. 1 minute<\/li>\n\n\n\n<li>Choose a meaningful value for Threshold in combination with \u201cChange state after\u201d (we recommend to not make it too small in order to avoid triggering the alarm on some short-time \u201clows\u201d, e.g. after system restart &#8211; this however depends on the individual memory consumption behaviour of your application)<\/li>\n\n\n\n<li>Create a new SNS topic or reuse an existing one in order to be informed via E-Mail<\/li>\n\n\n\n<li>Choose a speaking description as that would be contained in your E-Mail text (customizing the content is not possible out-of-the-box and the generated default text might be quite cryptic)<\/li>\n\n\n\n<li>We chose to only be informed in case of \u201cAlarm\u201d<\/li>\n<\/ul>\n\n\n\n<p>Tip<img loading=\"lazy\" decoding=\"async\" width=\"20\" height=\"20\" src=\"https:\/\/viaboxx.atlassian.net\/gateway\/api\/emoji\/4b315499-10ba-48b1-9fbd-6df8fbb047d9\/1f4a1\/path\" alt=\":bulb:\">: We also set up AWS Chatbot and subscribed it to the SNS topic in order to additionally get informed via Slack-channel. See [1] on how to do that.<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-7430fd90e9490398b7255bbc14dcb972\" id=\"The-Visualization-Solution---display-custom-Metrics-on-AWS-CloudWatch\">The Visualization Solution &#8211; Display custom Metrics on AWS CloudWatch<\/h4>\n\n\n\n<p>Although now we would be informed if memory drops below a certain value, we still would not be able to detect abnormalities including small memory leaks ( i.e. decreasing memory tendencies even after garbage collections triggered by the JVM).<\/p>\n\n\n\n<h5 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-63e696e428d197830b6a5f920acfec19\" id=\"Overview-of-necessary-Steps\">Overview of necessary Steps<\/h5>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li>Create new Data Source<\/li>\n\n\n\n<li>Create Lambda function to receive data to be displayed<\/li>\n\n\n\n<li>Show that data in a Graph<\/li>\n\n\n\n<li>Create Event that periodically triggers the Lambda function<\/li>\n\n\n\n<li>Create Dashboard that makes use of the data source<\/li>\n<\/ol>\n\n\n\n<p>Step 3 is kind of optional as the data will only be shown as long as the graph is displayed. As soon as the screen is reloaded or you log out and in again, already displayed values will be gone &#8211; there\u2019s no historical data being available. That\u2019s achieved by step 4 which will also have an affect on \u201csporadically\u201d created graphs as done in step 3 (as historical values will be shown).<\/p>\n\n\n\n<h5 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-67f03200c5d91f2d3d0bb20a8b22a229\" id=\"Create-a-new-Data-Source\">Create a new Data Source<\/h5>\n\n\n\n<p>We use the template wizard to create this data source as this will help to automatically create needed roles and policies.<\/p>\n\n\n\n<p>Go to AWS Console \u2192 <em>CloudWatch<\/em> \u2192 <em>Settings<\/em> \u2192 Tab <em>Metrics data sources<\/em> \u2192 <em>Create data source<\/em><\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-4a961b8f wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-102208.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-102208.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-102208.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-102208.png\" alt=\"\" class=\"uag-image-9464\" width=\"354\" height=\"239\" title=\"image-20240321-102208\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Choose \u201cCustom\u2026\u201d \u2192 Button \u201cNext\u201d<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-042e0c5d wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-102511-1024x787.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-102511.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-102511.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-102511-1024x787.png\" alt=\"\" class=\"uag-image-9466\" width=\"850\" height=\"652\" title=\"image-20240321-102511\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Name: Put in a meaningful name (better than my bad example <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/viaboxx.atlassian.net\/gateway\/api\/emoji\/4b315499-10ba-48b1-9fbd-6df8fbb047d9\/1f609\/path\" alt=\":wink:\" width=\"20\" height=\"20\">)<\/li>\n\n\n\n<li>Template: select the hello world \u2192 we will later adapt the name and replace the function\u2019s content<\/li>\n\n\n\n<li>Runtime: Python (as I personally prefer Python over JavaScript, you can of course also write the solution for any other runtime that is supported for AWS Lambda functions)<\/li>\n\n\n\n<li>Tick \u201cI acknowledge\u2026\u201d to allow AWS handle creation of all required resources. Unless you like to go through painful processed, I would highly recommend this setting.<\/li>\n<\/ul>\n\n\n\n<p>One remark concerning costs: there\u2019s a free-tier for calling Lambda functions. If you don\u2019t exaggerate by calling your function \u201ctoo often\u201d and\/or have lots functions being called frequently, you normally should not exceed the given limits (currently 1 million lambda function calls per month before you get charged).<\/p>\n\n\n\n<p>It now might take a while until your data source is accessible.<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-a573ce26 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-103735-1024x89.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-103735.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-103735.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-103735-1024x89.png\" alt=\"\" class=\"uag-image-9468\" width=\"850\" height=\"74\" title=\"image-20240321-103735\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If it is, you will be automatically forwarded to the \u201cConfigured data sources\u201d view in the CloudWatch settings. You can then click on \u201cView in Lambda console\u201d and continue with next chapter.<\/p>\n\n\n\n<h5 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-239cd36ad2677c0d1ae47b27e912740e\" id=\"Adapt-Lambda-Function-to-request-Health-Data\">Adapt Lambda Function to request Health Data<\/h5>\n\n\n\n<h6 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-3c5a5ca52855ebb36abcf10a4328b49e\" id=\"1.-Adapt-Settings-\/-Prepare-runtime\">1. Adapt Settings \/ Prepare runtime<\/h6>\n\n\n\n<p>With the creation of the data source we also created a Lambda function. If you did not open it from \u201cConfigured data sources\u201d view from previous chapter you can also select it by opening (AWS) Lambda service.<\/p>\n\n\n\n<p>First we will rename the hello-world package and then update the Python runtime from 3.8 to 3.12.<\/p>\n\n\n\n<p>Make sure to select \u201cCode\u201d tab, in the \u201cEnvironment\u201d window right-click on \u201chello-world\u201d, then \u201cRename\u201d:<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-69d5952a wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-105025.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-105025.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-105025.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-105025.png\" alt=\"\" class=\"uag-image-9470\" width=\"242\" height=\"387\" title=\"image-20240321-105025\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>I chose \u201cmemory\u201d as new package name.<\/p>\n\n\n\n<p>Scroll down to section \u201cRuntime settings\u201d and choose \u201cEdit\u201d. Select \u201cPython 3.12\u201d as runtime and in the handler-section replace \u2018hello-world\u2019 in the path (in my case) with \u2018memory\u2019. You can also rename the lambda function and the name of the handler function &#8211; I left it as is, however.<\/p>\n\n\n\n<p>Next, we will set the target URL for our health REST-endpoint as environment variable. Select <em>Configuration<\/em> tab \u2192 <em>Environment variables<\/em> \u2192 <em>Edit<\/em><\/p>\n\n\n\n<p>Key: HEALTH_ENDPOINT, Value: Your health endpoint URL (if you chose the same solution as we did)<\/p>\n\n\n\n<h6 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-ee51ccd5ae8a1b2e27c576c83381ba00\" id=\"2.-Add-missing-permissions\">2. Add missing permissions<\/h6>\n\n\n\n<p>If you would now try to test your code, the response would contain an error message:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-background-color has-background\"><code><code>\"errorMessage\": \"An error occurred (AccessDenied) when calling the PutMetricData operation...<\/code><\/code><\/pre>\n\n\n\n<p>Although we kindly asked AWS to create stuff for us, we still lack some permission to allow our Lambda function to publish data to the CloudWatch service.<\/p>\n\n\n\n<p>If you know the role name, you can directly search for it in \u2192 <em>IAM<\/em> \u2192 <em>Roles<\/em>. As I assume that you don\u2019t, here\u2019s an alternative way to go there:<\/p>\n\n\n\n<p>In the Lambda view, choose \u2192 <em>Configuration<\/em> tab \u2192 menu entry <em>Permissions<\/em>. Below \u201c<em>Execution role<\/em>\u201d, the role name is shown as clickable link. On permissions tab, scroll down to \u201c<em>Permissions policies<\/em>\u201d, click on \u201c<em>Add permissions<\/em>\u201d button \u2192 <em>Create inline policy<\/em><\/p>\n\n\n\n<p>Select \u201c<em>CloudWatch<\/em>\u201d as service in policy editor and pre-filter by typing \u201cputmetric\u201d in allowed actions field.<\/p>\n\n\n\n<p>Select \u201cEffect: Allow\u201d and write action \u201cPutMetricData\u201d<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-f63627ea wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-130828-1024x408.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-130828.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-130828.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-130828-1024x408.png\" alt=\"\" class=\"uag-image-9472\" width=\"850\" height=\"322\" title=\"image-20240321-130828\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Click \u201cNext\u201d.<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-17193805 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-130929-1024x576.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-130929.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-130929.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-130929-1024x576.png\" alt=\"\" class=\"uag-image-9474\" width=\"850\" height=\"455\" title=\"image-20240321-130929\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Click \u201c<em>Create policy<\/em>\u201d.<\/p>\n\n\n\n<p>Go back to \u2192 <em>Lambda<\/em> \u2192 <em>Configuration<\/em> Tab \u2192 <em>Permissions<\/em> Menu. You should be able to choose <em>CloudWatch<\/em> Service from the drop-down below <em>Resource summary<\/em>. If you do so, you should be able to see the allowed action as shown below:<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-74b3990a wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-131259.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-131259.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-131259.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-131259.png\" alt=\"\" class=\"uag-image-9476\" width=\"850\" height=\"507\" title=\"image-20240321-131259\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h6 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-7a327ce289a472e4037e867f5c98aeaf\" id=\"3.-Adapt-Python-Code\">3. Adapt Python Code<\/h6>\n\n\n\n<p>I used the hello-world example as template and adapted it to my needs in order to extract memory values from the health endpoint depending on the chosen input parameter (supported are \u201cfree\u201d and \u201cthreshold\u201d). Although the threshold is principally configurable, it should not change over time &#8211; unless we decide to adapt it after collecting some experience with our application\u2019s memory consumption).<\/p>\n\n\n\n<p>This is the resulting code:<\/p>\n\n\n\n<div class=\"wp-block-uagb-container uagb-block-221a23be alignfull uagb-is-root-container\"><div class=\"uagb-container-inner-blocks-wrap\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#24292e;--cbp-line-number-width:calc(3 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-encoded=\"true\" data-code=\"import%2520urllib.request%250Aimport%2520json%250Aimport%2520boto3%250Aimport%2520os%250A%250A%250Adef%2520get_memory()%253A%250A%2520%2520%2520%2520res%2520%253D%2520urllib.request.urlopen(urllib.request.Request(%250A%2520%2520%2520%2520%2520%2520%2520%2520url%253Dos.environ.get('HEALTH_ENDPOINT')%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520headers%253D%257B'Accept'%253A%2520'application%252Fjson'%257D%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520method%253D'GET')%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520timeout%253D5)%250A%2520%2520%2520%2520content%2520%253D%2520json.loads(res.read())%250A%2520%2520%2520%2520return%2520content%255B'components'%255D%255B'memory'%255D%255B'details'%255D%250A%250Adef%2520validation_error(message)%253A%250A%2520%2520%2520%2520return%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520'Error'%253A%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Code'%253A%2520'Validation'%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Value'%253A%2520message%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%257D%250A%2520%2520%2520%2520%257D%250A%250Adef%2520validate_get_metric_data_event(event)%253A%250A%2520%2520%2520%2520arguments%2520%253D%2520event%255B'GetMetricDataRequest'%255D%255B'Arguments'%255D%250A%250A%2520%2520%2520%2520if%2520len(arguments)%2520!%253D%25201%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520validation_error('Argument%2520count%2520must%2520be%25201')%250A%250A%2520%2520%2520%2520if%2520not%2520isinstance(arguments%255B0%255D%252C%2520str)%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520validation_error('Argument%25201%2520must%2520be%2520a%2520string')%250A%250A%2520%2520%2520%2520return%2520None%250A%250Adef%2520get_metric_data(event)%253A%250A%2520%2520%2520%2520validation_error%2520%253D%2520validate_get_metric_data_event(event)%250A%250A%2520%2520%2520%2520if%2520validation_error%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520validation_error%250A%250A%2520%2520%2520%2520metric_name%2520%253D%2520event%255B'GetMetricDataRequest'%255D%255B'Arguments'%255D%255B0%255D%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520print('metric%253A%2520'%2520%252B%2520metric_name)%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520memory%2520%253D%2520get_memory()%250A%2520%2520%2520%2520freeMem%2520%253D%2520memory%255B'free'%255D%250A%2520%2520%2520%2520threshold%2520%253D%2520memory%255B'threshold'%255D%250A%2520%2520%2520%2520value%2520%253D%25200%250A%2520%2520%2520%2520if%2520metric_name%2520%253D%253D%2520'free'%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520value%2520%253D%2520freeMem%250A%2520%2520%2520%2520elif%2520metric_name%2520%253D%253D%2520'threshold'%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520value%2520%253D%2520threshold%250A%2520%2520%2520%2520%2520%2520%2520%2520%250A%2520%2520%2520%2520cloudwatch%2520%253D%2520boto3.client('cloudwatch')%250A%2520%2520%2520%2520response%2520%253D%2520cloudwatch.put_metric_data(%250A%2520%2520%2520%2520%2520%2520%2520%2520MetricData%2520%253D%2520%255B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'MetricName'%253A%2520metric_name%2520%252B%2520'%2520memory'%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Dimensions'%253A%2520%255B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Name'%253A%2520'Metric'%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Value'%253A%2520'Memory%2520Usage'%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257D%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Name'%253A%2520'Version'%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Value'%253A%2520'1'%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257D%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%255D%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Unit'%253A%2520'Megabytes'%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520'Value'%253A%2520value%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257D%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%255D%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520Namespace%2520%253D%2520'FAA'%250A%2520%2520%2520%2520)%250A%2520%2520%2520%2520print('value%253A%2520'%2520%252B%2520str(value))%250A%2520%2520%2520%2520return%2520response%250A%250A%250Adef%2520describe_get_metric_data()%253A%250A%2520%2520%2520%2520description%2520%253D%2520f%2522%2522%2522%2523%2523%2520Custom%2520Metric%2520for%2520Memory%2520Usage%250A%250Areturns%2520memory%2520values%2520based%2520on%2520requested%2520input%2520(free%2520memory%252C%2520threshold)%250A%250A%2523%2523%2523%2520Query%2520arguments%250A%250A%255C%255C%2523%2520%257C%2520Type%2520%257C%2520Description%250A---%257C---%257C---%250A1%2520%257C%2520String%2520%257C%2520The%2520type%2520of%2520memory%2520(free%252C%2520threshold)%250A%250A%2523%2523%2523%2520Example%2520Expression%250A%250A%2560%2560%2560%250ALAMBDA('%257Bos.environ.get('AWS_LAMBDA_FUNCTION_NAME')%257D'%252C%2520'free')%250A%2560%2560%2560%250A%2522%2522%2522%250A%250A%2520%2520%2520%2520return%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520'ArgumentDefaults'%253A%2520%255B%257B'Value'%253A%2520'free'%257D%255D%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520'Description'%253A%2520description%250A%2520%2520%2520%2520%257D%250A%250A%250Adef%2520lambda_handler(event%252C%2520context)%253A%250A%2520%2520%2520%2520if%2520event%255B'EventType'%255D%2520%253D%253D%2520'GetMetricData'%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520get_metric_data(event)%250A%250A%2520%2520%2520%2520if%2520event%255B'EventType'%255D%2520%253D%253D%2520'DescribeGetMetricData'%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520describe_get_metric_data()%250A%250A%2520%2520%2520%2520return%2520validation_error('Invalid%2520event%2520type%253A%2520'%2520%252B%2520event%255B'EventType'%255D)%2520%250A\" style=\"color:#fff;display:none;background-color:#24292e\" aria-label=\"Copy\" data-copied-text=\"Copied!\" data-has-text-button=\"textSimple\" data-inside-header-type=\"none\" aria-live=\"polite\" class=\"code-block-pro-copy-button\"><span class=\"cbp-btn-text\">Copy<\/span><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> urllib.request<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> json<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> boto3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> os<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">def<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">get_memory<\/span><span style=\"color: #24292E\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    res <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> urllib.request.urlopen(urllib.request.Request(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">url<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">os.environ.get(<\/span><span style=\"color: #032F62\">&#39;HEALTH_ENDPOINT&#39;<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">headers<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">{<\/span><span style=\"color: #032F62\">&#39;Accept&#39;<\/span><span style=\"color: #24292E\">: <\/span><span style=\"color: #032F62\">&#39;application\/json&#39;<\/span><span style=\"color: #24292E\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">method<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&#39;GET&#39;<\/span><span style=\"color: #24292E\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">timeout<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #005CC5\">5<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    content <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> json.loads(res.read())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> content[<\/span><span style=\"color: #032F62\">&#39;components&#39;<\/span><span style=\"color: #24292E\">][<\/span><span style=\"color: #032F62\">&#39;memory&#39;<\/span><span style=\"color: #24292E\">][<\/span><span style=\"color: #032F62\">&#39;details&#39;<\/span><span style=\"color: #24292E\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">def<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">validation_error<\/span><span style=\"color: #24292E\">(message):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #032F62\">&#39;Error&#39;<\/span><span style=\"color: #24292E\">: {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #032F62\">&#39;Code&#39;<\/span><span style=\"color: #24292E\">: <\/span><span style=\"color: #032F62\">&#39;Validation&#39;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #032F62\">&#39;Value&#39;<\/span><span style=\"color: #24292E\">: message,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">def<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">validate_get_metric_data_event<\/span><span style=\"color: #24292E\">(event):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    arguments <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> event[<\/span><span style=\"color: #032F62\">&#39;GetMetricDataRequest&#39;<\/span><span style=\"color: #24292E\">][<\/span><span style=\"color: #032F62\">&#39;Arguments&#39;<\/span><span style=\"color: #24292E\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">len<\/span><span style=\"color: #24292E\">(arguments) <\/span><span style=\"color: #D73A49\">!=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">1<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> validation_error(<\/span><span style=\"color: #032F62\">&#39;Argument count must be 1&#39;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">not<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">isinstance<\/span><span style=\"color: #24292E\">(arguments[<\/span><span style=\"color: #005CC5\">0<\/span><span style=\"color: #24292E\">], <\/span><span style=\"color: #005CC5\">str<\/span><span style=\"color: #24292E\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> validation_error(<\/span><span style=\"color: #032F62\">&#39;Argument 1 must be a string&#39;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">None<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">def<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">get_metric_data<\/span><span style=\"color: #24292E\">(event):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    validation_error <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> validate_get_metric_data_event(event)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> validation_error:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> validation_error<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    metric_name <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> event[<\/span><span style=\"color: #032F62\">&#39;GetMetricDataRequest&#39;<\/span><span style=\"color: #24292E\">][<\/span><span style=\"color: #032F62\">&#39;Arguments&#39;<\/span><span style=\"color: #24292E\">][<\/span><span style=\"color: #005CC5\">0<\/span><span style=\"color: #24292E\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&#39;metric: &#39;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">+<\/span><span style=\"color: #24292E\"> metric_name)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    memory <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> get_memory()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    freeMem <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> memory[<\/span><span style=\"color: #032F62\">&#39;free&#39;<\/span><span style=\"color: #24292E\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    threshold <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> memory[<\/span><span style=\"color: #032F62\">&#39;threshold&#39;<\/span><span style=\"color: #24292E\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    value <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> metric_name <\/span><span style=\"color: #D73A49\">==<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&#39;free&#39;<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        value <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> freeMem<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">elif<\/span><span style=\"color: #24292E\"> metric_name <\/span><span style=\"color: #D73A49\">==<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&#39;threshold&#39;<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        value <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> threshold<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    cloudwatch <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> boto3.client(<\/span><span style=\"color: #032F62\">&#39;cloudwatch&#39;<\/span><span style=\"color: #24292E\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    response <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> cloudwatch.put_metric_data(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">MetricData<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                <\/span><span style=\"color: #032F62\">&#39;MetricName&#39;<\/span><span style=\"color: #24292E\">: metric_name <\/span><span style=\"color: #D73A49\">+<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&#39; memory&#39;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                <\/span><span style=\"color: #032F62\">&#39;Dimensions&#39;<\/span><span style=\"color: #24292E\">: [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                        <\/span><span style=\"color: #032F62\">&#39;Name&#39;<\/span><span style=\"color: #24292E\">: <\/span><span style=\"color: #032F62\">&#39;Metric&#39;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                        <\/span><span style=\"color: #032F62\">&#39;Value&#39;<\/span><span style=\"color: #24292E\">: <\/span><span style=\"color: #032F62\">&#39;Memory Usage&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                    },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                        <\/span><span style=\"color: #032F62\">&#39;Name&#39;<\/span><span style=\"color: #24292E\">: <\/span><span style=\"color: #032F62\">&#39;Version&#39;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                        <\/span><span style=\"color: #032F62\">&#39;Value&#39;<\/span><span style=\"color: #24292E\">: <\/span><span style=\"color: #032F62\">&#39;1&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                    },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                ],<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                <\/span><span style=\"color: #032F62\">&#39;Unit&#39;<\/span><span style=\"color: #24292E\">: <\/span><span style=\"color: #032F62\">&#39;Megabytes&#39;<\/span><span style=\"color: #24292E\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">                <\/span><span style=\"color: #032F62\">&#39;Value&#39;<\/span><span style=\"color: #24292E\">: value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            },<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        ],<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #E36209\">Namespace<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&#39;FAA&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #005CC5\">print<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&#39;value: &#39;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">+<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #005CC5\">str<\/span><span style=\"color: #24292E\">(value))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> response<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">def<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">describe_get_metric_data<\/span><span style=\"color: #24292E\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    description <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">f<\/span><span style=\"color: #032F62\">&quot;&quot;&quot;## Custom Metric for Memory Usage<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">returns memory values based on requested input (free memory, threshold)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">### Query arguments<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">\\\\<\/span><span style=\"color: #032F62\"># | Type | Description<\/span><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">---|---|---<\/span><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">1 | String | The type of memory (free, threshold)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">### Example Expression<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">```<\/span><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">LAMBDA(&#39;<\/span><span style=\"color: #005CC5\">{<\/span><span style=\"color: #24292E\">os.environ.get(<\/span><span style=\"color: #032F62\">&#39;AWS_LAMBDA_FUNCTION_NAME&#39;<\/span><span style=\"color: #24292E\">)<\/span><span style=\"color: #005CC5\">}<\/span><span style=\"color: #032F62\">&#39;, &#39;free&#39;)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">```<\/span><\/span>\n<span class=\"line\"><span style=\"color: #032F62\">&quot;&quot;&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #032F62\">&#39;ArgumentDefaults&#39;<\/span><span style=\"color: #24292E\">: [{<\/span><span style=\"color: #032F62\">&#39;Value&#39;<\/span><span style=\"color: #24292E\">: <\/span><span style=\"color: #032F62\">&#39;free&#39;<\/span><span style=\"color: #24292E\">}],<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #032F62\">&#39;Description&#39;<\/span><span style=\"color: #24292E\">: description<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">def<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">lambda_handler<\/span><span style=\"color: #24292E\">(event, context):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> event[<\/span><span style=\"color: #032F62\">&#39;EventType&#39;<\/span><span style=\"color: #24292E\">] <\/span><span style=\"color: #D73A49\">==<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&#39;GetMetricData&#39;<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> get_metric_data(event)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">if<\/span><span style=\"color: #24292E\"> event[<\/span><span style=\"color: #032F62\">&#39;EventType&#39;<\/span><span style=\"color: #24292E\">] <\/span><span style=\"color: #D73A49\">==<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&#39;DescribeGetMetricData&#39;<\/span><span style=\"color: #24292E\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> describe_get_metric_data()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> validation_error(<\/span><span style=\"color: #032F62\">&#39;Invalid event type: &#39;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">+<\/span><span style=\"color: #24292E\"> event[<\/span><span style=\"color: #032F62\">&#39;EventType&#39;<\/span><span style=\"color: #24292E\">]) <\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n<\/div><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The most interesting part is the construction of the <code><em>MetricData<\/em><\/code> and transferring it to CloudWatch (l. 55ff).<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h6 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-a753be36ffbc283ab2ba3b88ae89fd22\" id=\"4.-Test-the-implementation\">4. Test the implementation<\/h6>\n\n\n\n<p>By now, you should already be available to test your function. Below <em>Code<\/em> \u2192 <em>Code source<\/em>, choose <em>Test<\/em> \u2192 <em>Configure test event<\/em><\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-11ad15c0 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-111313.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-111313.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-111313.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-111313.png\" alt=\"\" class=\"uag-image-9478\" width=\"700\" height=\"596\" title=\"image-20240321-111313\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Simply ignore the template setting. Save. Click on test. The function should execute and output something similar to this:<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-468066d1 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-131559-1024x505.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-131559.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-131559.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-131559-1024x505.png\" alt=\"\" class=\"uag-image-9480\" width=\"850\" height=\"407\" title=\"image-20240321-131559\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Now we are ready to display the value on a graph.<\/p>\n\n\n\n<h5 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-7f31145e50158346abc9f9abf1fb7ed4\" id=\"Graph-custom-Metrics\">Graph custom Metrics<\/h5>\n\n\n\n<p>Go to AWS Console \u2192 CloudWatch \u2192 All Metrics and choose your metric (using the defined namespace might speed up things). Select the available metric from the list and you should see a dot representing the value. <\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-3dc13eaf wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134222-1024x458.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134222.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134222.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134222-1024x458.png\" alt=\"\" class=\"uag-image-9482\" width=\"850\" height=\"369\" title=\"image-20240321-134222\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>You can set the refresh interval to &#8211; for example &#8211; 1 minute in order to get a connected representation of the data after some time. Alternatively, you can select your metric via \u2192 <em>Multi source query<\/em> tab where you should be able to select the created data source:<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-ced0efc5 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134506-1024x413.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134506.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134506.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134506-1024x413.png\" alt=\"\" class=\"uag-image-9484\" width=\"700\" height=\"266\" title=\"image-20240321-134506\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>After doing so, AWS should also display the documentation from your lambda code and support you with providing arguments to customize your function\u2019s response value.<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-aeafaaf8 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134538-1024x443.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134538.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134538.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-134538-1024x443.png\" alt=\"\" class=\"uag-image-9486\" width=\"850\" height=\"350\" title=\"image-20240321-134538\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>However, this solution has a clear disadvantage (as already mentioned at the beginning of the post): We do not get historical data. How to achieve that will be described in the next chapter.<\/p>\n\n\n\n<h5 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-a6752bd945c61488da7efb7e97f0e5e0\" id=\"Trigger-Lambda-function-periodically\">Trigger Lambda function periodically<\/h5>\n\n\n\n<p>In order to get historical data (that means: get past data no matter when we want to display memory information), we need to trigger our Lambda function periodically. We can do this by using AWS EventBridge.<\/p>\n\n\n\n<p>Go to AWS Console \u2192 <em>Lambda<\/em> \u2192 <em>Add trigger<\/em> button<\/p>\n\n\n\n<p>Choose \u201c<em>EventBridge<\/em>\u201d as source, select \u201c<em>Create a new rule<\/em>\u201d and add name and description (e.g. \u201c<em>every-10-min<\/em>\u201d \/ \u201c<em>execute every 10 minutes<\/em>\u201d). Select \u201c<em>Schedule expression<\/em>\u201d as rule type and enter the periodicity, e.g. <em>rate(10 minutes)<\/em> [4]. If you need more sophisticated execution times, you can also specify a cron expression [5].<\/p>\n\n\n\n<p>Now, we need to adapt the EventBridge configuration as we need to customize the event being sent to our Lambda function. Go to <em>Lambda<\/em> \u2192 <em>Configuration<\/em> \u2192 <em>Triggers<\/em> menu (left side). On the shown trigger, click on the \u201cevery-10-min\u201d rule (alternatively, open via \u2192 <em>EventBridge<\/em> \u2192 <em>Rules<\/em> \u2192 { <em>your rule<\/em> }. Click on \u2192 <em>Targets<\/em> tab \u2192 <em>Edit<\/em>.<\/p>\n\n\n\n<p>Scroll to \u201c<em>Additional Settings<\/em>\u201d, select JSON as target input and paste the JSON from the Lambda\u2019s test event configuration.<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-41c482e8 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-144958-1024x438.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-144958.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-144958.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-144958-1024x438.png\" alt=\"\" class=\"uag-image-9488\" width=\"768\" height=\"328\" title=\"image-20240321-144958\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Click through the confirmation buttons to finally update your rule.<\/p>\n\n\n\n<p>Check functionality by looking at the lambda\u2019s CloudWatch logs (\u2192 <em>CloudWatch<\/em> \u2192 <em>Log groups<\/em> (below \u201cLogs\u201d) \u2192 <em>\/aws\/lambda\/{your lambda function name} \u2192 <\/em>select most recent log stream\u2026)<\/p>\n\n\n\n<p>If you still see an error like this<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-background-color has-background\"><code>&#91;ERROR] KeyError: 'EventType' Traceback (most recent call last): &nbsp;&nbsp;File \"\/var\/task\/memory\/lambda_function.py\"<\/code><\/pre>\n\n\n\n<p>for most recent call, then your event trigger was not updated correctly, log output should look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-background-color has-background\"><code>2024-03-21T15:00:04.687Z START RequestId: e5fa24e1-5d03-4e95-8494-f441705722ca Version: $LATEST\n2024-03-21T15:00:04.688Z metric: free\n2024-03-21T15:00:07.487Z value: 785\n2024-03-21T15:00:07.528Z END RequestId: e5fa24e1-5d03-4e95-8494-f441705722ca<\/code><\/pre>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h5 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-3f189115c38516a4762969efbacad3a6\" id=\"Show-Memory-Usage-on-a-Dashboard\">Show Memory Usage on a Dashboard<\/h5>\n\n\n\n<p>To make our achievements a round experience, we will create a new dashboard being shown on the CloudWatch overview page so we can quickly access our memory trend.<\/p>\n\n\n\n<p>This last step is fairly easy. Just go to \u2192 <em>CloudWatch<\/em> \u2192 <em>Dashboards<\/em> \u2192 <em>Create dashboard<\/em>. Choose \u201cCloudWatch-Default\u201d as name (then it will automatically be shown on the overview page).<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u201c<em>CloudWatch<\/em>\u201d as data source type<\/li>\n\n\n\n<li>\u201c<em>Metrics<\/em>\u201d as data type<\/li>\n\n\n\n<li>\u201c<em>Line<\/em>\u201d as widget type (or whatever suits your needs)<\/li>\n\n\n\n<li>In \u201c<em>Add metric graph<\/em>\u201d choose our metric<\/li>\n\n\n\n<li><em>Options<\/em> tab \u2192 <em>Left Y axis<\/em> \u2192 <em>Limits Min<\/em> \u2192 0<\/li>\n\n\n\n<li>Create widget<\/li>\n<\/ul>\n\n\n\n<p>After collecting enough data, you might see something like in our case where memory is steadily consumed by background processes and then gets cleaned up at some point by the garbage collector.<\/p>\n\n\n\n<div class=\"wp-block-uagb-image aligncenter uagb-block-a7810631 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center\"><figure class=\"wp-block-uagb-image__figure\"><img decoding=\"async\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-151819.png ,https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-151819.png 780w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-151819.png 360w\" sizes=\"(max-width: 480px) 150px\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/image-20240321-151819.png\" alt=\"\" class=\"uag-image-9490\" width=\"850\" height=\"550\" title=\"image-20240321-151819\" loading=\"lazy\" role=\"img\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading has-ast-global-color-7-color has-text-color has-link-color wp-elements-a37708b94b7e6f7a5ab25b7ad60fea43\" id=\"Links\">Links<\/h4>\n\n\n\n<p>[1] &#8211; Sending CloudWatch Custom Metrics From Lambda &#8211; <a href=\"https:\/\/stackify.com\/custom-metrics-aws-lambda\/\">https:\/\/stackify.com\/custom-metrics-aws-lambda\/<\/a><\/p>\n\n\n\n<p>[2] &#8211; Connect to a prebuilt data source with a wizard &#8211; <a href=\"https:\/\/docs.aws.amazon.com\/AmazonCloudWatch\/latest\/monitoring\/CloudWatch_MultiDataSources-Connect.html\">https:\/\/docs.aws.amazon.com\/AmazonCloudWatch\/latest\/monitoring\/CloudWatch_MultiDataSources-Connect.html<\/a><\/p>\n\n\n\n<p>[3] &#8211; Graph a metric &#8211; <a href=\"https:\/\/docs.aws.amazon.com\/AmazonCloudWatch\/latest\/monitoring\/graph_a_metric.html\">https:\/\/docs.aws.amazon.com\/AmazonCloudWatch\/latest\/monitoring\/graph_a_metric.html<\/a><\/p>\n\n\n\n<p>[4] &#8211; Rate expressions &#8211; <a href=\"https:\/\/docs.aws.amazon.com\/eventbridge\/latest\/userguide\/eb-rate-expressions.html\">https:\/\/docs.aws.amazon.com\/eventbridge\/latest\/userguide\/eb-rate-expressions.html<\/a><\/p>\n\n\n\n<p>[5] &#8211; Cron expressions &#8211; <a href=\"https:\/\/docs.aws.amazon.com\/eventbridge\/latest\/userguide\/eb-cron-expressions.html\">https:\/\/docs.aws.amazon.com\/eventbridge\/latest\/userguide\/eb-cron-expressions.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Preface \/ Motivation Recently, our production environment became unreachable due to our (Kotlin) application using up all available JVM memory. As up to then we did [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":9508,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[76,121,122,117,118],"tags":[568,572,571,569,570],"class_list":["post-9461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code","category-code-analysis","category-code-quality","category-tips","category-tools","tag-aws","tag-consumption","tag-memory","tag-monitor","tag-monitoring"],"uagb_featured_image_src":{"full":["https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/Monitor-Memory-Consumption-on-AWS.png",1100,350,false],"thumbnail":["https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/Monitor-Memory-Consumption-on-AWS-150x150.png",150,150,true],"medium":["https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/Monitor-Memory-Consumption-on-AWS-300x95.png",300,95,true],"medium_large":["https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/Monitor-Memory-Consumption-on-AWS-768x244.png",768,244,true],"large":["https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/Monitor-Memory-Consumption-on-AWS-1024x326.png",1024,326,true],"1536x1536":["https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/Monitor-Memory-Consumption-on-AWS.png",1100,350,false],"2048x2048":["https:\/\/www.viaboxx.de\/wp-content\/uploads\/2024\/03\/Monitor-Memory-Consumption-on-AWS.png",1100,350,false]},"uagb_author_info":{"display_name":"Maurice Jutkeit","author_link":"https:\/\/www.viaboxx.de\/en\/blog\/author\/maurice-jutkeitviaboxx-de\/"},"uagb_comment_info":19,"uagb_excerpt":"Preface \/ Motivation Recently, our production environment became unreachable due to our (Kotlin) application using up all available JVM memory. As up to then we did [&hellip;]","_links":{"self":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/9461"}],"collection":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/comments?post=9461"}],"version-history":[{"count":9,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/9461\/revisions"}],"predecessor-version":[{"id":9569,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/9461\/revisions\/9569"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/media\/9508"}],"wp:attachment":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/media?parent=9461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/categories?post=9461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/tags?post=9461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}