

# Structured error output in the AWS CLI

This topic describes the structured error output formats for the AWS Command Line Interface (AWS CLI). The CLI writes errors to stderr and supports the following formats:
+ **[`enhanced`](#cli-error-format-enhanced)** (default) – Error message with additional details displayed inline. Use for human-readable debugging.
+ **[`json`](#cli-error-format-json)** – The output is formatted as a [JSON](https://json.org/) string with all error fields. Use for automation and scripting.
+ **[`yaml`](#cli-error-format-yaml)** – The output is formatted as a [YAML](https://yaml.org/) string with all error fields. Use for automation and scripting.
+ **[`text`](#cli-error-format-text)** – Formats errors using the text formatter. Use for quick visual scanning.
+ **[`table`](#cli-error-format-table)** – Formats errors using the table formatter. Use for quick visual scanning.
+ **[`legacy`](#cli-error-format-legacy)** – Original error format without structured details. Use for backward compatibility.

## Configuring error format
<a name="cli-error-format-configuring"></a>

You can configure the error format using any of the following methods:

Command-line flag  

```BASH
$ aws {{<command>}} --cli-error-format json
```

Configuration file (`~/.aws/config`)  

```INI
[default]
cli_error_format = json
```

Environment variable  

```BASH
$ export AWS_CLI_ERROR_FORMAT=yaml
```

## Error output formats
<a name="cli-error-output-formats"></a>

The following sections describe each format:

### Enhanced format (default)
<a name="cli-error-format-enhanced"></a>

The enhanced format displays error messages with additional details inline for simple values. For complex structures, the format provides a hint to use JSON or YAML.

**Example: Missing region configuration**

```NONE
aws: [ERROR]: An error occurred (NoRegion): You must specify a region. You can also configure your region by running "aws configure".
```

**Example: Nonexistent Lambda function with additional fields**

```NONE
aws: [ERROR]: An error occurred (ResourceNotFoundException) when calling the GetFunction operation: Function not found: arn:aws:lambda:us-west-2:123456789012:function:nonexistent-function-12345

Additional error details:
Type: User
```

The "Additional error details" section displays only fields that are defined in the service's error shape model. Unmodeled fields from the error response are not shown.

**Example: Complex error fields**

```NONE
An error occurred (TransactionCanceledException) when calling the TransactWriteItems operation: Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed, None]

Additional error details:
CancellationReasons: <complex value>
Use "--cli-error-format json" or another error format to see the full details.
```

### JSON format
<a name="cli-error-format-json"></a>

The JSON format provides a structured representation with all error fields.

**Example: Missing region configuration**

```JSON
{
    "Code": "NoRegion",
    "Message": "You must specify a region. You can also configure your region by running \"aws configure\"."
}
```

**Example: Nonexistent Lambda function**

```JSON
{
    "Code": "ResourceNotFoundException",
    "Message": "Function not found: arn:aws:lambda:us-west-2:123456789012:function:nonexistent-function-12345",
    "Type": "User"
}
```

### YAML format
<a name="cli-error-format-yaml"></a>

The YAML format provides a structured representation with all error fields.

**Example: Missing region configuration**

```YAML
Code: NoRegion
Message: You must specify a region. You can also configure your region by running "aws configure".
```

**Example: Nonexistent Lambda function**

```YAML
Code: ResourceNotFoundException
Message: "Function not found: arn:aws:lambda:us-west-2:123456789012:function:nonexistent-function-12345"
Type: User
```

### Text format
<a name="cli-error-format-text"></a>

The text format uses the same formatter as successful command output.

**Example: Nonexistent Lambda function**

```NONE
ResourceNotFoundException    Function not found: arn:aws:lambda:us-west-2:123456789012:function:nonexistent-function-12345    User
```

### Table format
<a name="cli-error-format-table"></a>

The table format uses the same formatter as successful command output.

**Example: Nonexistent Lambda function**

```NONE
------------------------------------------------------------------------------------------------------------------------------------|
|                                                              error                                                                 |
+----------------------------+--------------------------------------------------------------------------------------------------+------+
|            Code            |                              Message                                                             | Type |
+----------------------------+--------------------------------------------------------------------------------------------------+------+
|  ResourceNotFoundException |  Function not found: arn:aws:lambda:us-west-2:123456789012:function:nonexistent-function-12345   | User |
+----------------------------+--------------------------------------------------------------------------------------------------+------+
```

### Legacy format
<a name="cli-error-format-legacy"></a>

The legacy format provides the original error format without structured details. This format does not include the "An error occurred (ErrorCode):" prefix for CLI exceptions.

**Example: Missing region configuration**

```NONE
aws: [ERROR]: You must specify a region. You can also configure your region by running "aws configure".
```

**Example: Nonexistent Lambda function**

```NONE
An error occurred (ResourceNotFoundException) when calling the GetFunction operation: Function not found: arn:aws:lambda:us-west-2:123456789012:function:nonexistent-function-12345
```

**Note**  
Errors now consistently include the `aws: [ERROR]:` prefix for CLI exceptions. Earlier versions did not always include this prefix.  
The following exceptions always use the legacy format regardless of the configured error format:  
`UnknownArgumentError` – Displays usage information
Keyboard interrupts (`KeyboardInterrupt`)

## Complete example
<a name="cli-error-format-example"></a>

The following example shows a command with JSON error formatting:

```BASH
$ aws lambda get-function \
    --function-name nonexistent-function-12345 \
    --cli-error-format json
```

Output (stderr):

```JSON
{
    "Code": "ResourceNotFoundException",
    "Message": "Function not found: arn:aws:lambda:us-west-2:123456789012:function:nonexistent-function-12345",
    "Type": "User"
}
```

The `Type` field is a modeled error member defined in the Lambda service's error shape. Only fields defined in the service's error model are included in the structured error output.