awscdksyntheticsalpha

package module
v2.101.1-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 12 Imported by: 1

README

Amazon CloudWatch Synthetics Construct Library

---

Deprecated

This API may emit warnings. Backward compatibility is not guaranteed.


All constructs moved to aws-cdk-lib/aws-synthetics.

Amazon CloudWatch Synthetics allow you to monitor your application by generating synthetic traffic. The traffic is produced by a canary: a configurable script that runs on a schedule. You configure the canary script to follow the same routes and perform the same actions as a user, which allows you to continually verify your user experience even when you don't have any traffic on your applications.

Canary

To illustrate how to use a canary, assume your application defines the following endpoint:

% curl "https://api.example.com/user/books/topbook/"
The Hitchhikers Guide to the Galaxy

The below code defines a canary that will hit the books/topbook endpoint every 5 minutes:

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	EnvironmentVariables: map[string]*string{
		"stage": jsii.String("prod"),
	},
})

The following is an example of an index.js file which exports the handler function:

const synthetics = require('Synthetics');
const log = require('SyntheticsLogger');

const pageLoadBlueprint = async function () {
  // Configure the stage of the API using environment variables
  const url = `https://api.example.com/${process.env.stage}/user/books/topbook/`;

  const page = await synthetics.getPage();
  const response = await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
  // Wait for page to render. Increase or decrease wait time based on endpoint being monitored.
  await page.waitFor(15000);
  // This will take a screenshot that will be included in test output artifacts.
  await synthetics.takeScreenshot('loaded', 'loaded');
  const pageTitle = await page.title();
  log.info('Page title: ' + pageTitle);
  if (response.status() !== 200) {
    throw 'Failed to load page!';
  }
};

exports.handler = async () => {
  return await pageLoadBlueprint();
};

Note: The function must be called handler.

The canary will automatically produce a CloudWatch Dashboard:

UI Screenshot

The Canary code will be executed in a lambda function created by Synthetics on your behalf. The Lambda function includes a custom runtime provided by Synthetics. The provided runtime includes a variety of handy tools such as Puppeteer (for nodejs based one) and Chromium.

To learn more about Synthetics capabilities, check out the docs.

Canary Schedule

You can specify the schedule on which a canary runs by providing a Schedule object to the schedule property.

Configure a run rate of up to 60 minutes with Schedule.rate:

schedule := synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5)))

You can also specify a cron expression with Schedule.cron:

schedule := synthetics.Schedule_Cron(&CronOptions{
	Hour: jsii.String("0,8,16"),
})

If you want the canary to run just once upon deployment, you can use Schedule.once().

Deleting underlying resources on canary deletion

When you delete a lambda, the following underlying resources are isolated in your AWS account:

  • Lambda Function that runs your canary script
  • S3 Bucket for artifact storage
  • IAM roles and policies
  • Log Groups in CloudWatch Logs.

To learn more about these underlying resources, see Synthetics Canaries Deletion.

In the CDK, you can configure your canary to delete the underlying lambda function when the canary is deleted. This can be provisioned by setting cleanup: Cleanup.LAMBDA. Note that this will create a custom resource under the hood that takes care of the lambda deletion for you.

canary := synthetics.NewCanary(this, jsii.String("Canary"), &CanaryProps{
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Handler: jsii.String("index.handler"),
		Code: synthetics.Code_FromInline(jsii.String("/* Synthetics handler code")),
	}),
	Cleanup: synthetics.Cleanup_LAMBDA,
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
})

Note: To properly clean up your canary on deletion, you still have to manually delete other resources like S3 buckets and CloudWatch logs.

Configuring the Canary Script

To configure the script the canary executes, use the test property. The test property accepts a Test instance that can be initialized by the Test class static methods. Currently, the only implemented method is Test.custom(), which allows you to bring your own code. In the future, other methods will be added. Test.custom() accepts code and handler properties -- both are required by Synthetics to create a lambda function on your behalf.

The synthetics.Code class exposes static methods to bundle your code artifacts:

  • code.fromInline(code) - specify an inline script.
  • code.fromAsset(path) - specify a .zip file or a directory in the local filesystem which will be zipped and uploaded to S3 on deployment. See the above Note for directory structure.
  • code.fromBucket(bucket, key[, objectVersion]) - specify an S3 object that contains the .zip file of your runtime code. See the above Note for directory structure.

Using the Code class static initializers:

// To supply the code from a S3 bucket:
import s3 "github.com/aws/aws-cdk-go/awscdk"
// To supply the code inline:
// To supply the code inline:
synthetics.NewCanary(this, jsii.String("Inline Canary"), &CanaryProps{
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromInline(jsii.String("/* Synthetics handler code */")),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
})

// To supply the code from your local filesystem:
// To supply the code from your local filesystem:
synthetics.NewCanary(this, jsii.String("Asset Canary"), &CanaryProps{
	Test: synthetics.Test_*Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
})
bucket := s3.NewBucket(this, jsii.String("Code Bucket"))
synthetics.NewCanary(this, jsii.String("Bucket Canary"), &CanaryProps{
	Test: synthetics.Test_*Custom(&CustomTestOptions{
		Code: synthetics.Code_FromBucket(bucket, jsii.String("canary.zip")),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
})

Note: Synthetics have a specified folder structure for canaries. For Node scripts supplied via code.fromAsset() or code.fromBucket(), the canary resource requires the following folder structure:

canary/
├── nodejs/
   ├── node_modules/
        ├── <filename>.js

For Python scripts supplied via code.fromAsset() or code.fromBucket(), the canary resource requires the following folder structure:

canary/
├── python/
    ├── <filename>.py

See Synthetics docs.

Running a canary on a VPC

You can specify what VPC a canary executes in. This can allow for monitoring services that may be internal to a specific VPC. To place a canary within a VPC, you can specify the vpc property with the desired VPC to place then canary in. This will automatically attach the appropriate IAM permissions to attach to the VPC. This will also create a Security Group and attach to the default subnets for the VPC unless specified via vpcSubnets and securityGroups.

import ec2 "github.com/aws/aws-cdk-go/awscdk"

var vpc iVpc

synthetics.NewCanary(this, jsii.String("Vpc Canary"), &CanaryProps{
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	Vpc: Vpc,
})

Note: By default, the Synthetics runtime needs access to the S3 and CloudWatch APIs, which will fail in a private subnet without internet access enabled (e.g. an isolated subnnet).

Ensure that the Canary is placed in a VPC either with internet connectivity or with VPC Endpoints for S3 and CloudWatch enabled and configured.

See Synthetics VPC docs.

Alarms

You can configure a CloudWatch Alarm on a canary metric. Metrics are emitted by CloudWatch automatically and can be accessed by the following APIs:

  • canary.metricSuccessPercent() - percentage of successful canary runs over a given time
  • canary.metricDuration() - how much time each canary run takes, in seconds.
  • canary.metricFailed() - number of failed canary runs over a given time

Create an alarm that tracks the canary metric:

import "github.com/aws/aws-cdk-go/awscdk"

var canary canary

cloudwatch.NewAlarm(this, jsii.String("CanaryAlarm"), &AlarmProps{
	Metric: canary.MetricSuccessPercent(),
	EvaluationPeriods: jsii.Number(2),
	Threshold: jsii.Number(90),
	ComparisonOperator: cloudwatch.ComparisonOperator_LESS_THAN_THRESHOLD,
})
Artifacts

You can pass an S3 bucket to store artifacts from canary runs. If you do not, one will be auto-generated when the canary is created. You may add lifecycle rules to the auto-generated bucket.

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	ArtifactsBucketLifecycleRules: []lifecycleRule{
		&lifecycleRule{
			Expiration: awscdk.Duration_Days(jsii.Number(30)),
		},
	},
})

Documentation

Overview

This module is deprecated. All constructs are now available under aws-cdk-lib/aws-synthetics

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canary_IsConstruct

func Canary_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`. Deprecated.

func Canary_IsOwnedResource

func Canary_IsOwnedResource(construct constructs.IConstruct) *bool

Returns true if the construct was created by CDK, and false otherwise. Deprecated.

func Canary_IsResource

func Canary_IsResource(construct constructs.IConstruct) *bool

Check whether the given construct is a Resource. Deprecated.

func NewAssetCode_Override

func NewAssetCode_Override(a AssetCode, assetPath *string, options *awss3assets.AssetOptions)

Deprecated.

func NewCanary_Override

func NewCanary_Override(c Canary, scope constructs.Construct, id *string, props *CanaryProps)

Deprecated.

func NewCode_Override

func NewCode_Override(c Code)

Deprecated.

func NewInlineCode_Override

func NewInlineCode_Override(i InlineCode, code *string)

Deprecated.

func NewRuntime_Override

func NewRuntime_Override(r Runtime, name *string, family RuntimeFamily)

Deprecated.

func NewS3Code_Override

func NewS3Code_Override(s S3Code, bucket awss3.IBucket, key *string, objectVersion *string)

Deprecated.

Types

type ArtifactsBucketLocation

type ArtifactsBucketLocation struct {
	// The s3 location that stores the data of each run.
	// Deprecated.
	Bucket awss3.IBucket `field:"required" json:"bucket" yaml:"bucket"`
	// The S3 bucket prefix.
	//
	// Specify this if you want a more specific path within the artifacts bucket.
	// Default: - no prefix.
	//
	// Deprecated.
	Prefix *string `field:"optional" json:"prefix" yaml:"prefix"`
}

Options for specifying the s3 location that stores the data of each canary run.

The artifacts bucket location **cannot** be updated once the canary is created.

Example:

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

var bucket bucket

artifactsBucketLocation := &ArtifactsBucketLocation{
	Bucket: bucket,

	// the properties below are optional
	Prefix: jsii.String("prefix"),
}

Deprecated.

type AssetCode

type AssetCode interface {
	Code
	// Called when the canary is initialized to allow this object to bind to the stack, add resources and have fun.
	// Deprecated.
	Bind(scope constructs.Construct, handler *string, family RuntimeFamily) *CodeConfig
}

Canary code from an Asset.

Example:

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

var dockerImage dockerImage
var grantable iGrantable
var localBundling iLocalBundling

assetCode := synthetics_alpha.NewAssetCode(jsii.String("assetPath"), &AssetOptions{
	AssetHash: jsii.String("assetHash"),
	AssetHashType: cdk.AssetHashType_SOURCE,
	Bundling: &BundlingOptions{
		Image: dockerImage,

		// the properties below are optional
		BundlingFileAccess: cdk.BundlingFileAccess_VOLUME_COPY,
		Command: []*string{
			jsii.String("command"),
		},
		Entrypoint: []*string{
			jsii.String("entrypoint"),
		},
		Environment: map[string]*string{
			"environmentKey": jsii.String("environment"),
		},
		Local: localBundling,
		Network: jsii.String("network"),
		OutputType: cdk.BundlingOutput_ARCHIVED,
		Platform: jsii.String("platform"),
		SecurityOpt: jsii.String("securityOpt"),
		User: jsii.String("user"),
		Volumes: []dockerVolume{
			&dockerVolume{
				ContainerPath: jsii.String("containerPath"),
				HostPath: jsii.String("hostPath"),

				// the properties below are optional
				Consistency: cdk.DockerVolumeConsistency_CONSISTENT,
			},
		},
		VolumesFrom: []*string{
			jsii.String("volumesFrom"),
		},
		WorkingDirectory: jsii.String("workingDirectory"),
	},
	DeployTime: jsii.Boolean(false),
	Exclude: []*string{
		jsii.String("exclude"),
	},
	FollowSymlinks: cdk.SymlinkFollowMode_NEVER,
	IgnoreMode: cdk.IgnoreMode_GLOB,
	Readers: []*iGrantable{
		grantable,
	},
})

Deprecated.

func AssetCode_FromAsset

func AssetCode_FromAsset(assetPath *string, options *awss3assets.AssetOptions) AssetCode

Specify code from a local path.

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

Returns: `AssetCode` associated with the specified path. See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch

Deprecated.

func Code_FromAsset

func Code_FromAsset(assetPath *string, options *awss3assets.AssetOptions) AssetCode

Specify code from a local path.

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

Returns: `AssetCode` associated with the specified path. See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch

Deprecated.

func InlineCode_FromAsset

func InlineCode_FromAsset(assetPath *string, options *awss3assets.AssetOptions) AssetCode

Specify code from a local path.

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

Returns: `AssetCode` associated with the specified path. See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch

Deprecated.

func NewAssetCode

func NewAssetCode(assetPath *string, options *awss3assets.AssetOptions) AssetCode

Deprecated.

func S3Code_FromAsset

func S3Code_FromAsset(assetPath *string, options *awss3assets.AssetOptions) AssetCode

Specify code from a local path.

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

Returns: `AssetCode` associated with the specified path. See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch

Deprecated.

type Canary

type Canary interface {
	awscdk.Resource
	awsec2.IConnectable
	// Bucket where data from each canary run is stored.
	// Deprecated.
	ArtifactsBucket() awss3.IBucket
	// The canary ID.
	// Deprecated.
	CanaryId() *string
	// The canary Name.
	// Deprecated.
	CanaryName() *string
	// The state of the canary.
	//
	// For example, 'RUNNING', 'STOPPED', 'NOT STARTED', or 'ERROR'.
	// Deprecated.
	CanaryState() *string
	// Access the Connections object.
	//
	// Will fail if not a VPC-enabled Canary.
	// Deprecated.
	Connections() awsec2.Connections
	// The environment this resource belongs to.
	//
	// For resources that are created and managed by the CDK
	// (generally, those created by creating new class instances like Role, Bucket, etc.),
	// this is always the same as the environment of the stack they belong to;
	// however, for imported resources
	// (those obtained from static methods like fromRoleArn, fromBucketName, etc.),
	// that might be different than the stack they were imported into.
	// Deprecated.
	Env() *awscdk.ResourceEnvironment
	// The tree node.
	// Deprecated.
	Node() constructs.Node
	// Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.
	//
	// This value will resolve to one of the following:
	// - a concrete value (e.g. `"my-awesome-bucket"`)
	// - `undefined`, when a name should be generated by CloudFormation
	// - a concrete name generated automatically during synthesis, in
	//   cross-environment scenarios.
	// Deprecated.
	PhysicalName() *string
	// Execution role associated with this Canary.
	// Deprecated.
	Role() awsiam.IRole
	// The stack in which this resource is defined.
	// Deprecated.
	Stack() awscdk.Stack
	// Apply the given removal policy to this resource.
	//
	// The Removal Policy controls what happens to this resource when it stops
	// being managed by CloudFormation, either because you've removed it from the
	// CDK application or because you've made a change that requires the resource
	// to be replaced.
	//
	// The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
	// account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).
	// Deprecated.
	ApplyRemovalPolicy(policy awscdk.RemovalPolicy)
	// Deprecated.
	GeneratePhysicalName() *string
	// Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. `bucket.bucketArn`).
	//
	// Normally, this token will resolve to `arnAttr`, but if the resource is
	// referenced across environments, `arnComponents` will be used to synthesize
	// a concrete ARN with the resource's physical name. Make sure to reference
	// `this.physicalName` in `arnComponents`.
	// Deprecated.
	GetResourceArnAttribute(arnAttr *string, arnComponents *awscdk.ArnComponents) *string
	// Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. `bucket.bucketName`).
	//
	// Normally, this token will resolve to `nameAttr`, but if the resource is
	// referenced across environments, it will be resolved to `this.physicalName`,
	// which will be a concrete name.
	// Deprecated.
	GetResourceNameAttribute(nameAttr *string) *string
	// Measure the Duration of a single canary run, in seconds.
	// Default: avg over 5 minutes.
	//
	// Deprecated.
	MetricDuration(options *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Measure the number of failed canary runs over a given time period.
	//
	// Default: sum over 5 minutes.
	// Deprecated.
	MetricFailed(options *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Measure the percentage of successful canary runs.
	// Default: avg over 5 minutes.
	//
	// Deprecated.
	MetricSuccessPercent(options *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Returns a string representation of this construct.
	// Deprecated.
	ToString() *string
}

Define a new Canary.

Example:

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	EnvironmentVariables: map[string]*string{
		"stage": jsii.String("prod"),
	},
})

Deprecated.

func NewCanary

func NewCanary(scope constructs.Construct, id *string, props *CanaryProps) Canary

Deprecated.

type CanaryProps

type CanaryProps struct {
	// Specify the runtime version to use for the canary.
	// See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_Library.html
	//
	// Deprecated.
	Runtime Runtime `field:"required" json:"runtime" yaml:"runtime"`
	// The type of test that you want your canary to run.
	//
	// Use `Test.custom()` to specify the test to run.
	// Deprecated.
	Test Test `field:"required" json:"test" yaml:"test"`
	// Lifecycle rules for the generated canary artifact bucket.
	//
	// Has no effect
	// if a bucket is passed to `artifactsBucketLocation`. If you pass a bucket
	// to `artifactsBucketLocation`, you can add lifecycle rules to the bucket
	// itself.
	// Default: - no rules applied to the generated bucket.
	//
	// Deprecated.
	ArtifactsBucketLifecycleRules *[]*awss3.LifecycleRule `field:"optional" json:"artifactsBucketLifecycleRules" yaml:"artifactsBucketLifecycleRules"`
	// The s3 location that stores the data of the canary runs.
	// Default: - A new s3 bucket will be created without a prefix.
	//
	// Deprecated.
	ArtifactsBucketLocation *ArtifactsBucketLocation `field:"optional" json:"artifactsBucketLocation" yaml:"artifactsBucketLocation"`
	// The name of the canary.
	//
	// Be sure to give it a descriptive name that distinguishes it from
	// other canaries in your account.
	//
	// Do not include secrets or proprietary information in your canary name. The canary name
	// makes up part of the canary ARN, which is included in outbound calls over the internet.
	// See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/servicelens_canaries_security.html
	//
	// Default: - A unique name will be generated from the construct ID.
	//
	// Deprecated.
	CanaryName *string `field:"optional" json:"canaryName" yaml:"canaryName"`
	// Specify the underlying resources to be cleaned up when the canary is deleted.
	//
	// Using `Cleanup.LAMBDA` will create a Custom Resource to achieve this.
	// Default: Cleanup.NOTHING
	//
	// Deprecated.
	Cleanup Cleanup `field:"optional" json:"cleanup" yaml:"cleanup"`
	// Whether or not to delete the lambda resources when the canary is deleted.
	// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-synthetics-canary.html#cfn-synthetics-canary-deletelambdaresourcesoncanarydeletion
	//
	// Default: false.
	//
	// Deprecated: this feature has been deprecated by the service team, use `cleanup: Cleanup.LAMBDA` instead which will use a Custom Resource to achieve the same effect.
	EnableAutoDeleteLambdas *bool `field:"optional" json:"enableAutoDeleteLambdas" yaml:"enableAutoDeleteLambdas"`
	// Key-value pairs that the Synthetics caches and makes available for your canary scripts.
	//
	// Use environment variables
	// to apply configuration changes, such as test and production environment configurations, without changing your
	// Canary script source code.
	// Default: - No environment variables.
	//
	// Deprecated.
	EnvironmentVariables *map[string]*string `field:"optional" json:"environmentVariables" yaml:"environmentVariables"`
	// How many days should failed runs be retained.
	// Default: Duration.days(31)
	//
	// Deprecated.
	FailureRetentionPeriod awscdk.Duration `field:"optional" json:"failureRetentionPeriod" yaml:"failureRetentionPeriod"`
	// Canary execution role.
	//
	// This is the role that will be assumed by the canary upon execution.
	// It controls the permissions that the canary will have. The role must
	// be assumable by the AWS Lambda service principal.
	//
	// If not supplied, a role will be created with all the required permissions.
	// If you provide a Role, you must add the required permissions.
	// See: required permissions: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-synthetics-canary.html#cfn-synthetics-canary-executionrolearn
	//
	// Default: - A unique role will be generated for this canary.
	// You can add permissions to roles by calling 'addToRolePolicy'.
	//
	// Deprecated.
	Role awsiam.IRole `field:"optional" json:"role" yaml:"role"`
	// Specify the schedule for how often the canary runs.
	//
	// For example, if you set `schedule` to `rate(10 minutes)`, then the canary will run every 10 minutes.
	// You can set the schedule with `Schedule.rate(Duration)` (recommended) or you can specify an expression using `Schedule.expression()`.
	// Default: 'rate(5 minutes)'.
	//
	// Deprecated.
	Schedule Schedule `field:"optional" json:"schedule" yaml:"schedule"`
	// The list of security groups to associate with the canary's network interfaces.
	//
	// You must provide `vpc` when using this prop.
	// Default: - If the canary is placed within a VPC and a security group is
	// not specified a dedicated security group will be created for this canary.
	//
	// Deprecated.
	SecurityGroups *[]awsec2.ISecurityGroup `field:"optional" json:"securityGroups" yaml:"securityGroups"`
	// Whether or not the canary should start after creation.
	// Default: true.
	//
	// Deprecated.
	StartAfterCreation *bool `field:"optional" json:"startAfterCreation" yaml:"startAfterCreation"`
	// How many days should successful runs be retained.
	// Default: Duration.days(31)
	//
	// Deprecated.
	SuccessRetentionPeriod awscdk.Duration `field:"optional" json:"successRetentionPeriod" yaml:"successRetentionPeriod"`
	// How long the canary will be in a 'RUNNING' state.
	//
	// For example, if you set `timeToLive` to be 1 hour and `schedule` to be `rate(10 minutes)`,
	// your canary will run at 10 minute intervals for an hour, for a total of 6 times.
	// Default: - no limit.
	//
	// Deprecated.
	TimeToLive awscdk.Duration `field:"optional" json:"timeToLive" yaml:"timeToLive"`
	// The VPC where this canary is run.
	//
	// Specify this if the canary needs to access resources in a VPC.
	// Default: - Not in VPC.
	//
	// Deprecated.
	Vpc awsec2.IVpc `field:"optional" json:"vpc" yaml:"vpc"`
	// Where to place the network interfaces within the VPC.
	//
	// You must provide `vpc` when using this prop.
	// Default: - the Vpc default strategy if not specified.
	//
	// Deprecated.
	VpcSubnets *awsec2.SubnetSelection `field:"optional" json:"vpcSubnets" yaml:"vpcSubnets"`
}

Properties for a canary.

Example:

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	EnvironmentVariables: map[string]*string{
		"stage": jsii.String("prod"),
	},
})

Deprecated.

type Cleanup

type Cleanup string

Different ways to clean up underlying Canary resources when the Canary is deleted.

Example:

canary := synthetics.NewCanary(this, jsii.String("Canary"), &CanaryProps{
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Handler: jsii.String("index.handler"),
		Code: synthetics.Code_FromInline(jsii.String("/* Synthetics handler code")),
	}),
	Cleanup: synthetics.Cleanup_LAMBDA,
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
})

Deprecated.

const (
	// Clean up nothing.
	//
	// The user is responsible for cleaning up
	// all resources left behind by the Canary.
	// Deprecated.
	Cleanup_NOTHING Cleanup = "NOTHING"
	// Clean up the underlying Lambda function only.
	//
	// The user is
	// responsible for cleaning up all other resources left behind
	// by the Canary.
	// Deprecated.
	Cleanup_LAMBDA Cleanup = "LAMBDA"
)

type Code

type Code interface {
	// Called when the canary is initialized to allow this object to bind to the stack, add resources and have fun.
	//
	// Returns: a bound `CodeConfig`.
	// Deprecated.
	Bind(scope constructs.Construct, handler *string, family RuntimeFamily) *CodeConfig
}

The code the canary should execute.

Example:

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	EnvironmentVariables: map[string]*string{
		"stage": jsii.String("prod"),
	},
})

Deprecated.

type CodeConfig

type CodeConfig struct {
	// Inline code (mutually exclusive with `s3Location`).
	// Default: - none.
	//
	// Deprecated.
	InlineCode *string `field:"optional" json:"inlineCode" yaml:"inlineCode"`
	// The location of the code in S3 (mutually exclusive with `inlineCode`).
	// Default: - none.
	//
	// Deprecated.
	S3Location *awss3.Location `field:"optional" json:"s3Location" yaml:"s3Location"`
}

Configuration of the code class.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import synthetics_alpha "github.com/aws/aws-cdk-go/awscdksyntheticsalpha"

codeConfig := &CodeConfig{
	InlineCode: jsii.String("inlineCode"),
	S3Location: &Location{
		BucketName: jsii.String("bucketName"),
		ObjectKey: jsii.String("objectKey"),

		// the properties below are optional
		ObjectVersion: jsii.String("objectVersion"),
	},
}

Deprecated.

type CronOptions

type CronOptions struct {
	// The day of the month to run this rule at.
	// Default: - Every day of the month.
	//
	// Deprecated.
	Day *string `field:"optional" json:"day" yaml:"day"`
	// The hour to run this rule at.
	// Default: - Every hour.
	//
	// Deprecated.
	Hour *string `field:"optional" json:"hour" yaml:"hour"`
	// The minute to run this rule at.
	// Default: - Every minute.
	//
	// Deprecated.
	Minute *string `field:"optional" json:"minute" yaml:"minute"`
	// The month to run this rule at.
	// Default: - Every month.
	//
	// Deprecated.
	Month *string `field:"optional" json:"month" yaml:"month"`
	// The day of the week to run this rule at.
	// Default: - Any day of the week.
	//
	// Deprecated.
	WeekDay *string `field:"optional" json:"weekDay" yaml:"weekDay"`
}

Options to configure a cron expression.

All fields are strings so you can use complex expressions. Absence of a field implies '*' or '?', whichever one is appropriate.

Example:

schedule := synthetics.Schedule_Cron(&CronOptions{
	Hour: jsii.String("0,8,16"),
})

See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_cron.html

Deprecated.

type CustomTestOptions

type CustomTestOptions struct {
	// The code of the canary script.
	// Deprecated.
	Code Code `field:"required" json:"code" yaml:"code"`
	// The handler for the code.
	//
	// Must end with `.handler`.
	// Deprecated.
	Handler *string `field:"required" json:"handler" yaml:"handler"`
}

Properties for specifying a test.

Example:

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	EnvironmentVariables: map[string]*string{
		"stage": jsii.String("prod"),
	},
})

Deprecated.

type InlineCode

type InlineCode interface {
	Code
	// Called when the canary is initialized to allow this object to bind to the stack, add resources and have fun.
	// Deprecated.
	Bind(_scope constructs.Construct, handler *string, _family RuntimeFamily) *CodeConfig
}

Canary code from an inline string.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import synthetics_alpha "github.com/aws/aws-cdk-go/awscdksyntheticsalpha"

inlineCode := synthetics_alpha.NewInlineCode(jsii.String("code"))

Deprecated.

func AssetCode_FromInline

func AssetCode_FromInline(code *string) InlineCode

Specify code inline.

Returns: `InlineCode` with inline code. Deprecated.

func Code_FromInline

func Code_FromInline(code *string) InlineCode

Specify code inline.

Returns: `InlineCode` with inline code. Deprecated.

func InlineCode_FromInline

func InlineCode_FromInline(code *string) InlineCode

Specify code inline.

Returns: `InlineCode` with inline code. Deprecated.

func NewInlineCode

func NewInlineCode(code *string) InlineCode

Deprecated.

func S3Code_FromInline

func S3Code_FromInline(code *string) InlineCode

Specify code inline.

Returns: `InlineCode` with inline code. Deprecated.

type Runtime

type Runtime interface {
	// The Lambda runtime family.
	// Deprecated.
	Family() RuntimeFamily
	// The name of the runtime version.
	// Deprecated.
	Name() *string
}

Runtime options for a canary.

Example:

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	EnvironmentVariables: map[string]*string{
		"stage": jsii.String("prod"),
	},
})

Deprecated.

func NewRuntime

func NewRuntime(name *string, family RuntimeFamily) Runtime

Deprecated.

func Runtime_SYNTHETICS_1_0

func Runtime_SYNTHETICS_1_0() Runtime

func Runtime_SYNTHETICS_NODEJS_2_0

func Runtime_SYNTHETICS_NODEJS_2_0() Runtime

func Runtime_SYNTHETICS_NODEJS_2_1

func Runtime_SYNTHETICS_NODEJS_2_1() Runtime

func Runtime_SYNTHETICS_NODEJS_2_2

func Runtime_SYNTHETICS_NODEJS_2_2() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_0

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_0() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_1

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_1() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_2

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_2() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_3

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_3() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_4

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_4() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_5

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_5() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_6

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_6() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_7

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_7() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_8

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_8() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_9

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_3_9() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_5_0

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_5_0() Runtime

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_5_1

func Runtime_SYNTHETICS_NODEJS_PUPPETEER_5_1() Runtime

func Runtime_SYNTHETICS_PYTHON_SELENIUM_1_0

func Runtime_SYNTHETICS_PYTHON_SELENIUM_1_0() Runtime

func Runtime_SYNTHETICS_PYTHON_SELENIUM_1_1

func Runtime_SYNTHETICS_PYTHON_SELENIUM_1_1() Runtime

func Runtime_SYNTHETICS_PYTHON_SELENIUM_1_2

func Runtime_SYNTHETICS_PYTHON_SELENIUM_1_2() Runtime

func Runtime_SYNTHETICS_PYTHON_SELENIUM_1_3

func Runtime_SYNTHETICS_PYTHON_SELENIUM_1_3() Runtime

type RuntimeFamily

type RuntimeFamily string

All known Lambda runtime families. Deprecated.

const (
	// All Lambda runtimes that depend on Node.js.
	// Deprecated.
	RuntimeFamily_NODEJS RuntimeFamily = "NODEJS"
	// All lambda runtimes that depend on Python.
	// Deprecated.
	RuntimeFamily_PYTHON RuntimeFamily = "PYTHON"
	// Any future runtime family.
	// Deprecated.
	RuntimeFamily_OTHER RuntimeFamily = "OTHER"
)

type S3Code

type S3Code interface {
	Code
	// Called when the canary is initialized to allow this object to bind to the stack, add resources and have fun.
	// Deprecated.
	Bind(_scope constructs.Construct, _handler *string, _family RuntimeFamily) *CodeConfig
}

S3 bucket path to the code zip file.

Example:

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

var bucket bucket

s3Code := synthetics_alpha.NewS3Code(bucket, jsii.String("key"), jsii.String("objectVersion"))

Deprecated.

func AssetCode_FromBucket

func AssetCode_FromBucket(bucket awss3.IBucket, key *string, objectVersion *string) 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`.

Returns: `S3Code` associated with the specified S3 object. See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch

Deprecated.

func Code_FromBucket

func Code_FromBucket(bucket awss3.IBucket, key *string, objectVersion *string) 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`.

Returns: `S3Code` associated with the specified S3 object. See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch

Deprecated.

func InlineCode_FromBucket

func InlineCode_FromBucket(bucket awss3.IBucket, key *string, objectVersion *string) 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`.

Returns: `S3Code` associated with the specified S3 object. See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch

Deprecated.

func NewS3Code

func NewS3Code(bucket awss3.IBucket, key *string, objectVersion *string) S3Code

Deprecated.

func S3Code_FromBucket

func S3Code_FromBucket(bucket awss3.IBucket, key *string, objectVersion *string) 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`.

Returns: `S3Code` associated with the specified S3 object. See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch

Deprecated.

type Schedule

type Schedule interface {
	// The Schedule expression.
	// Deprecated.
	ExpressionString() *string
}

Schedule for canary runs.

Example:

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	EnvironmentVariables: map[string]*string{
		"stage": jsii.String("prod"),
	},
})

Deprecated.

func Schedule_Cron

func Schedule_Cron(options *CronOptions) Schedule

Create a schedule from a set of cron fields. Deprecated.

func Schedule_Expression

func Schedule_Expression(expression *string) Schedule

Construct a schedule from a literal schedule expression.

The expression must be in a `rate(number units)` format. For example, `Schedule.expression('rate(10 minutes)')` Deprecated.

func Schedule_Once

func Schedule_Once() Schedule

The canary will be executed once. Deprecated.

func Schedule_Rate

func Schedule_Rate(interval awscdk.Duration) Schedule

Construct a schedule from an interval.

Allowed values: 0 (for a single run) or between 1 and 60 minutes. To specify a single run, you can use `Schedule.once()`. Deprecated.

type Test

type Test interface {
	// The code that the canary should run.
	// Deprecated.
	Code() Code
	// The handler of the canary.
	// Deprecated.
	Handler() *string
}

Specify a test that the canary should run.

Example:

canary := synthetics.NewCanary(this, jsii.String("MyCanary"), &CanaryProps{
	Schedule: synthetics.Schedule_Rate(awscdk.Duration_Minutes(jsii.Number(5))),
	Test: synthetics.Test_Custom(&CustomTestOptions{
		Code: synthetics.Code_FromAsset(path.join(__dirname, jsii.String("canary"))),
		Handler: jsii.String("index.handler"),
	}),
	Runtime: synthetics.Runtime_SYNTHETICS_NODEJS_PUPPETEER_4_0(),
	EnvironmentVariables: map[string]*string{
		"stage": jsii.String("prod"),
	},
})

Deprecated.

func Test_Custom

func Test_Custom(options *CustomTestOptions) Test

Specify a custom test with your own code.

Returns: `Test` associated with the specified Code object. Deprecated.

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL