Skip to content

Commit

Permalink
feat(aws-autoscaling): allow setting spotPrice
Browse files Browse the repository at this point in the history
Fixes aws#2208.
  • Loading branch information
SoManyHs committed May 17, 2019
1 parent cfe46f6 commit c91a49b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps {
* @default A role will automatically be created, it can be accessed via the `role` property
*/
readonly role?: iam.IRole;

/**
* The maximum hourly price to be paid for any Spot Instance launched to fulfill the request. Spot Instances are
* launched when the price you specify exceeds the current Spot market price.
*
* @default none
*/
readonly spotPrice?: string;
}

abstract class AutoScalingGroupBase extends Resource implements IAutoScalingGroup {
Expand Down Expand Up @@ -369,6 +377,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
iamInstanceProfile: iamProfile.ref,
userData: userDataToken,
associatePublicIpAddress: props.associatePublicIpAddress,
spotPrice: props.spotPrice,
});

launchConfig.node.addDependency(this.role);
Expand Down
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export = {

test.done();
},

'can add Security Group to Fleet'(test: Test) {
// GIVEN
const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' }});
Expand All @@ -363,6 +364,7 @@ export = {
}));
test.done();
},

'can set tags'(test: Test) {
// GIVEN
const stack = getTestStack();
Expand Down Expand Up @@ -405,6 +407,29 @@ export = {
}));
test.done();
},

'allows setting spot price'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);

// WHEN
new autoscaling.AutoScalingGroup(stack, 'MyStack', {
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.Micro),
machineImage: new ec2.AmazonLinuxImage(),
vpc,

spotPrice: "0.05",
});

// THEN
expect(stack).to(haveResource("AWS::AutoScaling::LaunchConfiguration", {
SpotPrice: "0.05",
}));

test.done();
},

'allows association of public IP address'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand All @@ -430,6 +455,7 @@ export = {
));
test.done();
},

'association of public IP address requires public subnet'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand All @@ -449,6 +475,7 @@ export = {
});
test.done();
},

'allows disassociation of public IP address'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand All @@ -472,6 +499,7 @@ export = {
));
test.done();
},

'does not specify public IP address association by default'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit c91a49b

Please sign in to comment.