-
Notifications
You must be signed in to change notification settings - Fork 86
Functions logging #2245
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
Functions logging #2245
Changes from all commits
17056f0
0cfba52
367ae90
49fe924
20615b0
3a90b89
63f89d6
1699eed
add274e
05291c7
b181192
f735ed8
f56b52a
8bf43ce
0e3659e
6d6c3dd
23a7409
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,9 @@ | ||
--- | ||
'@aws-amplify/ai-constructs': minor | ||
'@aws-amplify/backend-ai': minor | ||
'@aws-amplify/backend-function': minor | ||
'@aws-amplify/backend': minor | ||
'@aws-amplify/platform-core': minor | ||
--- | ||
|
||
Add options to control log settings |
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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { | ||
ConversationHandlerFunctionFactory, | ||
ConversationHandlerFunctionLogLevel, | ||
ConversationHandlerFunctionLogRetention, | ||
ConversationHandlerFunctionLoggingOptions, | ||
DefineConversationHandlerFunctionProps, | ||
defineConversationHandlerFunction, | ||
} from './factory.js'; | ||
|
||
export { | ||
ConversationHandlerFunctionFactory, | ||
ConversationHandlerFunctionLogLevel, | ||
ConversationHandlerFunctionLogRetention, | ||
ConversationHandlerFunctionLoggingOptions, | ||
DefineConversationHandlerFunctionProps, | ||
defineConversationHandlerFunction, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,6 +440,39 @@ void describe('AmplifyFunctionFactory', () => { | |
}); | ||
}); | ||
|
||
void describe('logging options', () => { | ||
void it('sets logging options', () => { | ||
const lambda = defineFunction({ | ||
entry: './test-assets/default-lambda/handler.ts', | ||
bundling: { | ||
minify: false, | ||
}, | ||
logging: { | ||
format: 'json', | ||
level: 'warn', | ||
retention: '13 months', | ||
}, | ||
}).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')) | ||
); | ||
Comment on lines
+460
to
+462
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. no way to assert the actual retention period? 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. I'll double check. 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. I found something. added below. |
||
template.hasResourceProperties('Custom::LogRetention', { | ||
RetentionInDays: 400, | ||
}); | ||
template.hasResourceProperties('AWS::Lambda::Function', { | ||
Handler: 'index.handler', | ||
LoggingConfig: { | ||
ApplicationLogLevel: 'WARN', | ||
LogFormat: 'JSON', | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
void describe('resourceAccessAcceptor', () => { | ||
void it('attaches policy to execution role and configures ssm environment context', () => { | ||
const functionFactory = defineFunction({ | ||
|
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.
Is it possible to avoid creating this extra lambda by creating the logGroup ourselves https://repost.aws/questions/QUzCgY0gSIQNGHZc6frGcI7g/log-retention-lambda#ANwKiEC22QQ-uV0r5yi0JdBQ?
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.
This has been tried and adopted in conversation handler.
However, it was easier there because it was a new thing.
Here the problem space is constrained in such a way that:
I wanted to avoid destructive changes, so I pursued a solution based on this extra lambda.
I think the proper solution to expose log group knobs would be to add another alternative to
LoggingOptions
in the future where we{..existing...} | { logGroupKnobs }
.wdyt ?
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.
Sounds good, at least it's only one extra function for all customer defined lambda functions.