# InitCommand

Command to execute on the instance.

Extends: InitElement › InitCommand

- Source: [`aws-ec2/lib/cfn-init-elements.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-ec2/lib/cfn-init-elements.ts#L207)

## Example

```ts
const handle = new ec2.InitServiceRestartHandle();
ec2.CloudFormationInit.fromElements(
  ec2.InitCommand.shellCommand('/usr/bin/custom-nginx-install.sh', { serviceRestartHandles: [handle] }),
  ec2.InitService.enable('nginx', { serviceRestartHandle: handle }),
);
```

## Properties

- `elementType`: string (required) — Returns the init element type for this element.

## Methods

- `argvCommand(argv: string[], options?: InitCommandOptions): InitCommand // chainable` (static) — Run a command from an argv array.

  You do not need to escape space characters or enclose command parameters in quotes.

- `shellCommand(shellCommand: string, options?: InitCommandOptions): InitCommand // chainable` (static) — Run a shell command.

  Remember that some characters like `&`, `|`, `;`, `>` etc. have special meaning in a shell and
  need to be preceded by a `\` if you want to treat them as part of a filename.
