aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.52k stars 3.86k forks source link

(ec2): Cannot attach Volume to Instance #16001

Open heuristics222 opened 3 years ago

heuristics222 commented 3 years ago

ec2.Instance only currently supports attaching volumes with type BlockDeviceVolume. See https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.Instance.html#blockdevices and https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.BlockDevice.html

Use Case

CloudFormation supports attaching Volumes created separately from the Instance. It would be nice to have the same support for the L2 CDK classes.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-volumes

Proposed Solution

I believe this would involve adding a new property, volumes to Instance of a type that maps a device name to Volume. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-mount-point.html

Other


This is a :rocket: Feature Request

heuristics222 commented 3 years ago

I found a workaround (Python)

        volume = ec2.Volume(self, 'serverVolume',
            removal_policy=cdk.RemovalPolicy.RETAIN,
            ...
        )
        instance = ec2.Instance(self, 'serverInstance',
            instance_type=ec2.InstanceType('t3a.small'),
            ...
        )
        instance.node.default_child.volumes = [
            ec2.CfnInstance.VolumeProperty(
                device='/dev/sda1',
                volume_id=volume.volume_id,
            )
        ]
njlynch commented 3 years ago

Thanks for the feature request and work-around! I'm a bit surprised this is a gap in the Instance construct, but so it is.

I've tagged this as P1, which means it should be on our near-term roadmap.

We welcome community contributions! If you are able, we encourage you to contribute. If you decide to contribute, please start an engineering discussion in this issue to ensure there is a commonly understood design before submitting code. This will minimize the number of review cycles and get your code merged faster.

github-actions[bot] commented 2 years ago

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

luxaritas commented 2 years ago

Still relevant