2

i purchased a EC2 and a RDS reserved instance. how do i reference it in CDK. and if i wanna use the reserved instance for auto scaling group. is it possible? how do i reference to the reserved instance id in auto scaling group?

const asg = new autoscaling.AutoScalingGroup(this,`${props.project}-${props.environment}-ASG`,{
      vpc:this.vpc,
      instanceType:ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, props.environment == 'production'?ec2.InstanceSize.SMALL: ec2.InstanceSize.MICRO),
      machineImage: new ec2.AmazonLinuxImage({
        generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2
      }),
      securityGroup:securityGroup,
      userData:ec2.UserData.custom(userData),
      minCapacity:1,
      maxCapacity:1,
      desiredCapacity:1,
      role:role
    })

i tried to search in CDK documentation and google. i could not find any answer. all i found was the following link

golifeline
  • 33
  • 4
  • 2
    An Amazon EC2 Reserved Instance is simply a billing discount. It does not refer to a _specific_ Amazon EC2 instance. If your AWS Account has purchased a Reserved Instance, and if a matching EC2 instance runs in a particular timeslot, then the Reserved Instance discount will apply to that instance. – John Rotenstein Nov 01 '22 at 05:30

1 Answers1

2

You do not have to do anything. If the instances in your ASG match the specifications of the Reserved Instances that you bought, it will be applied automatically. From docs:

If you purchase a Reserved Instance and you already have a running On-Demand Instance that matches the specifications of the Reserved Instance, the billing discount is applied immediately and automatically.

Marcin
  • 215,873
  • 14
  • 235
  • 294