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(integ): fix rate limit errors when deploying cloudwatch log group… #827

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -8,6 +8,7 @@ import {
Stage,
ThinkboxDockerRecipes,
} from 'aws-rfdk/deadline';
import { LogRetentionRetryAspect } from '../../../../lib/log-retention-retry-aspect';

import { SSMInstancePolicyAspect } from '../../../../lib/ssm-policy-aspect';
import { DatabaseType, StorageStruct } from '../../../../lib/storage-struct';
Expand Down Expand Up @@ -50,3 +51,5 @@ new RepositoryTestingTier(app, 'RFDKInteg-DL-TestingTier' + integStackTag, { env

// Adds IAM Policy to Instance and ASG Roles
Aspects.of(app).add(new SSMInstancePolicyAspect());
// Adds log retention retry to all functions
Aspects.of(app).add(new LogRetentionRetryAspect());
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Stage,
ThinkboxDockerRecipes,
} from 'aws-rfdk/deadline';
import { LogRetentionRetryAspect } from '../../../../lib/log-retention-retry-aspect';

import { RenderStruct } from '../../../../lib/render-struct';
import { SSMInstancePolicyAspect } from '../../../../lib/ssm-policy-aspect';
Expand Down Expand Up @@ -61,3 +62,5 @@ new RenderQueueTestingTier(app, 'RFDKInteg-RQ-TestingTier' + integStackTag, { en

// Adds IAM Policy to Instance and ASG Roles
Aspects.of(app).add(new SSMInstancePolicyAspect());
// Adds log retention retry to all functions
Aspects.of(app).add(new LogRetentionRetryAspect());
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Stage,
ThinkboxDockerRecipes,
} from 'aws-rfdk/deadline';
import { LogRetentionRetryAspect } from '../../../../lib/log-retention-retry-aspect';

import { RenderStruct } from '../../../../lib/render-struct';
import { SSMInstancePolicyAspect } from '../../../../lib/ssm-policy-aspect';
Expand Down Expand Up @@ -65,3 +66,5 @@ new WorkerFleetTestingTier(app, 'RFDKInteg-WF-TestingTier' + integStackTag, {env

// Adds IAM Policy to Instance and ASG Roles
Aspects.of(app).add(new SSMInstancePolicyAspect());
// Adds log retention retry to all functions
Aspects.of(app).add(new LogRetentionRetryAspect());
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Stage,
ThinkboxDockerRecipes,
} from 'aws-rfdk/deadline';
import { LogRetentionRetryAspect } from '../../../../lib/log-retention-retry-aspect';

import { RenderStruct } from '../../../../lib/render-struct';
import { SSMInstancePolicyAspect } from '../../../../lib/ssm-policy-aspect';
Expand Down Expand Up @@ -65,3 +66,5 @@ new WorkerFleetTestingTier(app, 'RFDKInteg-WFS-TestingTier' + integStackTag, {en

// Adds IAM Policy to Instance and ASG Roles
Aspects.of(app).add(new SSMInstancePolicyAspect());
// Adds log retention retry to all functions
Aspects.of(app).add(new LogRetentionRetryAspect());
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ThinkboxDockerRecipes,
UsageBasedLicense,
} from 'aws-rfdk/deadline';
import { LogRetentionRetryAspect } from '../../../../lib/log-retention-retry-aspect';
import {
RenderStruct,
RenderStructUsageBasedLicensingProps,
Expand Down Expand Up @@ -79,6 +80,8 @@ async function main() {

// Adds IAM Policy to Instance and ASG Roles
Aspects.of(app).add(new SSMInstancePolicyAspect());
// Adds log retention retry to all functions
Aspects.of(app).add(new LogRetentionRetryAspect());
}

/**
Expand Down
32 changes: 32 additions & 0 deletions integ/lib/log-retention-retry-aspect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import { CfnResource, IAspect, Stack } from 'aws-cdk-lib';
import { CfnFunction } from 'aws-cdk-lib/aws-lambda';
import { LogRetention } from 'aws-cdk-lib/aws-logs';
import { IConstruct } from 'constructs';

export class LogRetentionRetryAspect implements IAspect {
public visit(node: IConstruct): void {
// Define log retention retries to reduce the risk of the rate exceed error
// as the default create log group TPS is only 5. Make sure to set the timeout of log retention function
// to be greater than total retry time. That's because if the function that is used for a custom resource
// doesn't exit properly, it'd end up in retries and may take cloud formation an hour to realize that
// the custom resource failed.
if (node instanceof LogRetention) {
const logRetentionResource = node.node.defaultChild as CfnResource;
logRetentionResource.addPropertyOverride('SdkRetry', {
maxRetries: 7,
base: 200,
});

// referenced from cdk code: https://github.com/aws/aws-cdk/blob/v2.33.0/packages/@aws-cdk/aws-logs/lib/log-retention.ts#L116
const logRetentionFunctionConstructId = 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a';
const logRetentionFunction = Stack.of(node).node.findChild(logRetentionFunctionConstructId);
const cfnFunction = logRetentionFunction.node.defaultChild as CfnFunction;
cfnFunction.addPropertyOverride('Timeout', 30);
}
}
}