Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

amazon web services - need to create an autoscaling group with encrypted EBS volume with Customer kms key

using aws CDK, I need to create an autoscaling with encrypted volume with customer KMS key, I Now that I can do this by using a lanch template but I did not found in the documentation how to create the lanch template and how to create the autoscaling group with this one.

I found just this constructor methode "autoscaling.AutoScalingGroup" '''

autoscaling.AutoScalingGroup(self, "my-app",
                                vpc=vpc,
                                vpc_subnets=ec2.SubnetSelection(                                              
                                   subnets=[
                                      ec2.Subnet.from_subnet_id(self,"asg_subnetAz1",subnet_az1_id), 
                                      ec2.Subnet.from_subnet_id(self, "asg_subnetAz2", subnet_az2_id)
                                    ]
                                 ),
                                instance_type=ec2.InstanceType( instance_type_identifier=ec2_type),                                              
                                machine_image=linux_ami,
                                desired_capacity=1,
                                min_capacity=1,
                                max_capacity=1,
                                security_group=sg_asg,
                                block_devices=[
                                  autoscaling.BlockDevice(
                                     device_name="/dev/sda1", 
                                     volume=autoscaling.BlockDeviceVolume.ebs(
                                            volume_size=ebs_volume_size, 
                                            delete_on_termination=delete, 
                                            encrypted=True, 
                                            volume_type=autoscaling.EbsDeviceVolumeType.GP2
                                      )
                                  )
                                ],
                               user_data=ec2.UserData.custom(user_data_ec2), 
                               role=self.ec2_role
) 

'''

it is working fine but in block_devides parameter I can not specify the customer key.

have you any idea about how to do this?

question from:https://stackoverflow.com/questions/65874105/need-to-create-an-autoscaling-group-with-encrypted-ebs-volume-with-customer-kms

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

this perhaps could help another one. to create the autoscaling with custom key 2 ways:

  • Create a launch template where you can specify the KMS key to encrypt the EBS volume and then create ASG with this launch template.
  • or just create the asg without encryption and change the account setting to force the encryption of every new ebs volume with the CMK. this is the easiest way.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...