InitServiceRestartHandle

class aws_cdk.aws_ec2.InitServiceRestartHandle

Bases: object

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:

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

infused

Example:

# my_bucket: s3.Bucket


handle = ec2.InitServiceRestartHandle()

ec2.CloudFormationInit.from_elements(
    ec2.InitFile.from_string("/etc/nginx/nginx.conf", "...", service_restart_handles=[handle]),
    ec2.InitSource.from_s3_object("/var/www/html", my_bucket, "html.zip", service_restart_handles=[handle]),
    ec2.InitService.enable("nginx",
        service_restart_handle=handle
    ))