# Read an instance's user data

Read the cloud-init script an instance was launched with, which describing the instance never returns.

Describing an instance (`GET /ec2/api/instances`, `GET /ec2/api/instances/{id}`, the instances of
a security group, every console page) never returns its user data: a boot script is where
credentials tend to be written. It is read on its own, with its own permission.

## Prerequisites

- Permission for `ec2:GetInstanceUserData`. It is a sensitive read: it is not in the read-only
  presets, and every use, allowed or refused, is written to the audit log.

## Read it

**Console:** not available. The console never shows user data after launch.

**CLI**
```sh
dcloud ec2 instances get-user-data i-3f9a2c07
```

**API**
```http
GET /ec2/api/instances/i-3f9a2c07/user-data
```

**Terraform:** not available. `user_data` on `dcloud_instance` is never read back from the API.

## Result

`data.userData` is the script as you wrote it, or `null` when the instance was launched without
one. An instance that is not yours answers `404` "Instance not found"; without the permission the
answer is `403`. It is your script only: what the platform
adds to the machine's first boot (see
[What runs on your machines](what-runs-on-your-machines.md)) is not in it, nor is the instance's
identity secret.

## Related

- [Security](security.md)
- `ec2.instances.get-user-data` · `dcloud ec2 instances get-user-data`
