-
Notifications
You must be signed in to change notification settings - Fork 103
Update Lambda logging configuration to use non-deprecated AWS CDK properties #2968
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
base: main
Are you sure you want to change the base?
Changes from all commits
58db34b
259e15b
a7543da
89c9e5e
b8481a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@aws-amplify/backend-function': patch | ||
| --- | ||
|
|
||
| Update lambda logging configuration to use non-deprecated AWS CDK properties |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -654,7 +654,7 @@ void describe('AmplifyFunctionFactory', () => { | |
| }); | ||
|
|
||
| void describe('logging options', () => { | ||
| void it('sets logging options', () => { | ||
| void it('sets logging options with log group', () => { | ||
| const lambda = defineFunction({ | ||
| entry: './test-assets/default-lambda/handler.ts', | ||
| bundling: { | ||
|
|
@@ -667,15 +667,14 @@ void describe('AmplifyFunctionFactory', () => { | |
| }, | ||
| }).getInstance(getInstanceProps); | ||
| const template = Template.fromStack(lambda.stack); | ||
| // Enabling log retention adds extra lambda. | ||
| template.resourceCountIs('AWS::Lambda::Function', 2); | ||
| const lambdas = template.findResources('AWS::Lambda::Function'); | ||
| assert.ok( | ||
| Object.keys(lambdas).some((key) => key.startsWith('LogRetention')), | ||
| ); | ||
| template.hasResourceProperties('Custom::LogRetention', { | ||
|
|
||
| // We now create a LogGroup directly rather than using the deprecated logRetention | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove references to replacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @nsteffens, |
||
| template.resourceCountIs('AWS::Logs::LogGroup', 1); | ||
| template.hasResourceProperties('AWS::Logs::LogGroup', { | ||
| RetentionInDays: 400, | ||
| }); | ||
|
|
||
| // The function should use the applicationLogLevelV2 and loggingFormat properties | ||
| template.hasResourceProperties('AWS::Lambda::Function', { | ||
| Handler: 'index.handler', | ||
| LoggingConfig: { | ||
|
|
@@ -684,6 +683,32 @@ void describe('AmplifyFunctionFactory', () => { | |
| }, | ||
| }); | ||
| }); | ||
|
|
||
| void it('sets logging options without retention', () => { | ||
| const lambda = defineFunction({ | ||
| entry: './test-assets/default-lambda/handler.ts', | ||
| bundling: { | ||
| minify: false, | ||
| }, | ||
| logging: { | ||
| format: 'json', | ||
| level: 'info', | ||
| }, | ||
| }).getInstance(getInstanceProps); | ||
| const template = Template.fromStack(lambda.stack); | ||
|
|
||
| // No log group should be created when retention is not specified | ||
| template.resourceCountIs('AWS::Logs::LogGroup', 0); | ||
|
|
||
| // The function should still have logging config | ||
| template.hasResourceProperties('AWS::Lambda::Function', { | ||
| Handler: 'index.handler', | ||
| LoggingConfig: { | ||
| ApplicationLogLevel: 'INFO', | ||
| LogFormat: 'JSON', | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| void describe('resourceAccessAcceptor', () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the changeset should also include a patch bump to
@aws-amplify/backend(this is why the changesets test is failing), for some additional context see my comment here: #2968 (comment)