Class AssetStaging

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.core.Construct
software.amazon.awscdk.core.AssetStaging
All Implemented Interfaces:
IConstruct, IDependable, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct
Direct Known Subclasses:
Staging

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:29:54.791Z") @Stability(Stable) public class AssetStaging extends Construct
Stages a file or directory from a location on the file system into a staging directory.

This is controlled by the context key 'aws:cdk:asset-staging' and enabled by the CLI by default in order to ensure that when the CDK app exists, all assets are available for deployment. Otherwise, if an app references assets in temporary locations, those will not be available when it exists (see https://github.com/aws/aws-cdk/issues/1716).

The stagedPath property is a stringified token that represents the location of the file or directory after staging. It will be resolved only during the "prepare" stage and may be either the original path or the staged path depending on the context setting.

The file/directory are staged based on their content hash (fingerprint). This means that only if content was changed, copy will happen.

Example:

 // The code below shows an example of how to instantiate this type.
 // The values are placeholders you should change.
 import software.amazon.awscdk.core.*;
 DockerImage dockerImage;
 ILocalBundling localBundling;
 AssetStaging assetStaging = AssetStaging.Builder.create(this, "MyAssetStaging")
         .sourcePath("sourcePath")
         // the properties below are optional
         .assetHash("assetHash")
         .assetHashType(AssetHashType.SOURCE)
         .bundling(BundlingOptions.builder()
                 .image(dockerImage)
                 // the properties below are optional
                 .command(List.of("command"))
                 .entrypoint(List.of("entrypoint"))
                 .environment(Map.of(
                         "environmentKey", "environment"))
                 .local(localBundling)
                 .outputType(BundlingOutput.ARCHIVED)
                 .securityOpt("securityOpt")
                 .user("user")
                 .volumes(List.of(DockerVolume.builder()
                         .containerPath("containerPath")
                         .hostPath("hostPath")
                         // the properties below are optional
                         .consistency(DockerVolumeConsistency.CONSISTENT)
                         .build()))
                 .workingDirectory("workingDirectory")
                 .build())
         .exclude(List.of("exclude"))
         .extraHash("extraHash")
         .follow(SymlinkFollowMode.NEVER)
         .ignoreMode(IgnoreMode.GLOB)
         .build();
 
  • Field Details

    • BUNDLING_INPUT_DIR

      @Stability(Stable) public static final String BUNDLING_INPUT_DIR
      The directory inside the bundling container into which the asset sources will be mounted.
    • BUNDLING_OUTPUT_DIR

      @Stability(Stable) public static final String BUNDLING_OUTPUT_DIR
      The directory inside the bundling container into which the bundled output should be written.
  • Constructor Details

    • AssetStaging

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

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

      @Stability(Stable) public AssetStaging(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull AssetStagingProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • clearAssetHashCache

      @Stability(Stable) public static void clearAssetHashCache()
      Clears the asset hash cache.
    • relativeStagedPath

      @Stability(Stable) @NotNull public String relativeStagedPath(@NotNull Stack stack)
      Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack.

      Only returns a relative path if the asset was staged, returns an absolute path if it was not staged.

      A bundled asset might end up in the outDir and still not count as "staged"; if asset staging is disabled we're technically expected to reference source directories, but we don't have a source directory for the bundled outputs (as the bundle output is written to a temporary directory). Nevertheless, we will still return an absolute path.

      A non-obvious directory layout may look like this:

          CLOUD ASSEMBLY ROOT
            +-- asset.12345abcdef/
            +-- assembly-Stage
                  +-- MyStack.template.json
                  +-- MyStack.assets.json <- will contain { "path": "../asset.12345abcdef" }
       

      Parameters:
      stack - This parameter is required.
    • getAbsoluteStagedPath

      @Stability(Stable) @NotNull public String getAbsoluteStagedPath()
      Absolute path to the asset data.

      If asset staging is disabled, this will just be the source path or a temporary directory used for bundling.

      If asset staging is enabled it will be the staged path.

      IMPORTANT: If you are going to call addFileAsset(), use relativeStagedPath() instead.

    • getAssetHash

      @Stability(Stable) @NotNull public String getAssetHash()
      A cryptographic hash of the asset.
    • getIsArchive

      @Stability(Stable) @NotNull public Boolean getIsArchive()
      Whether this asset is an archive (zip or jar).
    • getPackaging

      @Stability(Stable) @NotNull public FileAssetPackaging getPackaging()
      How this asset should be packaged.
    • getSourceHash

      @Stability(Deprecated) @Deprecated @NotNull public String getSourceHash()
      Deprecated.
      see assetHash.
      (deprecated) A cryptographic hash of the asset.

    • getSourcePath

      @Stability(Stable) @NotNull public String getSourcePath()
      The absolute path of the asset as it was referenced by the user.
    • getStagedPath

      @Stability(Deprecated) @Deprecated @NotNull public String getStagedPath()
      Deprecated.
      • Use absoluteStagedPath instead.
      (deprecated) Absolute path to the asset data.

      If asset staging is disabled, this will just be the source path or a temporary directory used for bundling.

      If asset staging is enabled it will be the staged path.

      IMPORTANT: If you are going to call addFileAsset(), use relativeStagedPath() instead.