# MultipartUserData

Mime multipart user data.

This class represents MIME multipart user data, as described in.
[Specifying Multiple User Data Blocks Using a MIME Multi Part Archive](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html#multi-part_user_data)

Extends: UserData › 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#L463)

## Example

```ts
const bootHookConf = ec2.UserData.forLinux();
bootHookConf.addCommands('cloud-init-per once docker_options echo \'OPTIONS="${OPTIONS} --storage-opt dm.basesize=40G"\' >> /etc/sysconfig/docker');

const setupCommands = ec2.UserData.forLinux();
setupCommands.addCommands('sudo yum install awscli && echo Packages installed らと > /var/tmp/setup');

const multipartUserData = new ec2.MultipartUserData();
// The docker has to be configured at early stage, so content type is overridden to boothook
multipartUserData.addPart(ec2.MultipartBody.fromUserData(bootHookConf, 'text/cloud-boothook; charset="us-ascii"'));
// Execute the rest of setup
multipartUserData.addPart(ec2.MultipartBody.fromUserData(setupCommands));

new ec2.LaunchTemplate(this, '', {
  userData: multipartUserData,
  blockDevices: [
    // Block device configuration rest
  ]
});
```

## Initializer

```ts
new MultipartUserData(opts?: MultipartUserDataOptions)
```

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

- `addPart(part: MultipartBody): void` — Adds a part to the list of parts.

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

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

- `addUserDataPart(userData: UserData, contentType?: string, makeDefault?: boolean): void` — Adds a multipart part based on a UserData object.

  If `makeDefault` is true, then the UserData added by this method
  will also be the target of calls to the `add*Command` methods on
  this MultipartUserData object.

  If `makeDefault` is false, then this is the same as calling:

  ```ts
  declare const multiPart: ec2.MultipartUserData;
  declare const userData: ec2.UserData;
  declare const contentType: string;

  multiPart.addPart(ec2.MultipartBody.fromUserData(userData, contentType));
  ```

  An undefined `makeDefault` defaults to either:
  - `true` if no default UserData has been set yet; or
  - `false` if there is no default UserData set.

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

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

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

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

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