# 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.

Obtainable from: Size.bytes, Size.gibibytes, Size.kibibytes, Size.mebibytes, Size.pebibytes, Size.tebibytes

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

## Example

TypeScript:

```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,
  }),
});
```

Python:

```python
# my_file_system: efs.IFileSystem
# my_job_role: iam.Role

my_file_system.grant_read(my_job_role)

job_defn = batch.EcsJobDefinition(self, "JobDefn",
    container=batch.EcsEc2ContainerDefinition(self, "containerDefn",
        image=ecs.ContainerImage.from_registry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
        memory=cdk.Size.mebibytes(2048),
        cpu=256,
        volumes=[batch.EcsVolume.efs(
            name="myVolume",
            file_system=my_file_system,
            container_path="/Volumes/myVolume",
            use_job_role=True
        )],
        job_role=my_job_role
    )
)
```

Java:

```java
IFileSystem myFileSystem;
Role myJobRole;

myFileSystem.grantRead(myJobRole);

EcsJobDefinition jobDefn = EcsJobDefinition.Builder.create(this, "JobDefn")
        .container(EcsEc2ContainerDefinition.Builder.create(this, "containerDefn")
                .image(ContainerImage.fromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"))
                .memory(Size.mebibytes(2048))
                .cpu(256)
                .volumes(List.of(EcsVolume.efs(EfsVolumeOptions.builder()
                        .name("myVolume")
                        .fileSystem(myFileSystem)
                        .containerPath("/Volumes/myVolume")
                        .useJobRole(true)
                        .build())))
                .jobRole(myJobRole)
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
IFileSystem myFileSystem;
Role myJobRole;

myFileSystem.GrantRead(myJobRole);

var jobDefn = new EcsJobDefinition(this, "JobDefn", new EcsJobDefinitionProps {
    Container = new EcsEc2ContainerDefinition(this, "containerDefn", new EcsEc2ContainerDefinitionProps {
        Image = ContainerImage.FromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
        Memory = Size.Mebibytes(2048),
        Cpu = 256,
        Volumes = new [] { EcsVolume.Efs(new EfsVolumeOptions {
            Name = "myVolume",
            FileSystem = myFileSystem,
            ContainerPath = "/Volumes/myVolume",
            UseJobRole = true
        }) },
        JobRole = myJobRole
    })
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var myFileSystem IFileSystem
var myJobRole Role

myFileSystem.GrantRead(myJobRole)

jobDefn := batch.NewEcsJobDefinition(this, jsii.String("JobDefn"), &EcsJobDefinitionProps{
	Container: batch.NewEcsEc2ContainerDefinition(this, jsii.String("containerDefn"), &EcsEc2ContainerDefinitionProps{
		Image: ecs.ContainerImage_FromRegistry(jsii.String("public.ecr.aws/amazonlinux/amazonlinux:latest")),
		Memory: cdk.Size_Mebibytes(jsii.Number(2048)),
		Cpu: jsii.Number(256),
		Volumes: []EcsVolume{
			batch.EcsVolume_Efs(&EfsVolumeOptions{
				Name: jsii.String("myVolume"),
				FileSystem: myFileSystem,
				ContainerPath: jsii.String("/Volumes/myVolume"),
				UseJobRole: jsii.Boolean(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
