-
Notifications
You must be signed in to change notification settings - Fork 1
/
03-environment-using-spot-instances-stack.ts
57 lines (52 loc) · 1.7 KB
/
03-environment-using-spot-instances-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as cdk from "@aws-cdk/core";
import * as elasticBeanstalk from "@aws-cdk/aws-elasticbeanstalk";
export class EnvironmentUsingSpotInstancesStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const applicationName = "03-Application";
const environmentName = "03-Environment";
const solutionStackName =
"64bit Amazon Linux 2018.03 v2.10.9 running Java 8";
const application = new elasticBeanstalk.CfnApplication(
this,
"Application",
{
applicationName: applicationName,
}
);
// https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.as.html#environments-cfg-autoscaling-spot
const optionSettingProperties: elasticBeanstalk.CfnEnvironment.OptionSettingProperty[] = [
{
namespace: "aws:ec2:instances",
optionName: "EnableSpot",
value: "true",
},
{
namespace: "aws:ec2:instances",
optionName: "InstanceTypes",
value: "t2.micro,t3.micro,t3.small",
},
{
namespace: "aws:ec2:instances",
optionName: "SpotFleetOnDemandBase",
value: "0", // 0 = 100% Spot
},
{
namespace: "aws:ec2:instances",
optionName: "SpotFleetOnDemandAboveBasePercentage",
value: "0", // 0 = 100% Spot
},
];
const environment = new elasticBeanstalk.CfnEnvironment(
this,
"Environment",
{
environmentName: environmentName,
applicationName: applicationName,
solutionStackName: solutionStackName,
optionSettings: optionSettingProperties,
}
);
environment.addDependsOn(application);
}
}