{"pageProps":{"post":{"mdxSource":"var Component=(()=>{var u=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},r=(t,e,n,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of h(e))!p.call(t,i)&&i!==n&&s(t,i,{get:()=>e[i],enumerable:!(a=d(e,i))||a.enumerable});return t};var w=(t,e,n)=>(n=t!=null?u(m(t)):{},r(e||!t||!t.__esModule?s(n,\"default\",{value:t,enumerable:!0}):n,t)),v=t=>r(s({},\"__esModule\",{value:!0}),t);var c=f((x,l)=>{l.exports=_jsx_runtime});var L={};b(L,{default:()=>C,frontmatter:()=>y});var o=w(c()),y={slug:\"custom-cloudwatch-log-groups-lambda\",date:new Date(17001792e5),title:\"Streamlining AWS Lambda logging with custom CloudWatch log groups\",tags:[\"AWS\",\"Lambda\",\"CloudWatch\"],summary:\"Lambda functions can now log to custom CloudWatch log groups, keep reading to learn more.\",authors:[\"tlakomy\"]};function g(t){let e=Object.assign({p:\"p\",strong:\"strong\",a:\"a\",code:\"code\",div:\"div\",blockquote:\"blockquote\"},t.components),{Image:n}=e;return n||W(\"Image\",!0),(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.strong,{children:\"Finally!\"}),\" \",(0,o.jsx)(e.a,{href:\"https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/\",children:\"AWS has recently announced\"}),\" support for custom CloudWatch log groups for Lambda functions. For me the biggest benefit is being able to stream logs from multiple related functions into a single log group. This is especially useful when trying to \",(0,o.jsx)(e.a,{href:\"https://cloudash.dev/blog/cloudwatch-logs-insights-examples/\",children:\"investigate an issue using CloudWatch Logs Insights\"}),\".\"]}),`\n`,(0,o.jsxs)(e.p,{children:[\"Previously, Lambda functions were restricted to logging in pre-defined log groups with the format \",(0,o.jsx)(e.code,{children:\"/aws/lambda/\"}),\". This limitation made it challenging to aggregate logs from multiple functions. The latest update changes this, enabling users to select custom CloudWatch log groups. This means logs from various functions can now be aggregated into a single, shared log group.\"]}),`\n`,(0,o.jsx)(e.div,{children:(0,o.jsx)(n,{alt:\"A screenshot showing custom log group configuration\",src:\"/assets/blog/images/lambda-custom-log-group.png\",width:\"849\",height:\"999\"})}),`\n`,(0,o.jsx)(e.p,{children:\"As we can see in the screenshot above, if the log group doesn't exist, it will be created automatically whenever a function is invoked for the first time after applying this setting.\"}),`\n`,(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.a,{href:\"https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/\",children:\"According to the launch blogpost\"}),\" one of the key benefits of this update is the ability to apply security, governance, and retention policies at the application level. This is a big step up from the previous need to set policies individually for each function, simplifying the management process, especially for applications with multiple Lambda functions.\"]}),`\n`,(0,o.jsx)(e.div,{children:(0,o.jsx)(n,{alt:\"A screenshot showing custom log group configuration\",src:\"/assets/blog/images/lambda-custom-log-group-2.png\",width:\"792\",height:\"274\"})}),`\n`,(0,o.jsx)(e.p,{children:\"In shared log groups, each log stream is now tagged with the Lambda function\\u2019s name and version.\"}),`\n`,(0,o.jsxs)(e.p,{children:[\"To leverage this new feature, Lambda functions must have \",(0,o.jsx)(e.code,{children:\"logs:CreateLogStream\"}),\" and \",(0,o.jsx)(e.code,{children:\"logs:PutLogEvents\"}),\" permissions in their IAM policy. These permissions are crucial for allowing functions to create logs in the specified log groups. When using the AWS Console this will happen automatically, but might require a bit more work when using IaC (as you should!)\"]}),`\n`,(0,o.jsxs)(e.blockquote,{children:[`\n`,(0,o.jsx)(e.p,{children:\"Advanced logging controls for Lambda can be configured using Lambda API, AWS Management Console, AWS Command Line Interface (CLI), and infrastructure as code (IaC) tools such as AWS Serverless Application Model (AWS SAM) and AWS CloudFormation.\"}),`\n`]}),`\n`,(0,o.jsx)(e.p,{children:\"At the time of writing this feature seems not to be supported by CDK, although I'm suspecting it's only a matter of time.\"}),`\n`,(0,o.jsx)(e.p,{children:\"To sum up - more of this AWS, please! \\u{1F64F}\"})]})}function A(t={}){let{wrapper:e}=t.components||{};return e?(0,o.jsx)(e,Object.assign({},t,{children:(0,o.jsx)(g,t)})):g(t)}var C=A;function W(t,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return v(L);})();\n;return Component;","frontmatter":{"slug":"custom-cloudwatch-log-groups-lambda","date":"2023-11-17T00:00:00.000Z","title":"Streamlining AWS Lambda logging with custom CloudWatch log groups","tags":["AWS","Lambda","CloudWatch"],"summary":"Lambda functions can now log to custom CloudWatch log groups, keep reading to learn more.","authors":["tlakomy"],"fileName":"custom-cloudwatch-log-groups-lambda.mdx"}},"authors":[{"name":"Tomasz Łakomy","avatar":"/assets/blog/authors/tomasz.jpeg","twitter":"https://twitter.com/tlakomy","slug":["tlakomy"],"fileName":"tlakomy.md","date":null}],"prev":{"fileName":"lambda-internal-extensions.mdx","slug":"lambda-internal-extensions","date":"2023-11-16T00:00:00.000Z","title":"Overview of AWS Lambda internal extensions","tags":["AWS","Lambda"],"summary":"AWS Lambda supports both internal and external extensions. In this article we'll take a look at internal extensions and how to use them.","authors":["tlakomy"]},"next":{"fileName":"cloudfront-functions-lambda-at-edge-differences.mdx","slug":"cloudfront-functions-lambda-at-edge-differences","title":"CloudFront Functions vs. Lambda@Edge: what's the difference?","date":"2023-11-22T00:00:00.000Z","summary":"AWS CloudFront Functions and Lambda@Edge are simillar, but different! Let's compare those two services.","tags":["AWS","CloudFront","Lambda@Edge","Serverless"],"authors":["tlakomy"]}},"__N_SSG":true}