Class InitFile

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

@Generated(value="jsii-pacmak/1.98.0 (build 00b106d)", date="2024-05-08T21:35:06.154Z") @Stability(Stable) public abstract class InitFile extends InitElement
Create files on the EC2 instance.

Example:

 Vpc vpc;
 InstanceType instanceType;
 Instance.Builder.create(this, "Instance")
         .vpc(vpc)
         .instanceType(instanceType)
         .machineImage(MachineImage.latestAmazonLinux2023())
         .init(CloudFormationInit.fromElements(InitService.systemdConfigFile("simpleserver", SystemdConfigFileOptions.builder()
                 .command("/usr/bin/python3 -m http.server 8080")
                 .cwd("/var/www/html")
                 .build()), InitService.enable("simpleserver", InitServiceOptions.builder()
                 .serviceManager(ServiceManager.SYSTEMD)
                 .build()), InitFile.fromString("/var/www/html/index.html", "Hello! It's working!")))
         .build();
 
  • Constructor Details

    • InitFile

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

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

      @Stability(Stable) protected InitFile(@NotNull String fileName, @NotNull InitFileOptions options)
      Parameters:
      fileName - This parameter is required.
      options - This parameter is required.
  • Method Details

    • fromAsset

      @Stability(Stable) @NotNull public static InitFile fromAsset(@NotNull String targetFileName, @NotNull String path, @Nullable InitFileAssetOptions options)
      Create an asset from the given file.

      This is appropriate for files that are too large to embed into the template.

      Parameters:
      targetFileName - This parameter is required.
      path - This parameter is required.
      options -
    • fromAsset

      @Stability(Stable) @NotNull public static InitFile fromAsset(@NotNull String targetFileName, @NotNull String path)
      Create an asset from the given file.

      This is appropriate for files that are too large to embed into the template.

      Parameters:
      targetFileName - This parameter is required.
      path - This parameter is required.
    • fromExistingAsset

      @Stability(Stable) @NotNull public static InitFile fromExistingAsset(@NotNull String targetFileName, @NotNull Asset asset, @Nullable InitFileOptions options)
      Use a file from an asset at instance startup time.

      Parameters:
      targetFileName - This parameter is required.
      asset - This parameter is required.
      options -
    • fromExistingAsset

      @Stability(Stable) @NotNull public static InitFile fromExistingAsset(@NotNull String targetFileName, @NotNull Asset asset)
      Use a file from an asset at instance startup time.

      Parameters:
      targetFileName - This parameter is required.
      asset - This parameter is required.
    • fromFileInline

      @Stability(Stable) @NotNull public static InitFile fromFileInline(@NotNull String targetFileName, @NotNull String sourceFileName, @Nullable InitFileOptions options)
      Read a file from disk and use its contents.

      The file will be embedded in the template, so care should be taken to not exceed the template size.

      If options.base64encoded is set to true, this will base64-encode the file's contents.

      Parameters:
      targetFileName - This parameter is required.
      sourceFileName - This parameter is required.
      options -
    • fromFileInline

      @Stability(Stable) @NotNull public static InitFile fromFileInline(@NotNull String targetFileName, @NotNull String sourceFileName)
      Read a file from disk and use its contents.

      The file will be embedded in the template, so care should be taken to not exceed the template size.

      If options.base64encoded is set to true, this will base64-encode the file's contents.

      Parameters:
      targetFileName - This parameter is required.
      sourceFileName - This parameter is required.
    • fromObject

      @Stability(Stable) @NotNull public static InitFile fromObject(@NotNull String fileName, @NotNull Map<String,? extends Object> obj, @Nullable InitFileOptions options)
      Use a JSON-compatible object as the file content, write it to a JSON file.

      May contain tokens.

      Parameters:
      fileName - This parameter is required.
      obj - This parameter is required.
      options -
    • fromObject

      @Stability(Stable) @NotNull public static InitFile fromObject(@NotNull String fileName, @NotNull Map<String,? extends Object> obj)
      Use a JSON-compatible object as the file content, write it to a JSON file.

      May contain tokens.

      Parameters:
      fileName - This parameter is required.
      obj - This parameter is required.
    • fromS3Object

      @Stability(Stable) @NotNull public static InitFile fromS3Object(@NotNull String fileName, @NotNull IBucket bucket, @NotNull String key, @Nullable InitFileOptions options)
      Download a file from an S3 bucket at instance startup time.

      Parameters:
      fileName - This parameter is required.
      bucket - This parameter is required.
      key - This parameter is required.
      options -
    • fromS3Object

      @Stability(Stable) @NotNull public static InitFile fromS3Object(@NotNull String fileName, @NotNull IBucket bucket, @NotNull String key)
      Download a file from an S3 bucket at instance startup time.

      Parameters:
      fileName - This parameter is required.
      bucket - This parameter is required.
      key - This parameter is required.
    • fromString

      @Stability(Stable) @NotNull public static InitFile fromString(@NotNull String fileName, @NotNull String content, @Nullable InitFileOptions options)
      Use a literal string as the file content.

      Parameters:
      fileName - This parameter is required.
      content - This parameter is required.
      options -
    • fromString

      @Stability(Stable) @NotNull public static InitFile fromString(@NotNull String fileName, @NotNull String content)
      Use a literal string as the file content.

      Parameters:
      fileName - This parameter is required.
      content - This parameter is required.
    • fromUrl

      @Stability(Stable) @NotNull public static InitFile fromUrl(@NotNull String fileName, @NotNull String url, @Nullable InitFileOptions options)
      Download from a URL at instance startup time.

      Parameters:
      fileName - This parameter is required.
      url - This parameter is required.
      options -
    • fromUrl

      @Stability(Stable) @NotNull public static InitFile fromUrl(@NotNull String fileName, @NotNull String url)
      Download from a URL at instance startup time.

      Parameters:
      fileName - This parameter is required.
      url - This parameter is required.
    • symlink

      @Stability(Stable) @NotNull public static InitFile symlink(@NotNull String fileName, @NotNull String target, @Nullable InitFileOptions options)
      Write a symlink with the given symlink target.

      Parameters:
      fileName - This parameter is required.
      target - This parameter is required.
      options -
    • symlink

      @Stability(Stable) @NotNull public static InitFile symlink(@NotNull String fileName, @NotNull String target)
      Write a symlink with the given symlink target.

      Parameters:
      fileName - This parameter is required.
      target - This parameter is required.
    • getElementType

      @Stability(Stable) @NotNull public String getElementType()
      Returns the init element type for this element.
      Specified by:
      getElementType in class InitElement