@aws-cdk_aws-synthetics-alpha.Code

class Code ๐Ÿ”น

LanguageType name
.NETAmazon.CDK.AWS.Synthetics.Alpha.Code
Gogithub.com/aws/aws-cdk-go/awscdksyntheticsalpha/v2#Code
Javasoftware.amazon.awscdk.services.synthetics.alpha.Code
Pythonaws_cdk.aws_synthetics_alpha.Code
TypeScript (source)@aws-cdk/aws-synthetics-alpha ยป Code

Implemented by AssetCode, InlineCode, S3Code

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_4_0,
  environmentVariables: {
    stage: 'prod',
  },
});

Initializer

new Code()

Methods

NameDescription
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 fromAsset(assetPath, options?)๐Ÿ”นSpecify code from a local path.
static fromBucket(bucket, key, objectVersion?)๐Ÿ”นSpecify code from an s3 bucket.
static fromInline(code)๐Ÿ”น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

  • CodeConfig

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

  • AssetCode

Specify code from a local path.

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

See also: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch


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

  • S3Code

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.

See also: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch


static fromInline(code)๐Ÿ”น

public static fromInline(code: string): InlineCode

Parameters

  • code string โ€” The actual handler code (limited to 5MB).

Returns

  • InlineCode

Specify code inline.