# InitCommandOptions

Options for InitCommand.

Used as argument in: [InitCommand.argvCommand](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InitCommand.html#argvcommand), [InitCommand.shellCommand](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InitCommand.html#shellcommand)

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

## Example

TypeScript:

```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 }),
);
```

Python:

```python
handle = ec2.InitServiceRestartHandle()
ec2.CloudFormationInit.from_elements(
    ec2.InitCommand.shell_command("/usr/bin/custom-nginx-install.sh", service_restart_handles=[handle]),
    ec2.InitService.enable("nginx", service_restart_handle=handle))
```

Java:

```java
InitServiceRestartHandle handle = new InitServiceRestartHandle();
CloudFormationInit.fromElements(InitCommand.shellCommand("/usr/bin/custom-nginx-install.sh", InitCommandOptions.builder().serviceRestartHandles(List.of(handle)).build()), InitService.enable("nginx", InitServiceOptions.builder().serviceRestartHandle(handle).build()));
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var handle = new InitServiceRestartHandle();
CloudFormationInit.FromElements(InitCommand.ShellCommand("/usr/bin/custom-nginx-install.sh", new InitCommandOptions { ServiceRestartHandles = new [] { handle } }), InitService.Enable("nginx", new InitServiceOptions { ServiceRestartHandle = handle }));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
handle := ec2.NewInitServiceRestartHandle()
ec2.CloudFormationInit_FromElements(ec2.InitCommand_ShellCommand(jsii.String("/usr/bin/custom-nginx-install.sh"), &InitCommandOptions{
	ServiceRestartHandles: []InitServiceRestartHandle{
		handle,
	},
}), ec2.InitService_Enable(jsii.String("nginx"), &InitServiceOptions{
	ServiceRestartHandle: handle,
}))
```

## Properties

- `cwd`: string — The working directory.

  **Default:** Use default working directory

- `env`: { [key: string]: string } — Sets environment variables for the command.

  **Default:** Use current environment

  This property overwrites, rather than appends, the existing environment.

- `ignoreErrors`: boolean = false — Continue running if this command fails.

- `key`: string — Identifier key for this command.

  **Default:** Automatically generated based on index

  Commands are executed in lexicographical order of their key names.

- `serviceRestartHandles`: [InitServiceRestartHandle](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InitServiceRestartHandle.html)[] — Restart the given service(s) after this command has run.

  **Default:** Do not restart any service

- `testCmd`: string — Command to determine whether this command should be run.

  **Default:** Always run the command

  If the test passes (exits with error code of 0), the command is run.

- `waitAfterCompletion`: [InitCommandWaitDuration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InitCommandWaitDuration.html) — The duration to wait after a command has finished in case the command causes a reboot.

  **Default:** 60 seconds

  Set this value to `InitCommandWaitDuration.none()` if you do not want to wait for every command;
  `InitCommandWaitDuration.forever()` directs cfn-init to exit and resume only after the reboot is complete.

  For Windows systems only.
