Skip to content

Commit

Permalink
feat: adds support to ec2 vols gp3 throughput
Browse files Browse the repository at this point in the history
  • Loading branch information
csumpter committed Oct 10, 2022
1 parent 064a1a6 commit 60176b9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-ec2/README.md
Expand Up @@ -1245,6 +1245,19 @@ You can configure [tag propagation on volume creation](https://docs.aws.amazon.c
});
```

#### Throughput on GP3 Volumes

You can specify the `throughput` of a GP3 volume from 125 (default) to 1000.

```ts
new ec2.Volume(this, 'Volume', {
availabilityZone: 'us-east-1a',
size: cdk.Size.gibibytes(125),
volumeType: EbsDeviceVolumeType.GP3,
throughput: 125,
});
```

### Configuring Instance Metadata Service (IMDS)

#### Toggling IMDSv1
Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-ec2/lib/volume.ts
Expand Up @@ -443,6 +443,13 @@ export interface VolumeProps {
* @default RemovalPolicy.RETAIN
*/
readonly removalPolicy?: RemovalPolicy;

/**
* The throughput that the volume supports, in MiB/s
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-ebs-volume.html#cfn-ec2-ebs-volume-throughput
* @default - 125 MiB/s
*/
readonly throughput?: number;
}

/**
Expand Down Expand Up @@ -737,5 +744,14 @@ export class Volume extends VolumeBase {
throw new Error(`\`${volumeType}\` volumes must be between ${Min} GiB and ${Max} GiB in size.`);
}
}

if (props.throughput) {
if (props.volumeType != EbsDeviceVolumeType.GP3) {
throw new Error('throughput property requires volumeType: EbsDeviceVolumeType.GP3');
}
if (props.throughput < 125 || props.throughput > 1000) {
throw new Error('throughput property takes a minimum of 125 and a maximum of 1000');
}
}
}
}
32 changes: 32 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/volume.test.ts
Expand Up @@ -1436,4 +1436,36 @@ describe('volume', () => {
}).toThrow(/volumes must be between/);
}
});

test.each([124, 1001])('throws if throughput is set less than 125 or more than 1000', (throughput) => {
const stack = new cdk.Stack();
expect(() => {
new Volume(stack, 'Volume', {
availabilityZone: 'us-east-1a',
size: cdk.Size.gibibytes(1),
volumeType: EbsDeviceVolumeType.GP3,
throughput,
});
}).toThrow(/throughput property takes a minimum of 125 and a maximum of 1000/);
});

test.each([
...Object.values(EbsDeviceVolumeType).filter((v) => v !== 'gp3'),
])('throws if throughput is set on any volume type other than GP3', (volumeType) => {
const stack = new cdk.Stack();
const iops = [
EbsDeviceVolumeType.PROVISIONED_IOPS_SSD,
EbsDeviceVolumeType.PROVISIONED_IOPS_SSD_IO2,
].includes(volumeType) ? 100 : null;
expect(() => {
new Volume(stack, 'Volume', {
availabilityZone: 'us-east-1a',
size: cdk.Size.gibibytes(125),
volumeType,
...iops ? { iops }: {},
throughput: 125,
});
}).toThrow(/throughput property requires volumeType: EbsDeviceVolumeType.GP3/);
});

});

0 comments on commit 60176b9

Please sign in to comment.