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

fix(lambda): configuring log retention fails on 70+ Lambdas #31340

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface LogRetentionEvent extends Omit<AWSLambda.CloudFormationCustomResourceE
SdkRetry?: {
maxRetries?: string;
};
RemovalPolicy?: string
RemovalPolicy?: string;
};
}

Expand Down Expand Up @@ -91,7 +91,7 @@ export async function handler(event: LogRetentionEvent, context: AWSLambda.Conte
const logGroupRegion = event.ResourceProperties.LogGroupRegion;

// Parse to AWS SDK retry options
const maxRetries = parseIntOptional(event.ResourceProperties.SdkRetry?.maxRetries) ?? 5;
const maxRetries = parseIntOptional(event.ResourceProperties.SdkRetry?.maxRetries) ?? 10;
const withDelay = makeWithDelay(maxRetries);

const sdkConfig: Logs.CloudWatchLogsClientConfig = {
Expand Down Expand Up @@ -188,8 +188,8 @@ function parseIntOptional(value?: string, base = 10): number | undefined {

function makeWithDelay(
maxRetries: number,
delayBase: number = 100,
delayCap = 10 * 1000, // 10s
delayBase: number = 1_000,
delayCap = 60_000, // 60s
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: PR description says you cap at 10s, but this says 60s.

): (block: () => Promise<void>) => Promise<void> {
// If we try to update the log group, then due to the async nature of
// Lambda logging there could be a race condition when the same log group is
Expand Down Expand Up @@ -224,5 +224,5 @@ function makeWithDelay(
}

function calculateDelay(attempt: number, base: number, cap: number): number {
return Math.round(Math.random() * Math.min(cap, base * 2 ** attempt));
return Math.min(Math.round(Math.random() * base * 2 ** attempt), cap);
}
Loading