# UserData

Instance User Data.

Extends: UserData
Superclass of: MultipartUserData

- Source: [`aws-ec2/lib/user-data.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-ec2/lib/user-data.ts#L90)
- Type last changed: v2.46.0 · 13 Oct 2022

## Example

```ts
declare const cluster: eks.Cluster;
const userData = ec2.UserData.forLinux();
userData.addCommands(
  'set -o xtrace',
  `/etc/eks/bootstrap.sh ${cluster.clusterName}`,
);
const lt = new ec2.CfnLaunchTemplate(this, 'LaunchTemplate', {
  launchTemplateData: {
    imageId: 'some-ami-id', // custom AMI
    instanceType: 't3.small',
    userData: Fn.base64(userData.render()),
  },
});
cluster.addNodegroupCapacity('extra-ng', {
  launchTemplateSpec: {
    id: lt.ref,
    version: lt.attrLatestVersionNumber,
  },
});
```

## Initializer

```ts
new UserData()
```

## Methods

- `addCommands(...commands: string[]): void` — Add one or more commands to the user data.

- `addExecuteFileCommand(params: ExecuteFileOptions): void` — Adds commands to execute a file.

- `addOnExitCommands(...commands: string[]): void` — Add one or more commands to the user data that will run when the script exits.

- `addS3DownloadCommand(params: S3DownloadOptions): string` — Adds commands to download a file from S3.

  **Returns:** : The local path that the file will be downloaded to

- `addSignalOnExitCommand(resource: Resource): void` — Adds a command which will send a cfn-signal when the user data script ends.

- `custom(content: string): UserData // chainable` (static) — Create a userdata object with custom content.

- `forLinux(options?: LinuxUserDataOptions): UserData // chainable` (static) — Create a userdata object for Linux hosts.

- `forOperatingSystem(os: OperatingSystemType): UserData // chainable` (static)

- `forWindows(options?: WindowsUserDataOptions): UserData // chainable` (static) — Create a userdata object for Windows hosts.

- `render(): string` — Render the UserData for use in a construct.
