service catalog recreate new ec2 when updating ebs volumetype from gp2 to gp3

0

As on topic, I have created a new service catalog Portfolios > Products with two version.

1.) First version with the below cloudformation template.

2.) Launch the product using the below template is ok. EC2 launched successfully.

3.) Create a second version and modify the cloudformation template for BlockDeviceMapping > DeviceName /dev/xda > Ebs VolumeType to gp3.

4.) It create a new EC2 with EBS VolumeType gp3 instead of modifying the existing EC2 EBS VolumeType launched from first version.

5.) When checking from Provisioned products > provisioned product plan, the replacement is set to True. I believe this is the issue. How can I make it to use the existing EC2 launched from first version and modify the EBS VolumeType from gp2 to gp3?

Thank you for help.

 AWSTemplateFormatVersion: "2010-09-09"
 Description: "Create EC2 instance"
 Resources: 
 EC2Instance: 
 DeletionPolicy: Retain
 Properties: 
  BlockDeviceMappings: 
  - DeviceName: /dev/xvda
    Ebs: 
      VolumeType: gp2
      VolumeSize: 10
  IamInstanceProfile: roletest
  ImageId: ami-123456
  InstanceType: t2.micro
  SecurityGroupIds: 
    - sg-123456
  SubnetId: 123456
  Tags: 
    - 
      Key: Name
      Value: ec2test
Type: "AWS::EC2::Instance"
kyiori
asked 2 years ago392 views
1 Answer
0

Hello,

Per the VolumeType property, updates to this property after the instance is running results in an instance replacement. There is no way for CloudFormation to update the EBS volume type for the instance that is already running without an instance replacement.

An workaround is to first remove the instance from CloudFormation management (delete the instance from the stack after having applied the DeletionPolicy: Retain) as in your template above. After this, manually modify the EBS volume to gp3 via the EC2 console and after modification is complete, import the instance back to CloudFormation.

Additionally, note that because Service Catalog is being used, the stack needs to first be disassociated from Service Catalog using the "--retain-physical-resources" option in the terminate-provisioned-product command. After the instance have been imported back to the stack as in the step above, you can then add this stack back to Service Catalog using the import-as-provisioned-product CLI command.

AWS
answered 2 years ago
  • @Ugochukwu_I

    Are you referring to this? https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-update-volume-instance/

    Are you able to explain this further? "An workaround is to first remove the instance from CloudFormation management (delete the instance from the stack after having applied the DeletionPolicy: Retain) as in your template above."

    How do I remove the instance from the current Cloudformation template? Can you highlight what needs to be changed from the cloudformation template?

  • Hello Kyiori,

    I was referring to your use-case where you want to modify the volume without instance replacement. The workaround for this is to use the CloudFormation import feature. First, you perform a stack update where you apply a "DeletionPolicy: Retain" on the instance (which you have already done). To remove/delete the instance from CloudFormation management, simply comment out the EC2Instance from the template and update the stack. CloudFormation will take it out of its management. Then you can manually update the volume from EC2 and when done import the instance back to CloudFormation

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions