Class AssetStaging
Stages a file or directory from a location on the file system into a staging directory.
public class AssetStaging : Construct, IConstruct, IConstruct, IDependable
- Inheritance
-
AssetStaging
- Implements
-
IConstruct
- Inherited Members
Examples
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
DockerImage dockerImage;
ILocalBundling localBundling;
var assetStaging = new AssetStaging(this, "MyAssetStaging", new AssetStagingProps {
SourcePath = "sourcePath",
// the properties below are optional
AssetHash = "assetHash",
AssetHashType = AssetHashType.SOURCE,
Bundling = new BundlingOptions {
Image = dockerImage,
// the properties below are optional
Command = new [] { "command" },
Entrypoint = new [] { "entrypoint" },
Environment = new Dictionary<string, string> {
{ "environmentKey", "environment" }
},
Local = localBundling,
OutputType = BundlingOutput.ARCHIVED,
SecurityOpt = "securityOpt",
User = "user",
Volumes = new [] { new DockerVolume {
ContainerPath = "containerPath",
HostPath = "hostPath",
// the properties below are optional
Consistency = DockerVolumeConsistency.CONSISTENT
} },
WorkingDirectory = "workingDirectory"
},
Exclude = new [] { "exclude" },
ExtraHash = "extraHash",
Follow = SymlinkFollowMode.NEVER,
IgnoreMode = IgnoreMode.GLOB
});
Remarks
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.
ExampleMetadata: fixture=_generated
Constructors
AssetStaging(Construct, string, IAssetStagingProps)
public AssetStaging(Construct scope, string id, IAssetStagingProps props)
Parameters
scope
Constructid
stringprops
IAssetStagingProps
Properties
AbsoluteStagedPath
Absolute path to the asset data.
public virtual string AbsoluteStagedPath { get; }
Property Value
Remarks
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.
AssetHash
A cryptographic hash of the asset.
public virtual string AssetHash { get; }
Property Value
BUNDLING_INPUT_DIR
The directory inside the bundling container into which the asset sources will be mounted.
public static string BUNDLING_INPUT_DIR { get; }
Property Value
BUNDLING_OUTPUT_DIR
The directory inside the bundling container into which the bundled output should be written.
public static string BUNDLING_OUTPUT_DIR { get; }
Property Value
IsArchive
Whether this asset is an archive (zip or jar).
public virtual bool IsArchive { get; }
Property Value
Packaging
How this asset should be packaged.
public virtual FileAssetPackaging Packaging { get; }
Property Value
SourceHash
(deprecated) A cryptographic hash of the asset.
[Obsolete("see `assetHash`.")]
public virtual string SourceHash { get; }
Property Value
Remarks
Stability: Deprecated
SourcePath
The absolute path of the asset as it was referenced by the user.
public virtual string SourcePath { get; }
Property Value
StagedPath
(deprecated) Absolute path to the asset data.
[Obsolete("- Use `absoluteStagedPath` instead.")]
public virtual string StagedPath { get; }
Property Value
Remarks
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.
Stability: Deprecated
Methods
ClearAssetHashCache()
Clears the asset hash cache.
public static void ClearAssetHashCache()
RelativeStagedPath(Stack)
Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack.
public virtual string RelativeStagedPath(Stack stack)
Parameters
stack
Stack
Returns
Remarks
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" }