Skip to content
v2.273.0

SystemdConfigFileOptions Struct ​

Options for creating a SystemD configuration file.

Example ​

ts
declare const vpc: ec2.Vpc;
declare const instanceType: ec2.InstanceType;

new ec2.Instance(this, 'Instance', {
  vpc,
  instanceType,
  machineImage: ec2.MachineImage.latestAmazonLinux2023(),

  init: ec2.CloudFormationInit.fromElements(
    // Create a simple config file that runs a Python web server
    ec2.InitService.systemdConfigFile('simpleserver', {
      command: '/usr/bin/python3 -m http.server 8080',
      cwd: '/var/www/html',
    }),
    // Start the server using SystemD
    ec2.InitService.enable('simpleserver', {
      serviceManager: ec2.ServiceManager.SYSTEMD,
    }),
    // Drop an example file to show the web server working
    ec2.InitFile.fromString('/var/www/html/index.html', 'Hello! It\'s working!'),
  ),
});

Properties ​

afterNetworkbooleanafter_networkboolafterNetworkBooleanAfterNetworkboolAfterNetwork*bool= true#
Start the service after the networking part of the OS comes up.
commandstringcommandstrcommandStringCommandstringCommand*stringrequired#
The command to run to start this service.
cwdstringcwdstrcwdStringCwdstringCwd*string= Root directory or home directory…#
The working directory for the command.
default

Default: Root directory or home directory of specified user

descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= No description#
A description of this service.
environmentFilesstring[]environment_filestyping.List[str]environmentFilesList<String>EnvironmentFilesstring[]EnvironmentFiles*[]*string= No environment files#
Loads environment variables from files when the process is running.

Must use absolute paths.

environmentVariables{ [key: string]: string }environment_variablestyping.Mapping[str, str]environmentVariablesMap<String, String>EnvironmentVariablesIDictionary<string, string>EnvironmentVariables*map[string]*string= No environment variables set#
Environment variables to load when the process is running.
groupstringgroupstrgroupStringGroupstringGroup*string= root#
The group to execute the process under.
keepRunningbooleankeep_runningboolkeepRunningBooleanKeepRunningboolKeepRunning*bool= true#
Keep the process running all the time.

Restarts the process when it exits for any reason other than the machine shutting down.

userstringuserstruserStringUserstringUser*string= root#
The user to execute the process under.