Aws-cdk: How to create EC2 with custom storage size

Created on 31 Oct 2019  路  1Comment  路  Source: aws/aws-cdk

:question: General Issue

The Question

How can I create ec2 node with defined storage size from CDK

Environment

  • CDK CLI Version:
    1.13.1 (build 96cfc63)
  • Module Version:
    @aws-cdk/aws-ec2 version 1.13.1
  • OS:
    OSX Mojave
  • Language:
    TypeScript

Other information

This is my construct

const instance = new Instance(this, 'SolrInstance', {
      vpc: vpc,
      instanceName: 'SolrInstance',
      instanceType: InstanceType.of(InstanceClass.BURSTABLE3, InstanceSize.NANO),
      machineImage: ubuntuImage,
      allowAllOutbound: true,
      keyName: 'solr-key',
      vpcSubnets: { subnetType: SubnetType.PRIVATE },
      securityGroup: SolrSecurityGroup,
    });

How do i specify the ebs volume of this instance?

@aws-cdaws-ec2 feature-request in-progress

Most helpful comment

Hey @icecold21,

It looks like the BlockDeviceMappings property is missing from the L2 Instance construct.

Until they're added, you'll need to modifiy the CloudFormation properties directly, something like:

const cfnInstance = instance.node.defaultChild as CfnInstance;
// @ts-ignore - readonly
cfnInstance.blockDeviceMappings = [{
  deviceName: '/dev/sda',
  ebs: {volumeSize: 20},
}];

I'll look into making a PR to ease that process

EDIT: I actually already did most of the work for aws-autoscaling with #3622, this should be fairly easy to port to aws-ec2

>All comments

Hey @icecold21,

It looks like the BlockDeviceMappings property is missing from the L2 Instance construct.

Until they're added, you'll need to modifiy the CloudFormation properties directly, something like:

const cfnInstance = instance.node.defaultChild as CfnInstance;
// @ts-ignore - readonly
cfnInstance.blockDeviceMappings = [{
  deviceName: '/dev/sda',
  ebs: {volumeSize: 20},
}];

I'll look into making a PR to ease that process

EDIT: I actually already did most of the work for aws-autoscaling with #3622, this should be fairly easy to port to aws-ec2

Was this page helpful?
0 / 5 - 0 ratings