Skip to content
v2.277.0

AssetCode Class ​

Canary code from an Asset.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
import { aws_synthetics as synthetics } from 'aws-cdk-lib';
import { aws_kms as interfaces_kms } from 'aws-cdk-lib/interfaces';

declare const dockerImage: cdk.DockerImage;
declare const grantable: iam.IGrantable;
declare const keyRef: interfaces_kms.IKeyRef;
declare const localBundling: cdk.ILocalBundling;
const assetCode = new synthetics.AssetCode('assetPath', /* all optional props */ {
  assetHash: 'assetHash',
  assetHashType: cdk.AssetHashType.SOURCE,
  bundling: {
    image: dockerImage,

    // the properties below are optional
    bundlingFileAccess: cdk.BundlingFileAccess.VOLUME_COPY,
    command: ['command'],
    entrypoint: ['entrypoint'],
    environment: {
      environmentKey: 'environment',
    },
    local: localBundling,
    network: 'network',
    outputType: cdk.BundlingOutput.ARCHIVED,
    platform: 'platform',
    securityOpt: 'securityOpt',
    user: 'user',
    volumes: [{
      containerPath: 'containerPath',
      hostPath: 'hostPath',

      // the properties below are optional
      consistency: cdk.DockerVolumeConsistency.CONSISTENT,
    }],
    volumesFrom: ['volumesFrom'],
    workingDirectory: 'workingDirectory',
  },
  deployTime: false,
  displayName: 'displayName',
  exclude: ['exclude'],
  followSymlinks: cdk.SymlinkFollowMode.NEVER,
  ignoreMode: cdk.IgnoreMode.GLOB,
  readers: [grantable],
  sourceKMSKey: keyRef,
});
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_iam as iam
from aws_cdk import aws_synthetics as synthetics
from aws_cdk.interfaces import aws_kms as interfaces_kms

# docker_image: cdk.DockerImage
# grantable: iam.IGrantable
# key_ref: interfaces_kms.IKeyRef
# local_bundling: cdk.ILocalBundling

asset_code = synthetics.AssetCode("assetPath",
    asset_hash="assetHash",
    asset_hash_type=cdk.AssetHashType.SOURCE,
    bundling=cdk.BundlingOptions(
        image=docker_image,

        # the properties below are optional
        bundling_file_access=cdk.BundlingFileAccess.VOLUME_COPY,
        command=["command"],
        entrypoint=["entrypoint"],
        environment={
            "environment_key": "environment"
        },
        local=local_bundling,
        network="network",
        output_type=cdk.BundlingOutput.ARCHIVED,
        platform="platform",
        security_opt="securityOpt",
        user="user",
        volumes=[cdk.DockerVolume(
            container_path="containerPath",
            host_path="hostPath",

            # the properties below are optional
            consistency=cdk.DockerVolumeConsistency.CONSISTENT
        )],
        volumes_from=["volumesFrom"],
        working_directory="workingDirectory"
    ),
    deploy_time=False,
    display_name="displayName",
    exclude=["exclude"],
    follow_symlinks=cdk.SymlinkFollowMode.NEVER,
    ignore_mode=cdk.IgnoreMode.GLOB,
    readers=[grantable],
    source_kms_key=key_ref
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.iam.*;
import software.amazon.awscdk.services.synthetics.*;
import software.amazon.awscdk.interfaces.kms.*;

DockerImage dockerImage;
IGrantable grantable;
IKeyRef keyRef;
ILocalBundling localBundling;

AssetCode assetCode = AssetCode.Builder.create("assetPath")
        .assetHash("assetHash")
        .assetHashType(AssetHashType.SOURCE)
        .bundling(BundlingOptions.builder()
                .image(dockerImage)

                // the properties below are optional
                .bundlingFileAccess(BundlingFileAccess.VOLUME_COPY)
                .command(List.of("command"))
                .entrypoint(List.of("entrypoint"))
                .environment(Map.of(
                        "environmentKey", "environment"))
                .local(localBundling)
                .network("network")
                .outputType(BundlingOutput.ARCHIVED)
                .platform("platform")
                .securityOpt("securityOpt")
                .user("user")
                .volumes(List.of(DockerVolume.builder()
                        .containerPath("containerPath")
                        .hostPath("hostPath")

                        // the properties below are optional
                        .consistency(DockerVolumeConsistency.CONSISTENT)
                        .build()))
                .volumesFrom(List.of("volumesFrom"))
                .workingDirectory("workingDirectory")
                .build())
        .deployTime(false)
        .displayName("displayName")
        .exclude(List.of("exclude"))
        .followSymlinks(SymlinkFollowMode.NEVER)
        .ignoreMode(IgnoreMode.GLOB)
        .readers(List.of(grantable))
        .sourceKMSKey(keyRef)
        .build();
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;
using Amazon.CDK.AWS.IAM;
using Amazon.CDK.AWS.Synthetics;
using Amazon.CDK.Interfaces.KMS;

DockerImage dockerImage;
IGrantable grantable;
IKeyRef keyRef;
ILocalBundling localBundling;

var assetCode = new AssetCode("assetPath", new AssetOptions {
    AssetHash = "assetHash",
    AssetHashType = AssetHashType.SOURCE,
    Bundling = new BundlingOptions {
        Image = dockerImage,

        // the properties below are optional
        BundlingFileAccess = BundlingFileAccess.VOLUME_COPY,
        Command = new [] { "command" },
        Entrypoint = new [] { "entrypoint" },
        Environment = new Dictionary<string, string> {
            { "environmentKey", "environment" }
        },
        Local = localBundling,
        Network = "network",
        OutputType = BundlingOutput.ARCHIVED,
        Platform = "platform",
        SecurityOpt = "securityOpt",
        User = "user",
        Volumes = new [] { new DockerVolume {
            ContainerPath = "containerPath",
            HostPath = "hostPath",

            // the properties below are optional
            Consistency = DockerVolumeConsistency.CONSISTENT
        } },
        VolumesFrom = new [] { "volumesFrom" },
        WorkingDirectory = "workingDirectory"
    },
    DeployTime = false,
    DisplayName = "displayName",
    Exclude = new [] { "exclude" },
    FollowSymlinks = SymlinkFollowMode.NEVER,
    IgnoreMode = IgnoreMode.GLOB,
    Readers = new [] { grantable },
    SourceKMSKey = keyRef
});
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"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var dockerImage DockerImage
var grantable IGrantable
var keyRef IKeyRef
var localBundling ILocalBundling

assetCode := awscdk.Aws_synthetics.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),
	DisplayName: jsii.String("displayName"),
	Exclude: []*string{
		jsii.String("exclude"),
	},
	FollowSymlinks: cdk.SymlinkFollowMode_NEVER,
	IgnoreMode: cdk.IgnoreMode_GLOB,
	Readers: []IGrantable{
		grantable,
	},
	SourceKMSKey: keyRef,
})

Initializer ​

ts
new AssetCode(assetPath: string, options?: AssetOptions)
python
AssetCode(asset_path: str, options: typing.Optional[AssetOptions] = None)
java
new AssetCode(String assetPath, AssetOptions options)
csharp
new AssetCode(string assetPath, AssetOptions? options = null)
go
NewAssetCode(AssetPath *string, Options AssetOptions)

Methods ​

bind(scope: Construct, handler: string, family: RuntimeFamily, runtimeName?: string): CodeConfigdef bind(self, scope: Construct, handler: str, family: RuntimeFamily, runtime_name: typing.Optional[str] = None) -> CodeConfigpublic CodeConfig bind(Construct scope, String handler, RuntimeFamily family, String runtimeName)public CodeConfig Bind(Construct scope, string handler, RuntimeFamily family, string? runtimeName = null)func 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 // chainable@staticmethod def from_asset(asset_path: str, options: typing.Optional[AssetOptions] = None) -> AssetCodepublic static AssetCode fromAsset(String assetPath, AssetOptions options)public static AssetCode FromAsset(string assetPath, AssetOptions? options = null)func FromAsset(AssetPath *string, Options AssetOptions) AssetCodestatic#
Specify code from a local path.

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

1 parameter · returns

Parameters

  • assetPathasset_pathassetPathassetPathAssetPath — Either a directory or a .zip file.

Returns: AssetCode associated with the specified path.

fromBucket(bucket: IBucketRef, key: string, objectVersion?: string): S3Code@staticmethod def from_bucket(bucket: IBucketRef, key: str, object_version: typing.Optional[str] = None) -> S3Codepublic static S3Code fromBucket(IBucketRef bucket, String key, String objectVersion)public static S3Code FromBucket(IBucketRef bucket, string key, string? objectVersion = null)func FromBucket(Bucket IBucketRef, Key *string, ObjectVersion *string) S3Codestatic#
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.

3 parameters · returns

Parameters

  • bucketbucketbucketbucketBucket — The S3 bucket.
  • keykeykeykeyKey — The object key.
  • objectVersionobject_versionobjectVersionobjectVersionObjectVersion — Optional S3 object version.

Returns: S3Code associated with the specified S3 object.

fromInline(code: string): InlineCode@staticmethod def from_inline(code: str) -> InlineCodepublic static InlineCode fromInline(String code)public static InlineCode FromInline(string code)func FromInline(Code *string) InlineCodestatic#
Specify code inline.
1 parameter · returns

Parameters

  • codecodecodecodeCode — The actual handler code (limited to 5MB).

Returns: InlineCode with inline code.