Class MultipartUserData

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

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:39.462Z") @Stability(Stable) public class MultipartUserData extends UserData
Mime multipart user data.

This class represents MIME multipart user data, as described in. Specifying Multiple User Data Blocks Using a MIME Multi Part Archive

Example:

 UserData bootHookConf = UserData.forLinux();
 bootHookConf.addCommands("cloud-init-per once docker_options echo 'OPTIONS=\"${OPTIONS} --storage-opt dm.basesize=40G\"' >> /etc/sysconfig/docker");
 UserData setupCommands = UserData.forLinux();
 setupCommands.addCommands("sudo yum install awscli && echo Packages installed らと > /var/tmp/setup");
 MultipartUserData multipartUserData = new MultipartUserData();
 // The docker has to be configured at early stage, so content type is overridden to boothook
 multipartUserData.addPart(MultipartBody.fromUserData(bootHookConf, "text/cloud-boothook; charset=\"us-ascii\""));
 // Execute the rest of setup
 multipartUserData.addPart(MultipartBody.fromUserData(setupCommands));
 LaunchTemplate.Builder.create(this, "")
         .userData(multipartUserData)
         .blockDevices(List.of())
         .build();
 
  • Constructor Details

    • MultipartUserData

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

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

      @Stability(Stable) public MultipartUserData(@Nullable MultipartUserDataOptions opts)
      Parameters:
      opts -
    • MultipartUserData

      @Stability(Stable) public MultipartUserData()
  • Method Details

    • addCommands

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

      Specified by:
      addCommands in class UserData
      Parameters:
      commands - This parameter is required.
    • addExecuteFileCommand

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

      Specified by:
      addExecuteFileCommand in class UserData
      Parameters:
      params - This parameter is required.
    • addOnExitCommands

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

      Specified by:
      addOnExitCommands in class UserData
      Parameters:
      commands - This parameter is required.
    • addPart

      @Stability(Stable) public void addPart(@NotNull MultipartBody part)
      Adds a part to the list of parts.

      Parameters:
      part - This parameter is required.
    • addS3DownloadCommand

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

      Specified by:
      addS3DownloadCommand in class UserData
      Parameters:
      params - This parameter is required.
      Returns:
      : The local path that the file will be downloaded to
    • addSignalOnExitCommand

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

      Specified by:
      addSignalOnExitCommand in class UserData
      Parameters:
      resource - This parameter is required.
    • addUserDataPart

      @Stability(Stable) public void addUserDataPart(@NotNull UserData userData, @Nullable String contentType, @Nullable Boolean makeDefault)
      Adds a multipart part based on a UserData object.

      If makeDefault is true, then the UserData added by this method will also be the target of calls to the add*Command methods on this MultipartUserData object.

      If makeDefault is false, then this is the same as calling:

       MultipartUserData multiPart;
       UserData userData;
       String contentType;
       multiPart.addPart(MultipartBody.fromUserData(userData, contentType));
       

      An undefined makeDefault defaults to either:

      • true if no default UserData has been set yet; or
      • false if there is no default UserData set.

      Parameters:
      userData - This parameter is required.
      contentType -
      makeDefault -
    • addUserDataPart

      @Stability(Stable) public void addUserDataPart(@NotNull UserData userData, @Nullable String contentType)
      Adds a multipart part based on a UserData object.

      If makeDefault is true, then the UserData added by this method will also be the target of calls to the add*Command methods on this MultipartUserData object.

      If makeDefault is false, then this is the same as calling:

       MultipartUserData multiPart;
       UserData userData;
       String contentType;
       multiPart.addPart(MultipartBody.fromUserData(userData, contentType));
       

      An undefined makeDefault defaults to either:

      • true if no default UserData has been set yet; or
      • false if there is no default UserData set.

      Parameters:
      userData - This parameter is required.
      contentType -
    • addUserDataPart

      @Stability(Stable) public void addUserDataPart(@NotNull UserData userData)
      Adds a multipart part based on a UserData object.

      If makeDefault is true, then the UserData added by this method will also be the target of calls to the add*Command methods on this MultipartUserData object.

      If makeDefault is false, then this is the same as calling:

       MultipartUserData multiPart;
       UserData userData;
       String contentType;
       multiPart.addPart(MultipartBody.fromUserData(userData, contentType));
       

      An undefined makeDefault defaults to either:

      • true if no default UserData has been set yet; or
      • false if there is no default UserData set.

      Parameters:
      userData - This parameter is required.
    • render

      @Stability(Stable) @NotNull public String render()
      Render the UserData for use in a construct.
      Specified by:
      render in class UserData