InitCommand Class
Command to execute on the instance.
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 }),
);
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
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()));
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 }));
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
Returns the init element type for this element.
Methods
argvCommand(argv: string[], options?: InitCommandOptions): InitCommand // chainable@staticmethod def argv_command(argv: typing.List[str], options: typing.Optional[InitCommandOptions] = None) -> InitCommandpublic static InitCommand argvCommand(List<String> argv, InitCommandOptions options)public static InitCommand ArgvCommand(string[] argv, InitCommandOptions? options = null)func ArgvCommand(Argv *[]*string, Options InitCommandOptions) InitCommandstatic#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@staticmethod def shell_command(shell_command: str, options: typing.Optional[InitCommandOptions] = None) -> InitCommandpublic static InitCommand shellCommand(String shellCommand, InitCommandOptions options)public static InitCommand ShellCommand(string shellCommand, InitCommandOptions? options = null)func ShellCommand(ShellCommand *string, Options InitCommandOptions) InitCommandstatic#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.