aws-cdk-lib.aws_ec2.InitService

class InitService

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

Extends InitElement

A services that be enabled, disabled or restarted when the instance is launched.

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

Properties

NameTypeDescription
elementTypestringReturns the init element type for this element.

elementType

Type: string

Returns the init element type for this element.

Methods

NameDescription
static disable(serviceName)Disable and stop the given service.
static enable(serviceName, options?)Enable and start the given service, optionally restarting it.
static systemdConfigFile(serviceName, options)Install a systemd-compatible config file for the given service.

static disable(serviceName)

public static disable(serviceName: string): InitService

Parameters

  • serviceName string

Returns

  • InitService

Disable and stop the given service.


static enable(serviceName, options?)

public static enable(serviceName: string, options?: InitServiceOptions): InitService

Parameters

  • serviceName string
  • options InitServiceOptions

Returns

  • InitService

Enable and start the given service, optionally restarting it.


static systemdConfigFile(serviceName, options)

public static systemdConfigFile(serviceName: string, options: SystemdConfigFileOptions): InitFile

Parameters

  • serviceName string
  • options SystemdConfigFileOptions

Returns

  • InitFile

Install a systemd-compatible config file for the given service.

This is a helper function to create a simple systemd configuration file that will allow running a service on the machine using InitService.enable().

Systemd allows many configuration options; this function does not pretend to expose all of them. If you need advanced configuration options, you can use InitFile to create exactly the configuration file you need at /etc/systemd/system/${serviceName}.service.