AssetStaging
- class aws_cdk.AssetStaging(scope, id, *, source_path, extra_hash=None, asset_hash=None, asset_hash_type=None, bundling=None, exclude=None, follow=None, ignore_mode=None)
Bases:
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.
- ExampleMetadata:
fixture=_generated
Example:
# The code below shows an example of how to instantiate this type. # The values are placeholders you should change. import aws_cdk as cdk # docker_image: cdk.DockerImage # local_bundling: cdk.ILocalBundling asset_staging = cdk.AssetStaging(self, "MyAssetStaging", source_path="sourcePath", # the properties below are optional asset_hash="assetHash", asset_hash_type=cdk.AssetHashType.SOURCE, bundling=cdk.BundlingOptions( image=docker_image, # the properties below are optional bundling_file_access=cdk.BundlingFileAccess.VOLUME_COPY, command=["command"], entrypoint=["entrypoint"], environment={ "environment_key": "environment" }, local=local_bundling, network="network", output_type=cdk.BundlingOutput.ARCHIVED, platform="platform", security_opt="securityOpt", user="user", volumes=[cdk.DockerVolume( container_path="containerPath", host_path="hostPath", # the properties below are optional consistency=cdk.DockerVolumeConsistency.CONSISTENT )], volumes_from=["volumesFrom"], working_directory="workingDirectory" ), exclude=["exclude"], extra_hash="extraHash", follow=cdk.SymlinkFollowMode.NEVER, ignore_mode=cdk.IgnoreMode.GLOB )
- Parameters:
scope (
Construct
)id (
str
)source_path (
str
) – The source file or directory to copy from.extra_hash (
Optional
[str
]) – Extra information to encode into the fingerprint (e.g. build instructions and other inputs). Default: - hash is only based on source contentasset_hash (
Optional
[str
]) – Specify a custom hash for this asset. IfassetHashType
is set it must be set toAssetHashType.CUSTOM
. For consistency, this custom hash will be SHA256 hashed and encoded as hex. The resulting hash will be the asset hash. NOTE: the hash is used in order to identify a specific revision of the asset, and used for optimizing and caching deployment activities related to this asset such as packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will need to make sure it is updated every time the asset changes, or otherwise it is possible that some deployments will not be invalidated. Default: - based onassetHashType
asset_hash_type (
Optional
[AssetHashType
]) – Specifies the type of hash to calculate for this asset. IfassetHash
is configured, this option must beundefined
orAssetHashType.CUSTOM
. Default: - the default isAssetHashType.SOURCE
, but ifassetHash
is explicitly specified this value defaults toAssetHashType.CUSTOM
.bundling (
Union
[BundlingOptions
,Dict
[str
,Any
],None
]) – Bundle the asset by executing a command in a Docker container or a custom bundling provider. The asset path will be mounted at/asset-input
. The Docker container is responsible for putting content at/asset-output
. The content at/asset-output
will be zipped and used as the final asset. Default: - uploaded as-is to S3 if the asset is a regular file or a .zip file, archived into a .zip file and uploaded to S3 otherwiseexclude (
Optional
[Sequence
[str
]]) – File paths matching the patterns will be excluded. SeeignoreMode
to set the matching behavior. Has no effect on Assets bundled using thebundling
property. Default: - nothing is excludedfollow (
Optional
[SymlinkFollowMode
]) – A strategy for how to handle symlinks. Default: SymlinkFollowMode.NEVERignore_mode (
Optional
[IgnoreMode
]) – The ignore behavior to use forexclude
patterns. Default: IgnoreMode.GLOB
Methods
- relative_staged_path(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 (
Stack
)- Return type:
str
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- BUNDLING_INPUT_DIR = '/asset-input'
- BUNDLING_OUTPUT_DIR = '/asset-output'
- absolute_staged_path
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()
, userelativeStagedPath()
instead.
- asset_hash
A cryptographic hash of the asset.
- is_archive
Whether this asset is an archive (zip or jar).
- node
The tree node.
- packaging
How this asset should be packaged.
- source_path
The absolute path of the asset as it was referenced by the user.
Static Methods
- classmethod clear_asset_hash_cache()
Clears the asset hash cache.
- Return type:
None
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
instances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructs
library on disk are seen as independent, completely different libraries. As a consequence, the classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
the other class.npm install
will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.