# S3Code

S3 bucket path to the code zip file.

Extends: [Code](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_synthetics.Code.html) › S3Code
Obtainable from: [Code.fromBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_synthetics.Code.html#frombucket)

- Source: [`aws-synthetics/lib/code.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-synthetics/lib/code.ts#L223)
- Type last changed: v2.224.0 · 13 Nov 2025

## Example

TypeScript:

```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');
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_synthetics as synthetics
from aws_cdk.interfaces import aws_s3 as interfaces_s3

# bucket_ref: interfaces_s3.IBucketRef

s3_code = synthetics.S3Code(bucket_ref, "key", "objectVersion")
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.synthetics.*;
import software.amazon.awscdk.interfaces.s3.*;

IBucketRef bucketRef;

S3Code s3Code = new S3Code(bucketRef, "key", "objectVersion");
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.Synthetics;
using Amazon.CDK.Interfaces.S3;

IBucketRef bucketRef;

var s3Code = new S3Code(bucketRef, "key", "objectVersion");
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var bucketRef IBucketRef

s3Code := awscdk.Aws_synthetics.NewS3Code(bucketRef, jsii.String("key"), jsii.String("objectVersion"))
```

## Initializer

TypeScript:

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

Python:

```python
S3Code(bucket: IBucketRef, key: str, object_version: typing.Optional[str] = None)
```

Java:

```java
new S3Code(IBucketRef bucket, String key, String objectVersion)
```

C# / .NET:

```csharp
new S3Code(IBucketRef bucket, string key, string? objectVersion = null)
```

Golang:

```go
NewS3Code(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.
