# AssetCode

Canary code from an Asset.

Extends: Code › AssetCode

- Source: [`aws-synthetics/lib/code.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-synthetics/lib/code.ts#L87)
- Type last changed: v2.177.0 · 25 Jan 2025

## Example

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
import { aws_synthetics as synthetics } from 'aws-cdk-lib';
import { aws_kms as interfaces_kms } from 'aws-cdk-lib/interfaces';

declare const dockerImage: cdk.DockerImage;
declare const grantable: iam.IGrantable;
declare const keyRef: interfaces_kms.IKeyRef;
declare const localBundling: cdk.ILocalBundling;
const assetCode = new synthetics.AssetCode('assetPath', /* all optional props */ {
  assetHash: 'assetHash',
  assetHashType: cdk.AssetHashType.SOURCE,
  bundling: {
    image: dockerImage,

    // the properties below are optional
    bundlingFileAccess: cdk.BundlingFileAccess.VOLUME_COPY,
    command: ['command'],
    entrypoint: ['entrypoint'],
    environment: {
      environmentKey: 'environment',
    },
    local: localBundling,
    network: 'network',
    outputType: cdk.BundlingOutput.ARCHIVED,
    platform: 'platform',
    securityOpt: 'securityOpt',
    user: 'user',
    volumes: [{
      containerPath: 'containerPath',
      hostPath: 'hostPath',

      // the properties below are optional
      consistency: cdk.DockerVolumeConsistency.CONSISTENT,
    }],
    volumesFrom: ['volumesFrom'],
    workingDirectory: 'workingDirectory',
  },
  deployTime: false,
  displayName: 'displayName',
  exclude: ['exclude'],
  followSymlinks: cdk.SymlinkFollowMode.NEVER,
  ignoreMode: cdk.IgnoreMode.GLOB,
  readers: [grantable],
  sourceKMSKey: keyRef,
});
```

## Initializer

```ts
new AssetCode(assetPath: string, options?: AssetOptions)
```

## Methods

- `bind(scope: Construct, handler: string, family: RuntimeFamily, runtimeName?: string): CodeConfig` — Called when the canary is initialized to allow this object to bind to the stack, add resources and have fun.

- `fromAsset(assetPath: string, options?: AssetOptions): AssetCode // chainable` (static) — Specify code from a local path.

  Path must include the folder structure `nodejs/node_modules/myCanaryFilename.js`.

  **Parameters**

  - `assetPath` — Either a directory or a .zip file.

  **Returns:** `AssetCode` associated with the specified path.

- `fromBucket(bucket: IBucketRef, key: string, objectVersion?: string): S3Code` (static) — Specify code from an s3 bucket.

  The object in the s3 bucket must be a .zip file that contains
  the structure `nodejs/node_modules/myCanaryFilename.js`.

  **Parameters**

  - `bucket` — The S3 bucket.
  - `key` — The object key.
  - `objectVersion` — Optional S3 object version.

  **Returns:** `S3Code` associated with the specified S3 object.

- `fromInline(code: string): InlineCode` (static) — Specify code inline.

  **Parameters**

  - `code` — The actual handler code (limited to 5MB).

  **Returns:** `InlineCode` with inline code.
