class Code
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.Synthetics.Code |
Java | software.amazon.awscdk.services.synthetics.Code |
Python | aws_cdk.aws_synthetics.Code |
TypeScript (source) | @aws-cdk/aws-synthetics » Code |
Implemented by
Asset, Inline, S3
The code the canary should execute.
Example
const canary = new synthetics.Canary(this, 'MyCanary', {
schedule: synthetics.Schedule.rate(Duration.minutes(5)),
test: synthetics.Test.custom({
code: synthetics.Code.fromAsset(path.join(__dirname, 'canary')),
handler: 'index.handler',
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_1,
environmentVariables: {
stage: 'prod',
},
});
Initializer
new Code()
Methods
| Name | Description |
|---|---|
| bind(scope, handler, family) | Called when the canary is initialized to allow this object to bind to the stack, add resources and have fun. |
| static from | Specify code from a local path. |
| static from | Specify code from an s3 bucket. |
| static from | Specify code inline. |
bind(scope, handler, family)
public bind(scope: Construct, handler: string, family: RuntimeFamily): CodeConfig
Parameters
- scope
Construct— The binding scope. - handler
string - family
RuntimeFamily
Returns
Called when the canary is initialized to allow this object to bind to the stack, add resources and have fun.
static fromAsset(assetPath, options?)
public static fromAsset(assetPath: string, options?: AssetOptions): AssetCode
Parameters
- assetPath
string— Either a directory or a .zip file. - options
AssetOptions
Returns
Specify code from a local path.
Path must include the folder structure nodejs/node_modules/myCanaryFilename.js.
static fromBucket(bucket, key, objectVersion?)
public static fromBucket(bucket: IBucket, key: string, objectVersion?: string): S3Code
Parameters
- bucket
IBucket— The S3 bucket. - key
string— The object key. - objectVersion
string— Optional S3 object version.
Returns
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.
static fromInline(code)
public static fromInline(code: string): InlineCode
Parameters
- code
string— The actual handler code (limited to 4KiB).
Returns
Specify code inline.

.NET
Java
Python
TypeScript (