# Size

Represents the amount of digital storage.

The amount can be specified either as a literal value (e.g: `10`) which
cannot be negative, or as an unresolved number token.

When the amount is passed as a token, unit conversion is not possible.

- Source: [`core/lib/size.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/core/lib/size.ts#L13)
- Type last changed: v2.267.0 · 27 Aug 2026

## Example

```ts
declare const myFileSystem: efs.IFileSystem;
declare const myJobRole: iam.Role;
myFileSystem.grantRead(myJobRole);

const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
  container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
    image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
    memory: cdk.Size.mebibytes(2048),
    cpu: 256,
    volumes: [batch.EcsVolume.efs({
      name: 'myVolume',
      fileSystem: myFileSystem,
      containerPath: '/Volumes/myVolume',
      useJobRole: true,
    })],
    jobRole: myJobRole,
  }),
});
```

## Methods

- `bytes(amount: number): Size // chainable` (static) — Create a Storage representing an amount bytes.

  **Parameters**

  - `amount` — the amount of bytes to be represented.

  **Returns:** a new `Size` instance

- `gibibytes(amount: number): Size // chainable` (static) — Create a Storage representing an amount gibibytes.

  1 GiB = 1024 MiB

  **Parameters**

  - `amount` — the amount of gibibytes to be represented.

  **Returns:** a new `Size` instance

- `isUnresolved(): boolean` — Checks if size is a token or a resolvable object.

- `kibibytes(amount: number): Size // chainable` (static) — Create a Storage representing an amount kibibytes.

  1 KiB = 1024 bytes

  **Parameters**

  - `amount` — the amount of kibibytes to be represented.

  **Returns:** a new `Size` instance

- `mebibytes(amount: number): Size // chainable` (static) — Create a Storage representing an amount mebibytes.

  1 MiB = 1024 KiB

  **Parameters**

  - `amount` — the amount of mebibytes to be represented.

  **Returns:** a new `Size` instance

- `pebibytes(amount: number): Size // chainable` (static) — Create a Storage representing an amount pebibytes.

  1 PiB = 1024 TiB

  **Parameters**

  - `amount` — the amount of pebibytes to be represented.

  **Returns:** a new `Size` instance

- `tebibytes(amount: number): Size // chainable` (static) — Create a Storage representing an amount tebibytes.

  1 TiB = 1024 GiB

  **Parameters**

  - `amount` — the amount of tebibytes to be represented.

  **Returns:** a new `Size` instance

- `toBytes(opts?: SizeConversionOptions): number` — Return this storage as a total number of bytes.

  **Parameters**

  - `opts` — the conversion options.

  **Returns:** the quantity expressed in bytes

- `toGibibytes(opts?: SizeConversionOptions): number` — Return this storage as a total number of gibibytes.

  **Parameters**

  - `opts` — the conversion options.

  **Returns:** the quantity of bytes expressed in gibibytes

- `toHumanString(): string` — Convert this Size object to the most appropriate readable number.

- `toKibibytes(opts?: SizeConversionOptions): number` — Return this storage as a total number of kibibytes.

  **Parameters**

  - `opts` — the conversion options.

  **Returns:** the quantity of bytes expressed in kibibytes

- `toMebibytes(opts?: SizeConversionOptions): number` — Return this storage as a total number of mebibytes.

  **Parameters**

  - `opts` — the conversion options.

  **Returns:** the quantity of bytes expressed in mebibytes

- `toPebibytes(opts?: SizeConversionOptions): number` — Return this storage as a total number of pebibytes.

  **Parameters**

  - `opts` — the conversion options.

  **Returns:** the quantity of bytes expressed in pebibytes

- `toString(): string` — Convert this Size object to its constructor form.

- `toTebibytes(opts?: SizeConversionOptions): number` — Return this storage as a total number of tebibytes.

  **Parameters**

  - `opts` — the conversion options.

  **Returns:** the quantity of bytes expressed in tebibytes
