amazon-web-servicesamazon-ec2amazon-rdsaws-cdkaws-reserved-instances

CDK how to use reserved rds/ec2 instances?


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


Solution

  • 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.