-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
942 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
packages/@aws-cdk/aws-apprunner-alpha/lib/auto-scaling-configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import * as cdk from 'aws-cdk-lib/core'; | ||
import { Construct } from 'constructs'; | ||
import { CfnAutoScalingConfiguration } from 'aws-cdk-lib/aws-apprunner'; | ||
|
||
/** | ||
* Properties of the App Runner Auto Scaling Configuration. | ||
*/ | ||
export interface AutoScalingConfigurationProps { | ||
/** | ||
* The name for the Auto Scaling Configuration. | ||
*/ | ||
readonly autoScalingConfigurationName?: string; | ||
|
||
/** | ||
* The maximum number of concurrent requests that an instance processes. | ||
* If the number of concurrent requests exceeds this limit, App Runner scales the service up. | ||
* | ||
* Must be between 1 and 25. | ||
* | ||
* @default 100 | ||
*/ | ||
readonly maxConcurrency?: number; | ||
|
||
/** | ||
* The maximum number of instances that a service scales up to. | ||
* At most maxSize instances actively serve traffic for your service. | ||
* | ||
* Must be between 1 and 25. | ||
* | ||
* @default 1 | ||
*/ | ||
readonly maxSize?: number; | ||
|
||
/** | ||
* The minimum number of instances that App Runner provisions for a service. | ||
* The service always has at least minSize provisioned instances. | ||
* | ||
* @default 25 | ||
*/ | ||
readonly minSize?: number; | ||
} | ||
|
||
/** | ||
* Attributes for the App Runner Auto Scaling Configuration. | ||
*/ | ||
export interface AutoScalingConfigurationAttributes { | ||
/** | ||
* The name of the Auto Scaling Configuration. | ||
*/ | ||
readonly autoScalingConfigurationName: string; | ||
|
||
/** | ||
* The ARN of the Auto Scaling Configuration. | ||
*/ | ||
readonly autoScalingConfigurationArn: string; | ||
|
||
/** | ||
* The revision of the Auto Scaling Configuration. | ||
*/ | ||
readonly autoScalingConfigurationRevision: number; | ||
} | ||
|
||
/** | ||
* Represents the App Runner Auto Scaling Configuration. | ||
*/ | ||
export interface IAutoScalingConfiguration extends cdk.IResource { | ||
/** | ||
* The ARN of the Auto Scaling Configuration. | ||
* @attribute | ||
*/ | ||
readonly autoScalingConfigurationArn: string; | ||
|
||
/** | ||
* The Name of the Auto Scaling Configuration. | ||
* @attribute | ||
*/ | ||
readonly autoScalingConfigurationName: string; | ||
|
||
/** | ||
* The revision of the Auto Scaling Configuration. | ||
* @attribute | ||
*/ | ||
readonly autoScalingConfigurationRevision: number; | ||
} | ||
|
||
/** | ||
* The App Runner Auto Scaling Configuration. | ||
* | ||
* @resource AWS::AppRunner::AutoScalingConfiguration | ||
*/ | ||
export class AutoScalingConfiguration extends cdk.Resource implements IAutoScalingConfiguration { | ||
/** | ||
* Import from Auto Scaling Configuration attributes. | ||
*/ | ||
public static fromAutoScalingConfigurationAttributes(scope: Construct, id: string, | ||
attrs: AutoScalingConfigurationAttributes): IAutoScalingConfiguration { | ||
const autoScalingConfigurationArn = attrs.autoScalingConfigurationArn; | ||
const autoScalingConfigurationName = attrs.autoScalingConfigurationName; | ||
const autoScalingConfigurationRevision = attrs.autoScalingConfigurationRevision; | ||
|
||
class Import extends cdk.Resource { | ||
public readonly autoScalingConfigurationArn = autoScalingConfigurationArn | ||
public readonly autoScalingConfigurationName = autoScalingConfigurationName | ||
public readonly autoScalingConfigurationRevision = autoScalingConfigurationRevision | ||
} | ||
|
||
return new Import(scope, id); | ||
} | ||
|
||
/** | ||
* The ARN of the Auto Scaling Configuration. | ||
* @attribute | ||
*/ | ||
readonly autoScalingConfigurationArn: string; | ||
|
||
/** | ||
* The name of the Auto Scaling Configuration. | ||
* @attribute | ||
*/ | ||
readonly autoScalingConfigurationName: string; | ||
|
||
/** | ||
* The revision of the Auto Scaling Configuration. | ||
* @attribute | ||
*/ | ||
readonly autoScalingConfigurationRevision: number; | ||
|
||
public constructor(scope: Construct, id: string, props: AutoScalingConfigurationProps = {}) { | ||
super(scope, id, { | ||
physicalName: props.autoScalingConfigurationName, | ||
}); | ||
|
||
if (props.minSize !== undefined && (props.minSize < 1 || props.minSize > 25)) { | ||
throw new Error(`minSize must be between 1 and 25, got ${props.minSize}`); | ||
} | ||
if (props.maxSize !== undefined && (props.maxSize < 1 || props.maxSize > 25)) { | ||
throw new Error(`maxSize must be between 1 and 25, got ${props.maxSize}`); | ||
} | ||
if (props.minSize !== undefined && props.maxSize !== undefined && !(props.minSize < props.maxSize)) { | ||
throw new Error('maxSize must be greater than minSize'); | ||
} | ||
if (props.maxConcurrency !== undefined && (props.maxConcurrency < 1 || props.maxConcurrency > 200)) { | ||
throw new Error(`maxConcurrency must be between 1 and 200, got ${props.maxConcurrency}`); | ||
} | ||
|
||
const resource = new CfnAutoScalingConfiguration(this, 'Resource', { | ||
autoScalingConfigurationName: props.autoScalingConfigurationName, | ||
maxConcurrency: props.maxConcurrency, | ||
maxSize: props.maxSize, | ||
minSize: props.minSize, | ||
}); | ||
|
||
this.autoScalingConfigurationArn = resource.attrAutoScalingConfigurationArn; | ||
this.autoScalingConfigurationRevision = resource.attrAutoScalingConfigurationRevision; | ||
this.autoScalingConfigurationName = resource.ref; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// AWS::AppRunner CloudFormation Resources: | ||
export * from './auto-scaling-configuration'; | ||
export * from './service'; | ||
export * from './vpc-connector'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/@aws-cdk/aws-apprunner-alpha/test/auto-scaling-configuration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Match, Template } from 'aws-cdk-lib/assertions'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { AutoScalingConfiguration } from '../lib'; | ||
|
||
let stack: cdk.Stack; | ||
beforeEach(() => { | ||
stack = new cdk.Stack(); | ||
}); | ||
|
||
test('create an Auto scaling Configuration with all properties', () => { | ||
// WHEN | ||
new AutoScalingConfiguration(stack, 'AutoScalingConfiguration', { | ||
autoScalingConfigurationName: 'MyAutoScalingConfiguration', | ||
maxConcurrency: 150, | ||
maxSize: 20, | ||
minSize: 5, | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppRunner::AutoScalingConfiguration', { | ||
AutoScalingConfigurationName: 'MyAutoScalingConfiguration', | ||
MaxConcurrency: 150, | ||
MaxSize: 20, | ||
MinSize: 5, | ||
}); | ||
}); | ||
|
||
test('create an Auto scaling Configuration without all properties', () => { | ||
// WHEN | ||
new AutoScalingConfiguration(stack, 'AutoScalingConfiguration', { | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppRunner::AutoScalingConfiguration', { | ||
AutoScalingConfigurationName: Match.absent(), | ||
MaxConcurrency: Match.absent(), | ||
MaxSize: Match.absent(), | ||
MinSize: Match.absent(), | ||
}); | ||
}); | ||
|
||
test.each([0, 26])('invalid minSize', (minSize: number) => { | ||
expect(() => { | ||
new AutoScalingConfiguration(stack, 'AutoScalingConfiguration', { | ||
minSize, | ||
}); | ||
}).toThrow(`minSize must be between 1 and 25, got ${minSize}`); | ||
}); | ||
|
||
test.each([0, 26])('invalid maxSize', (maxSize: number) => { | ||
expect(() => { | ||
new AutoScalingConfiguration(stack, 'AutoScalingConfiguration', { | ||
maxSize, | ||
}); | ||
}).toThrow(`maxSize must be between 1 and 25, got ${maxSize}`); | ||
}); | ||
|
||
test('minSize greater than maxSize', () => { | ||
expect(() => { | ||
new AutoScalingConfiguration(stack, 'AutoScalingConfiguration', { | ||
minSize: 5, | ||
maxSize: 3, | ||
}); | ||
}).toThrow('maxSize must be greater than minSize'); | ||
}); | ||
|
||
test.each([0, 201])('invalid maxConcurrency', (maxConcurrency: number) => { | ||
expect(() => { | ||
new AutoScalingConfiguration(stack, 'AutoScalingConfiguration', { | ||
maxConcurrency, | ||
}); | ||
}).toThrow(`maxConcurrency must be between 1 and 200, got ${maxConcurrency}`); | ||
}); |
19 changes: 19 additions & 0 deletions
19
....js.snapshot/AppRunnerAutoScalingConfigurationDefaultTestDeployAssert4AFB3BF1.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...s.snapshot/AppRunnerAutoScalingConfigurationDefaultTestDeployAssert4AFB3BF1.template.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...cdk/aws-apprunner-alpha/test/integ.service-auto-scaling-configuration.js.snapshot/cdk.out
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.