Class AssetStaging
Stages a file or directory from a location on the file system into a staging directory.
Inheritance
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class AssetStaging : Construct
Syntax (vb)
Public Class AssetStaging
Inherits Construct
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
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
BundlingFileAccess = BundlingFileAccess.VOLUME_COPY,
Command = new [] { "command" },
Entrypoint = new [] { "entrypoint" },
Environment = new Dictionary<string, string> {
{ "environmentKey", "environment" }
},
Local = localBundling,
Network = "network",
OutputType = BundlingOutput.ARCHIVED,
Platform = "platform",
SecurityOpt = "securityOpt",
User = "user",
Volumes = new [] { new DockerVolume {
ContainerPath = "containerPath",
HostPath = "hostPath",
// the properties below are optional
Consistency = DockerVolumeConsistency.CONSISTENT
} },
VolumesFrom = new [] { "volumesFrom" },
WorkingDirectory = "workingDirectory"
},
Exclude = new [] { "exclude" },
ExtraHash = "extraHash",
Follow = SymlinkFollowMode.NEVER,
IgnoreMode = IgnoreMode.GLOB
});
Synopsis
Constructors
AssetStaging(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
AssetStaging(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
AssetStaging(Construct, String, IAssetStagingProps) |
Properties
AbsoluteStagedPath | Absolute path to the asset data. |
AssetHash | A cryptographic hash of the asset. |
BUNDLING_INPUT_DIR | The directory inside the bundling container into which the asset sources will be mounted. |
BUNDLING_OUTPUT_DIR | The directory inside the bundling container into which the bundled output should be written. |
IsArchive | Whether this asset is an archive (zip or jar). |
Packaging | How this asset should be packaged. |
SourcePath | The absolute path of the asset as it was referenced by the user. |
Methods
ClearAssetHashCache() | Clears the asset hash cache. |
RelativeStagedPath(Stack) | Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack. |
Constructors
AssetStaging(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected AssetStaging(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
AssetStaging(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected AssetStaging(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
AssetStaging(Construct, String, IAssetStagingProps)
public AssetStaging(Construct scope, string id, IAssetStagingProps props)
Parameters
- scope Constructs.Construct
- id System.String
- props IAssetStagingProps
Properties
AbsoluteStagedPath
Absolute path to the asset data.
public virtual string AbsoluteStagedPath { get; }
Property Value
System.String
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
System.String
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
System.String
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
System.String
IsArchive
Whether this asset is an archive (zip or jar).
public virtual bool IsArchive { get; }
Property Value
System.Boolean
Packaging
How this asset should be packaged.
public virtual FileAssetPackaging Packaging { get; }
Property Value
SourcePath
The absolute path of the asset as it was referenced by the user.
public virtual string SourcePath { get; }
Property Value
System.String
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
System.String
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" }