aws-cdk-lib.aws_ec2.InitServiceRestartHandle

class InitServiceRestartHandle

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

An object that represents reasons to restart an InitService.

Pass an instance of this object to the InitFile, InitCommand, InitSource and InitPackage objects, and finally to an InitService itself to cause the actions (files, commands, sources, and packages) to trigger a restart of the service.

For example, the following will run a custom command to install Nginx, and trigger the nginx service to be restarted after the command has run.

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

Example

declare const myBucket: s3.Bucket;

const handle = new ec2.InitServiceRestartHandle();

ec2.CloudFormationInit.fromElements(
  ec2.InitFile.fromString('/etc/nginx/nginx.conf', '...', { serviceRestartHandles: [handle] }),
  ec2.InitSource.fromS3Object('/var/www/html', myBucket, 'html.zip', { serviceRestartHandles: [handle] }),
  ec2.InitService.enable('nginx', {
    serviceRestartHandle: handle,
  })
);

Initializer

new InitServiceRestartHandle()