Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AWS Lambda): Support loggingConfig #12315

Open
wants to merge 5 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/providers/aws/guide/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,21 @@ functions:
ephemeralStorageSize: 1024
```

## Logging Configuration

[Configuring Lambda advanced logging options](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced)

```yml
functions:
helloLogging:
handler: handler.handler
loggingConfig:
applicationLogLevel: DEBUG
logFormat: JSON
logGroup: helloLoggingLogGroup
systemLogLevel: DEBUG
```

## Lambda Hashing Algorithm migration

**Note** Below migration guide is intended to be used if you are already using `v3` version of the Framework and you have `provider.lambdaHashingVersion` property set to `20200924` in your configuration file. If you are still on v2 and want to upgrade to v3, please refer to [V3 Upgrade docs](../../../guides/upgrading-v3.md#lambda-hashing-algorithm).
Expand Down
6 changes: 6 additions & 0 deletions docs/providers/aws/guide/serverless.yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ functions:
maximumRetryAttempts: 1
# Maximum event age in seconds when invoking asynchronously (between 60 and 21600)
maximumEventAge: 7200
# Configuring Lambda advanced logging options
loggingConfig:
applicationLogLevel: DEBUG
logFormat: JSON
logGroup: helloLoggingLogGroup
systemLogLevel: DEBUG
```

## Lambda events
Expand Down
24 changes: 24 additions & 0 deletions lib/plugins/aws/package/compile/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,30 @@ class AwsCompileFunctions {
}
}

if (functionObject.loggingConfig) {
const loggingConfig = {};

if (functionObject.loggingConfig.applicationLogLevel) {
loggingConfig.ApplicationLogLevel = functionObject.loggingConfig.applicationLogLevel;
}

if (functionObject.loggingConfig.logFormat) {
loggingConfig.LogFormat = functionObject.loggingConfig.logFormat;
}

if (functionObject.loggingConfig.logGroup) {
loggingConfig.LogGroup = functionObject.loggingConfig.logGroup;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, Serverless also provisions the Log Group itself as part of it's cloudformation stack. At that stage, the custom log group name also needs to be checked.

}

if (functionObject.loggingConfig.systemLogLevel) {
loggingConfig.SystemLogLevel = functionObject.loggingConfig.systemLogLevel;
}

if (Object.keys(loggingConfig).length) {
functionResource.Properties.LoggingConfig = loggingConfig;
}
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be more compact as:

if (functionObject.loggingConfig) {
  const loggingConfig = {};

  ({
    ApplicationLogLevel: loggingConfig.applicationLogLevel,
    LogFormat: loggingConfig.logFormat,
    LogGroup: loggingConfig.logGroup,
    SystemLogLevel: loggingConfig.systemLogLevel,
  } = functionObject.loggingConfig);

  functionResource.Properties.LoggingConfig = Object.keys(loggingConfig).length ? loggingConfig : undefined;
}

this.compileFunctionUrl(functionName);
this.compileFunctionEventInvokeConfig(functionName);
}
Expand Down
13 changes: 13 additions & 0 deletions lib/plugins/aws/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,19 @@ class AwsProvider {
disableLogs: { type: 'boolean' },
environment: { $ref: '#/definitions/awsLambdaEnvironment' },
ephemeralStorageSize: { type: 'integer', minimum: 512, maximum: 10240 },
loggingConfig: {
type: 'object',
properties: {
applicationLogLevel: {
type: 'string',
enum: ['DEBUG', 'ERROR', 'FATAL', 'INFO', 'TRACE', 'WARN'],
},
logFormat: { type: 'string', enum: ['JSON', 'Text'] },
logGroup: { type: 'string', pattern: '^[.-_/#A-Za-z0-9]{1,512}$' },
systemLogLevel: { type: 'string', enum: ['DEBUG', 'INFO', 'WARN'] },
},
additionalProperties: false,
},
fileSystemConfig: {
type: 'object',
properties: {
Expand Down