-
Notifications
You must be signed in to change notification settings - Fork 74
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
catch errors during secret refreshes #2438
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: e985e64 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
// Catch errors and do nothing in the case we are retrieving secrets when the Lambda starts shutting down | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
void internalAmplifyFunctionResolveSsmParams().catch(() => {}); |
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.
Two things.
- Can we try-catch inside
internalAmplifyFunctionResolveSsmParams
? - Should we at least
console.debug
this ?
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.
Re 1. Peharps we don't because we want lambda to crash at cold start.
But maybe there's some way to have normal try catch here ?
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.
For 1, yeah we would want it to crash at cold start, just not for subsequent SSM calls. I'll look into having this as a normal try catch so we can remove the eslint comment.
For 2, any logging would cause an EPIPE
error in the scenario for this error.
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.
For 2, any logging would cause an EPIPE error in the scenario for this error.
Unless... we try-catch logger as well.
The thing I'm worried about is that empty catch block will eat legit errors that are not due to shutdown.
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.
But maybe there's some way to have normal try catch here ?
Seems like it's not possible, tried doing
setInterval(() => {
try {
void internalAmplifyFunctionResolveSsmParams();
} catch (error) {
// Catch errors and do nothing in the case we are retrieving secrets when the Lambda starts shutting down
}
}, SSM_PARAMETER_REFRESH_MS);
and Lambda doesn't seem to handle top level try catch gracefully and gives us the original error.
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.
you would need this
setInterval(async () => {
try {
await internalAmplifyFunctionResolveSsmParams();
} catch (error) {
// Catch errors and do nothing in the case we are retrieving secrets when the Lambda starts shutting down
}
}, SSM_PARAMETER_REFRESH_MS);
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.
setInterval(void (async () => {
try {
await internalAmplifyFunctionResolveSsmParams();
} catch (error) {
// Catch errors and do nothing in the case we are retrieving secrets when the Lambda starts shutting down
}
}), SSM_PARAMETER_REFRESH_MS);
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.
...I may still be in weekend mode, of course it has to be like this.
306fd62
// eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
setInterval(async () => { | ||
try { | ||
await internalAmplifyFunctionResolveSsmParams(); | ||
} catch (error) { | ||
try { | ||
// Attempt to log error | ||
// eslint-disable-next-line no-console | ||
console.debug(error); | ||
// eslint-disable-next-line amplify-backend-rules/no-empty-catch | ||
} catch (error) { | ||
// Do nothing if logging fails | ||
} | ||
} |
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 feels bad to add this many eslint-disable-next-line
(especially the first one, tried several things but couldn't get them to work), are there any other alternatives?
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.
@rtpascual have you tried this one #2438 (comment) ? (my suggestion differs from @Amplifiyer 's a bit - void
and extra bracket, the misused promise is expected in this case that syntax expresses it.)
for second one we should add file like this to lambda-shims
folder /~https://github.com/aws-amplify/amplify-backend/blob/main/packages/backend-auth/src/lambda/.eslintrc.json
Last one, we can't solve so that one remains.
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.
Missed the differences in your suggestion, updated!
Problem
For long running Lambda functions, there may be times when our SSM shim which gets secret values is running when the Lambda starts shutting down causing errors like:
Issue number, if available:
Changes
Catch errors on subsequent calls to get secrets and do nothing so the Lambda function can shutdown gracefully.
Corresponding docs PR, if applicable:
Validation
Lambda deployed to my account that is running on a schedule every minute:
Error spikes are the error message mentioned above.
Checklist
run-e2e
label set.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.