Class UserData

java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.ec2.UserData
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
Direct Known Subclasses:
MultipartUserData

@Generated(value="jsii-pacmak/1.104.0 (build e79254c)", date="2024-12-11T23:26:32.504Z") @Stability(Stable) public abstract class UserData extends software.amazon.jsii.JsiiObject
Instance User Data.

Example:

 Cluster cluster;
 UserData userData = UserData.forLinux();
 userData.addCommands("set -o xtrace", String.format("/etc/eks/bootstrap.sh %s", cluster.getClusterName()));
 CfnLaunchTemplate lt = CfnLaunchTemplate.Builder.create(this, "LaunchTemplate")
         .launchTemplateData(LaunchTemplateDataProperty.builder()
                 .imageId("some-ami-id") // custom AMI
                 .instanceType("t3.small")
                 .userData(Fn.base64(userData.render()))
                 .build())
         .build();
 cluster.addNodegroupCapacity("extra-ng", NodegroupOptions.builder()
         .launchTemplateSpec(LaunchTemplateSpec.builder()
                 .id(lt.getRef())
                 .version(lt.getAttrLatestVersionNumber())
                 .build())
         .build());
 
  • Constructor Details

    • UserData

      protected UserData(software.amazon.jsii.JsiiObjectRef objRef)
    • UserData

      protected UserData(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • UserData

      @Stability(Stable) protected UserData()
  • Method Details

    • custom

      @Stability(Stable) @NotNull public static UserData custom(@NotNull String content)
      Create a userdata object with custom content.

      Parameters:
      content - This parameter is required.
    • forLinux

      @Stability(Stable) @NotNull public static UserData forLinux(@Nullable LinuxUserDataOptions options)
      Create a userdata object for Linux hosts.

      Parameters:
      options -
    • forLinux

      @Stability(Stable) @NotNull public static UserData forLinux()
      Create a userdata object for Linux hosts.
    • forOperatingSystem

      @Stability(Stable) @NotNull public static UserData forOperatingSystem(@NotNull OperatingSystemType os)
      Parameters:
      os - This parameter is required.
    • forWindows

      @Stability(Stable) @NotNull public static UserData forWindows(@Nullable WindowsUserDataOptions options)
      Create a userdata object for Windows hosts.

      Parameters:
      options -
    • forWindows

      @Stability(Stable) @NotNull public static UserData forWindows()
      Create a userdata object for Windows hosts.
    • addCommands

      @Stability(Stable) public abstract void addCommands(@NotNull @NotNull String... commands)
      Add one or more commands to the user data.

      Parameters:
      commands - This parameter is required.
    • addExecuteFileCommand

      @Stability(Stable) public abstract void addExecuteFileCommand(@NotNull ExecuteFileOptions params)
      Adds commands to execute a file.

      Parameters:
      params - This parameter is required.
    • addOnExitCommands

      @Stability(Stable) public abstract void addOnExitCommands(@NotNull @NotNull String... commands)
      Add one or more commands to the user data that will run when the script exits.

      Parameters:
      commands - This parameter is required.
    • addS3DownloadCommand

      @Stability(Stable) @NotNull public abstract String addS3DownloadCommand(@NotNull S3DownloadOptions params)
      Adds commands to download a file from S3.

      Parameters:
      params - This parameter is required.
      Returns:
      : The local path that the file will be downloaded to
    • addSignalOnExitCommand

      @Stability(Stable) public abstract void addSignalOnExitCommand(@NotNull Resource resource)
      Adds a command which will send a cfn-signal when the user data script ends.

      Parameters:
      resource - This parameter is required.
    • render

      @Stability(Stable) @NotNull public abstract String render()
      Render the UserData for use in a construct.