Skip to content
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 @@ -20,8 +20,24 @@ export function throttlingBackOff<T>(
request: () => Promise<T>,
options?: Partial<Omit<IBackOffOptions, 'retry'>>,
): Promise<T> {
const defaultDelay = 500;
let maxDelayValue = 2000;

if (process.env.BACKOFF_START_DELAY) {
const backoffStartDelay = parseInt(process.env.BACKOFF_START_DELAY, 10);
if (Number.isInteger(backoffStartDelay)) {
maxDelayValue = backoffStartDelay;
}
}

// Add jitter to the starting delay
const startingDelay = Math.random() * (maxDelayValue - defaultDelay + 1) + defaultDelay;

console.log(`throttlingBackOff delay set to ${startingDelay}`);

return backOff(request, {
startingDelay: 500,
startingDelay,
delayFirstAttempt: true,
jitter: 'full',
retry: isThrottlingError,
...options,
Expand All @@ -34,6 +50,7 @@ export const isThrottlingError = (e: any) =>
e.code === 'ConcurrentModificationException' || // Retry for AWS Organizations
e.code === 'InsufficientDeliveryPolicyException' || // Retry for ConfigService
e.code === 'NoAvailableDeliveryChannelException' || // Retry for ConfigService
e.code === 'ConcurrentModifications' || // Retry for AssociateHostedZone
e.code === 'TooManyRequestsException' ||
e.code === 'Throttling' ||
e.code === 'ThrottlingException' ||
Expand Down
2 changes: 2 additions & 0 deletions src/core/cdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function main() {
env.CONFIG_S3_BUCKET || `${acceleratorPrefix.toLowerCase()}${cdk.Aws.ACCOUNT_ID}-${cdk.Aws.REGION}-config`;
const codebuildComputeType = env.BUILD_COMPUTE_TYPE || 'BUILD_GENERAL1_LARGE';
const pageSize = env.DEPLOY_STACK_PAGE_SIZE || '900';
const backoff = env.BACKOFF_START_DELAY;
const enablePrebuiltProject = 'ENABLE_PREBUILT_PROJECT' in env;
const notificationEmail = env.NOTIFICATION_EMAIL || 'notify@example.com';
const installerCmk = env.INSTALLER_CMK || `alias/${acceleratorPrefix}Installer-Key`;
Expand Down Expand Up @@ -70,6 +71,7 @@ async function main() {
installerCmk,
codebuildComputeType,
pageSize,
backoff,
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/cdk/src/initial-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export namespace InitialSetup {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
codebuildComputeType: any;
pageSize: string;
backoff: string | undefined;
/**
* Current Accelerator version
*/
Expand Down Expand Up @@ -264,6 +265,7 @@ export namespace InitialSetup {
SUBNET_CIDR_ASSIGNED_POOL: subnetCidrPoolTable.tableName,
CIDR_POOL: cidrPoolTable.tableName,
DEPLOY_STACK_PAGE_SIZE: props.pageSize,
BACKOFF_START_DELAY: props.backoff || '',
COMPUTE_TYPE: props.codebuildComputeType,
},
});
Expand Down
4 changes: 2 additions & 2 deletions src/deployments/cdk/src/common/alb-ip-forwarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class AlbIpForwarding extends Construct {
runtime: lambda.Runtime.NODEJS_14_X,
code: lambdaCode,
handler: 'index.albIpMonitor',
timeout: Duration.seconds(30),
timeout: Duration.seconds(60),
environment: {
LOOKUP_TABLE: ddbTable.tableName,
},
Expand All @@ -82,7 +82,7 @@ export class AlbIpForwarding extends Construct {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.albTargetRecordMonitor',
code: lambdaCode,
timeout: Duration.seconds(30),
timeout: Duration.seconds(60),
environment: {
LOOKUP_TABLE: ddbTable.tableName,
},
Expand Down
10 changes: 10 additions & 0 deletions src/installer/cdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class Installer extends cdk.Stack {
default: 680,
});

const backoffStartDelay = new cdk.CfnParameter(this, 'Backoff Start Delay', {
description:
'The start delay for exponential backoff of API calls in milliseconds. Leave at the default of 2000 unless needed.',
default: 2000,
});

const stateMachineName = `${acceleratorPrefix}MainStateMachine_sm`;

// The state machine name has to match the name of the state machine in initial setup
Expand Down Expand Up @@ -322,6 +328,10 @@ class Installer extends cdk.Stack {
type: codebuild.BuildEnvironmentVariableType.PLAINTEXT,
value: stackDeployPageSize.valueAsString,
},
BACKOFF_START_DELAY: {
type: codebuild.BuildEnvironmentVariableType.PLAINTEXT,
value: backoffStartDelay.valueAsString,
},
},
},
cache: codebuild.Cache.local(codebuild.LocalCacheMode.SOURCE),
Expand Down
4 changes: 3 additions & 1 deletion src/lib/cdk-accelerator/src/core/accelerator-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import * as cdk from '@aws-cdk/core';
import { AcceleratorNameTagger, AcceleratorProtectedTagger } from '.';
import { AcceleratorNameTagger, AcceleratorProtectedTagger, LambdaEnvironmentVariables, LambdaDefaultTimeout } from '.';

export interface AcceleratorStackProps extends cdk.StackProps {
acceleratorName: string;
Expand All @@ -34,6 +34,8 @@ export class AcceleratorStack extends cdk.Stack {
cdk.Aspects.of(this).add(new cdk.Tag('Accelerator', this.acceleratorName));
cdk.Aspects.of(this).add(new AcceleratorNameTagger());
cdk.Aspects.of(this).add(new AcceleratorProtectedTagger(this.acceleratorName));
cdk.Aspects.of(this).add(new LambdaEnvironmentVariables());
cdk.Aspects.of(this).add(new LambdaDefaultTimeout());
}

static of(construct: cdk.IConstruct): AcceleratorStack {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/cdk-accelerator/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
export * from './cfn-include';
export * from './name-tagger';
export * from './accelerator-protected-tagger';
export * from './lambda-env-variables';
export * from './lambda-default-timeout';
12 changes: 12 additions & 0 deletions src/lib/cdk-accelerator/src/core/lambda-default-timeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';

export class LambdaDefaultTimeout implements cdk.IAspect {
visit(node: cdk.IConstruct): void {
if (node instanceof lambda.CfnFunction) {
if (!node.timeout) {
node.timeout = 60;
}
}
}
}
10 changes: 10 additions & 0 deletions src/lib/cdk-accelerator/src/core/lambda-env-variables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';

export class LambdaEnvironmentVariables implements cdk.IAspect {
visit(node: cdk.IConstruct): void {
if (node instanceof lambda.Function) {
node.addEnvironment('BACKOFF_START_DELAY', process.env['BACKOFF_START_DELAY'] || '2000');
}
}
}
19 changes: 18 additions & 1 deletion src/lib/common/src/aws/backoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,24 @@ export function throttlingBackOff<T>(
request: () => Promise<T>,
options?: Partial<Omit<IBackOffOptions, 'retry'>>,
): Promise<T> {
const defaultDelay = 500;
let maxDelayValue = 2000;

if (process.env.BACKOFF_START_DELAY) {
const backoffStartDelay = parseInt(process.env.BACKOFF_START_DELAY, 10);
if (Number.isInteger(backoffStartDelay)) {
maxDelayValue = backoffStartDelay;
}
}

// Add jitter to the starting delay
const startingDelay = Math.random() * (maxDelayValue - defaultDelay + 1) + defaultDelay;

console.log(`throttlingBackOff delay set to ${startingDelay}`);

return backOff(request, {
startingDelay: 500,
startingDelay,
delayFirstAttempt: true,
jitter: 'full',
retry: isThrottlingError,
...options,
Expand All @@ -34,6 +50,7 @@ export const isThrottlingError = (e: any) =>
e.code === 'ConcurrentModificationException' || // Retry for AWS Organizations
e.code === 'InsufficientDeliveryPolicyException' || // Retry for ConfigService
e.code === 'NoAvailableDeliveryChannelException' || // Retry for ConfigService
e.code === 'ConcurrentModifications' || // Retry for AssociateHostedZone
e.code === 'TooManyRequestsException' ||
e.code === 'Throttling' ||
e.code === 'ThrottlingException' ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class AcmImportCertificate extends cdk.Construct implements cdk.ITaggable
code: lambda.Code.fromAsset(lambdaDir),
handler: 'index.handler',
role,
timeout: cdk.Duration.seconds(10),
timeout: cdk.Duration.seconds(60),
});
}
}
18 changes: 17 additions & 1 deletion src/lib/custom-resources/cdk-cfn-utils/cdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,24 @@ export function throttlingBackOff<T>(
request: () => Promise<T>,
options?: Partial<Omit<IBackOffOptions, 'retry'>>,
): Promise<T> {
const defaultDelay = 500;
let maxDelayValue = 2000;

if (process.env.BACKOFF_START_DELAY) {
const backoffStartDelay = parseInt(process.env.BACKOFF_START_DELAY, 10);
if (Number.isInteger(backoffStartDelay)) {
maxDelayValue = backoffStartDelay;
}
}

// Add jitter to the starting delay
const startingDelay = Math.random() * (maxDelayValue - defaultDelay + 1) + defaultDelay;

console.log(`throttlingBackOff delay set to ${startingDelay}`);

return backOff(request, {
startingDelay: 500,
startingDelay,
delayFirstAttempt: true,
jitter: 'full',
retry: isThrottlingError,
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class CurReportDefinition extends cdk.Construct {
code: lambda.Code.fromAsset(lambdaDir),
handler: 'index.handler',
role,
timeout: cdk.Duration.seconds(10),
timeout: cdk.Duration.seconds(60),
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class EbsDefaultEncryption extends cdk.Construct {
code: lambda.Code.fromAsset(lambdaDir),
handler: 'index.handler',
role,
timeout: cdk.Duration.seconds(10),
timeout: cdk.Duration.seconds(60),
});
}
}
2 changes: 1 addition & 1 deletion src/lib/custom-resources/cdk-ec2-keypair/cdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Keypair extends cdk.Construct implements cdk.ITaggable {
code: lambda.Code.fromAsset(lambdaDir),
handler: 'index.handler',
role,
timeout: cdk.Duration.seconds(10),
timeout: cdk.Duration.seconds(60),
});
}
}
2 changes: 1 addition & 1 deletion src/lib/custom-resources/cdk-kms-grant/cdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class Grant extends cdk.Construct {
code: lambda.Code.fromAsset(lambdaDir),
handler: 'index.handler',
role,
timeout: cdk.Duration.seconds(10),
timeout: cdk.Duration.seconds(60),
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class S3UpdateLogArchivePolicy extends cdk.Construct {
code: lambda.Code.fromAsset(lambdaDir),
handler: 'index.handler',
role,
timeout: cdk.Duration.seconds(30),
timeout: cdk.Duration.seconds(60),
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class EbsDefaultEncryption extends cdk.Construct {
code: lambda.Code.fromAsset(lambdaDir),
handler: 'index.handler',
role,
timeout: cdk.Duration.seconds(10),
timeout: cdk.Duration.seconds(60),
});
}
}