Skip to content

AssetStaging

Stages a file or directory from a location on the file system into a staging directory.

This is controlled by the context key 'aliyun:ros:disable-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.

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.

Initializers

import ros_cdk_core
ros_cdk_core.AssetStaging(
  scope: Construct,
  id: str,
  exclude: typing.List[str] = None,
  follow: SymlinkFollowMode = None,
  ignore_mode: IgnoreMode = None,
  extra_hash: str = None,
  asset_hash: str = None,
  asset_hash_type: AssetHashType = None,
  bundling: BundlingOptions = None,
  source_path: str
)
Name Type Description
scope Construct No description.
id str No description.
exclude typing.List[str] File paths matching the patterns will be excluded.
follow SymlinkFollowMode A strategy for how to handle symlinks.
ignore_mode IgnoreMode The ignore behavior to use for exclude patterns.
extra_hash str Extra information to encode into the fingerprint (e.g. build instructions and other inputs).
asset_hash str Specify a custom hash for this asset.
asset_hash_type AssetHashType Specifies the type of hash to calculate for this asset.
bundling BundlingOptions Bundle the asset by executing a command in a Docker container or a custom bundling provider.
source_path str The source file or directory to copy from.

scopeRequired


idRequired

  • Type: str

excludeOptional

  • Type: typing.List[str]
  • Default: nothing is excluded

File paths matching the patterns will be excluded.

See ignoreMode to set the matching behavior. Has no effect on Assets bundled using the bundling property.


followOptional

A strategy for how to handle symlinks.


ignore_modeOptional

The ignore behavior to use for exclude patterns.


extra_hashOptional

  • Type: str
  • Default: hash is only based on source content

Extra information to encode into the fingerprint (e.g. build instructions and other inputs).


asset_hashOptional

  • Type: str
  • Default: based on assetHashType

Specify a custom hash for this asset.

If assetHashType is set it must be set to AssetHashType.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 OSS bucket, 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.


asset_hash_typeOptional

  • Type: AssetHashType
  • Default: the default is AssetHashType.SOURCE, but if assetHash is explicitly specified this value defaults to AssetHashType.CUSTOM.

Specifies the type of hash to calculate for this asset.

If assetHash is configured, this option must be undefined or AssetHashType.CUSTOM.


bundlingOptional

  • Type: BundlingOptions
  • Default: uploaded as-is to OSS bucket if the asset is a regular file or a .zip file, archived into a .zip file and uploaded to OSS bucket otherwise.

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.


source_pathRequired

  • Type: str

The source file or directory to copy from.


Methods

Name Description
to_string Returns a string representation of this construct.
synthesize Allows this construct to emit artifacts into the cloud assembly during synthesis.
relative_staged_path Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack.

to_string

def to_string() -> str

Returns a string representation of this construct.

synthesize

def synthesize(
  session: ISynthesisSession
) -> None

Allows this construct to emit artifacts into the cloud assembly during synthesis.

This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

sessionRequired

The synthesis session.


relative_staged_path

def relative_staged_path(
  stack: Stack
) -> str

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" }

stackRequired


Static Functions

Name Description
is_construct Return whether the given object is a Construct.
clear_asset_hash_cache Clears the asset hash cache.

is_construct

import ros_cdk_core
ros_cdk_core.AssetStaging.is_construct(
  x: typing.Any
)

Return whether the given object is a Construct.

xRequired

  • Type: typing.Any

clear_asset_hash_cache

import ros_cdk_core
ros_cdk_core.AssetStaging.clear_asset_hash_cache()

Clears the asset hash cache.

Properties

Name Type Description
node ConstructNode The construct tree node associated with this construct.
absolute_staged_path str Absolute path to the asset data.
asset_hash str A cryptographic hash of the asset.
is_archive bool Whether this asset is an archive (zip or jar).
packaging FileAssetPackaging How this asset should be packaged.
source_path str The absolute path of the asset as it was referenced by the user.

nodeRequired

node: ConstructNode

The construct tree node associated with this construct.


absolute_staged_pathRequired

absolute_staged_path: str
  • Type: str

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.


asset_hashRequired

asset_hash: str
  • Type: str

A cryptographic hash of the asset.


is_archiveRequired

is_archive: bool
  • Type: bool

Whether this asset is an archive (zip or jar).


packagingRequired

packaging: FileAssetPackaging

How this asset should be packaged.


source_pathRequired

source_path: str
  • Type: str

The absolute path of the asset as it was referenced by the user.


Constants

Name Type Description
BUNDLING_INPUT_DIR str The directory inside the bundling container into which the asset sources will be mounted.
BUNDLING_OUTPUT_DIR str The directory inside the bundling container into which the bundled output should be written.

BUNDLING_INPUT_DIRRequired

BUNDLING_INPUT_DIR: str
  • Type: str

The directory inside the bundling container into which the asset sources will be mounted.


BUNDLING_OUTPUT_DIRRequired

BUNDLING_OUTPUT_DIR: str
  • Type: str

The directory inside the bundling container into which the bundled output should be written.