class Code
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Synthetics.Code |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awssynthetics#Code |
Java | software.amazon.awscdk.services.synthetics.Code |
Python | aws_cdk.aws_synthetics.Code |
TypeScript (source) | aws-cdk-lib » aws_synthetics » Code |
Implemented by
Asset
, Inline
, S3
The code the canary should execute.
Example
import * as cdk from "aws-cdk-lib";
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_6_2,
memory: cdk.Size.mebibytes(1024), // 1024 MiB
});
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
Runtime
Family
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
Asset
Options
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 5MB).
Returns
Specify code inline.