Skip to content

Commit

Permalink
feat(lambda): support for advanced logging (#28039)
Browse files Browse the repository at this point in the history
Structured logging enables automated analysis of the logs, thus enables customers to perform quick exploratory and automated monitoring the health of their applications, and helps them troubleshoot their production issues faster. Structured logging is now considered to be a monitoring best practice.

Lambda is developing Advance Logging Controls to give developers and operators more control over their function logs. The feature allows customers to capture logs in JSON format and control the level of details in emitted logs. To ensure compatibility and enable these capabilities, four new fields (LogFormat, ApplicationLogLevel, SystemLogLevel, and LogGroup) will be added to the existing LoggingConfig structure. Also, even adding custom log group for Log group section to have the flexibility of changing the name instead of having it as default. This update empowers customers to define their logging behavior and efficiently manage their function logs, reflecting Lambda's commitment to delivering a user-friendly logging solution that addresses the evolving needs of users.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
otaviomacedo authored Nov 16, 2023
1 parent 1d1876c commit 3278c19
Show file tree
Hide file tree
Showing 13 changed files with 2,101 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
{
"Resources": {
"MyLogGroupWithLogGroupNameB577EB65": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "customLogGroup",
"RetentionInDays": 731
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"LambdaWithLogGroupServiceRoleC5DDB031": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"LambdaWithLogGroupC3B62A1A": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "foo"
},
"Handler": "index.handler",
"LoggingConfig": {
"LogGroup": {
"Ref": "MyLogGroupWithLogGroupNameB577EB65"
}
},
"Role": {
"Fn::GetAtt": [
"LambdaWithLogGroupServiceRoleC5DDB031",
"Arn"
]
},
"Runtime": "nodejs18.x"
},
"DependsOn": [
"LambdaWithLogGroupServiceRoleC5DDB031"
]
},
"MyLogGroupWithoutLogGroupName385E46B7": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"RetentionInDays": 731
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"LambdaWithLogGroupAndNoLogGroupNameServiceRoleFEE6AF87": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"LambdaWithLogGroupAndNoLogGroupName1F5C7375": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "foo"
},
"Handler": "index.handler",
"LoggingConfig": {
"LogGroup": {
"Ref": "MyLogGroupWithoutLogGroupName385E46B7"
}
},
"Role": {
"Fn::GetAtt": [
"LambdaWithLogGroupAndNoLogGroupNameServiceRoleFEE6AF87",
"Arn"
]
},
"Runtime": "nodejs18.x"
},
"DependsOn": [
"LambdaWithLogGroupAndNoLogGroupNameServiceRoleFEE6AF87"
]
},
"LambdaWithTextFormatServiceRoleABCC0E93": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"LambdaWithTextFormatA0EDE227": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "foo"
},
"Handler": "index.handler",
"LoggingConfig": {
"LogFormat": "Text"
},
"Role": {
"Fn::GetAtt": [
"LambdaWithTextFormatServiceRoleABCC0E93",
"Arn"
]
},
"Runtime": "nodejs18.x"
},
"DependsOn": [
"LambdaWithTextFormatServiceRoleABCC0E93"
]
},
"LambdaWithJSONFormatServiceRole37FFB486": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"LambdaWithJSONFormat20E01C00": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "foo"
},
"Handler": "index.handler",
"LoggingConfig": {
"LogFormat": "JSON"
},
"Role": {
"Fn::GetAtt": [
"LambdaWithJSONFormatServiceRole37FFB486",
"Arn"
]
},
"Runtime": "nodejs18.x"
},
"DependsOn": [
"LambdaWithJSONFormatServiceRole37FFB486"
]
},
"LambdaWithLogLevelServiceRole90A45743": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"LambdaWithLogLevelCBBBEFFC": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "foo"
},
"Handler": "index.handler",
"LoggingConfig": {
"ApplicationLogLevel": "INFO",
"LogFormat": "JSON",
"SystemLogLevel": "INFO"
},
"Role": {
"Fn::GetAtt": [
"LambdaWithLogLevelServiceRole90A45743",
"Arn"
]
},
"Runtime": "nodejs18.x"
},
"DependsOn": [
"LambdaWithLogLevelServiceRole90A45743"
]
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3278c19

Please sign in to comment.