aws-cdk-lib.aws_ec2.InitCommand

class InitCommand

LanguageType name
.NETAmazon.CDK.AWS.EC2.InitCommand
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsec2#InitCommand
Javasoftware.amazon.awscdk.services.ec2.InitCommand
Pythonaws_cdk.aws_ec2.InitCommand
TypeScript (source)aws-cdk-lib » aws_ec2 » InitCommand

Extends InitElement

Command to execute on the instance.

Example

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

NameTypeDescription
elementTypestringReturns the init element type for this element.

elementType

Type: string

Returns the init element type for this element.

Methods

NameDescription
static argvCommand(argv, options?)Run a command from an argv array.
static shellCommand(shellCommand, options?)Run a shell command.

static argvCommand(argv, options?)

public static argvCommand(argv: string[], options?: InitCommandOptions): InitCommand

Parameters

  • argv string[]
  • options InitCommandOptions

Returns

  • InitCommand

Run a command from an argv array.

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


static shellCommand(shellCommand, options?)

public static shellCommand(shellCommand: string, options?: InitCommandOptions): InitCommand

Parameters

  • shellCommand string
  • options InitCommandOptions

Returns

  • InitCommand

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.