# S3Code

S3 bucket path to the code zip file.

Extends: Code › S3Code

- 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#L223)
- Type last changed: v2.224.0 · 13 Nov 2025

## Example

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

declare const bucketRef: interfaces_s3.IBucketRef;
const s3Code = new synthetics.S3Code(bucketRef, 'key', /* all optional props */ 'objectVersion');
```

## Initializer

```ts
new S3Code(bucket: IBucketRef, key: string, objectVersion?: string)
```

## 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` (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 // chainable` (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.
