You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(ec2): support KMS keys for block device mappings for both instances and launch templates (#18326)
This pullrequest will add the optional ```kmsKeyId``` property to the ```EbsDeviceOptions``` Interface. Whit this, it will be possible to specify the kmsKeyId used for encrypting the ebs volumes when launching instances. At the moment I already use this via an escape hatch in my projects, but it's not that handy as the block device mapping is an array.
I don't like to only specify a kmsKeyId (= ARN) but accepting an ```kms.IKey``` in the properties would be a bigger change.
fixes: #18309
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy file name to clipboardExpand all lines: packages/@aws-cdk/aws-ec2/README.md
+31
Original file line number
Diff line number
Diff line change
@@ -1051,6 +1051,37 @@ new ec2.Instance(this, 'Instance', {
1051
1051
1052
1052
```
1053
1053
1054
+
It is also possible to encrypt the block devices. In this example we will create an customer managed key encrypted EBS-backed root device:
1055
+
1056
+
```ts
1057
+
import { Key } from'@aws-cdk/aws-kms';
1058
+
1059
+
declareconst vpc:ec2.Vpc;
1060
+
declareconst instanceType:ec2.InstanceType;
1061
+
declareconst machineImage:ec2.IMachineImage;
1062
+
1063
+
const kmsKey =newKey(this, 'KmsKey')
1064
+
1065
+
newec2.Instance(this, 'Instance', {
1066
+
vpc,
1067
+
instanceType,
1068
+
machineImage,
1069
+
1070
+
// ...
1071
+
1072
+
blockDevices: [
1073
+
{
1074
+
deviceName: '/dev/sda1',
1075
+
volume: ec2.BlockDeviceVolume.ebs(50, {
1076
+
encrypted: true,
1077
+
kmsKey: kmsKey,
1078
+
}),
1079
+
},
1080
+
],
1081
+
});
1082
+
1083
+
```
1084
+
1054
1085
### Volumes
1055
1086
1056
1087
Whereas a `BlockDeviceVolume` is an EBS volume that is created and destroyed as part of the creation and destruction of a specific instance. A `Volume` is for when you want an EBS volume separate from any particular instance. A `Volume` is an EBS block device that can be attached to, or detached from, any instance at any time. Some types of `Volume`s can also be attached to multiple instances at the same time to allow you to have shared storage between those instances.
0 commit comments