InitCommand

class aws_cdk.aws_ec2.InitCommand

Bases: InitElement

Command to execute on the instance.

ExampleMetadata:

infused

Example:

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))

Attributes

element_type

Returns the init element type for this element.

Static Methods

classmethod argv_command(argv, *, cwd=None, env=None, ignore_errors=None, key=None, service_restart_handles=None, test_cmd=None, wait_after_completion=None)

Run a command from an argv array.

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

Parameters:
  • argv (Sequence[str]) –

  • cwd (Optional[str]) – The working directory. Default: - Use default working directory

  • env (Optional[Mapping[str, str]]) – Sets environment variables for the command. This property overwrites, rather than appends, the existing environment. Default: - Use current environment

  • ignore_errors (Optional[bool]) – Continue running if this command fails. Default: false

  • key (Optional[str]) – Identifier key for this command. Commands are executed in lexicographical order of their key names. Default: - Automatically generated based on index

  • service_restart_handles (Optional[Sequence[InitServiceRestartHandle]]) – Restart the given service(s) after this command has run. Default: - Do not restart any service

  • test_cmd (Optional[str]) – Command to determine whether this command should be run. If the test passes (exits with error code of 0), the command is run. Default: - Always run the command

  • wait_after_completion (Optional[InitCommandWaitDuration]) – The duration to wait after a command has finished in case the command causes a reboot. 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. Default: - 60 seconds

Return type:

InitCommand

classmethod shell_command(shell_command, *, cwd=None, env=None, ignore_errors=None, key=None, service_restart_handles=None, test_cmd=None, wait_after_completion=None)

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.

Parameters:
  • shell_command (str) –

  • cwd (Optional[str]) – The working directory. Default: - Use default working directory

  • env (Optional[Mapping[str, str]]) – Sets environment variables for the command. This property overwrites, rather than appends, the existing environment. Default: - Use current environment

  • ignore_errors (Optional[bool]) – Continue running if this command fails. Default: false

  • key (Optional[str]) – Identifier key for this command. Commands are executed in lexicographical order of their key names. Default: - Automatically generated based on index

  • service_restart_handles (Optional[Sequence[InitServiceRestartHandle]]) – Restart the given service(s) after this command has run. Default: - Do not restart any service

  • test_cmd (Optional[str]) – Command to determine whether this command should be run. If the test passes (exits with error code of 0), the command is run. Default: - Always run the command

  • wait_after_completion (Optional[InitCommandWaitDuration]) – The duration to wait after a command has finished in case the command causes a reboot. 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. Default: - 60 seconds

Return type:

InitCommand