DockerImageAsset
An asset that represents a Docker image.
The image will be created in build time and uploaded to an ECR repository.
Example
import { DockerImageAsset } from 'aws-cdk-lib/aws-ecr-assets';
const asset = new DockerImageAsset(this, 'MyBuildImage', {
directory: path.join(__dirname, 'my-image'),
buildContexts: {
mycontext: path.join(__dirname, 'path/to/context'),
alpine: 'docker-image://alpine:latest',
},
});
from aws_cdk.aws_ecr_assets import DockerImageAsset
asset = DockerImageAsset(self, "MyBuildImage",
directory=path.join(__dirname, "my-image"),
build_contexts={
"mycontext": path.join(__dirname, "path/to/context"),
"alpine": "docker-image://alpine:latest"
}
)
import software.amazon.awscdk.services.ecr.assets.DockerImageAsset;
DockerImageAsset asset = DockerImageAsset.Builder.create(this, "MyBuildImage")
.directory(join(__dirname, "my-image"))
.buildContexts(Map.of(
"mycontext", join(__dirname, "path/to/context"),
"alpine", "docker-image://alpine:latest"))
.build();
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Ecr.Assets;
var asset = new DockerImageAsset(this, "MyBuildImage", new DockerImageAssetProps {
Directory = Join(__dirname, "my-image"),
BuildContexts = new Dictionary<string, string> {
{ "mycontext", Join(__dirname, "path/to/context") },
{ "alpine", "docker-image://alpine:latest" }
}
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
asset := awscdk.NewDockerImageAsset(this, jsii.String("MyBuildImage"), &DockerImageAssetProps{
Directory: path.join(__dirname, jsii.String("my-image")),
BuildContexts: map[string]*string{
"mycontext": path.join(__dirname, jsii.String("path/to/context")),
"alpine": jsii.String("docker-image://alpine:latest"),
},
})
Initializer
new DockerImageAsset(scope: Construct, id: string, props: DockerImageAssetProps)
DockerImageAsset(scope: Construct, id: str, props: DockerImageAssetProps)
new DockerImageAsset(Construct scope, String id, DockerImageAssetProps props)
new DockerImageAsset(Construct scope, string id, DockerImageAssetProps props)
NewDockerImageAsset(Scope Construct, Id *string, Props DockerImageAssetProps)
Construct Props
assetNameoptionalstringasset_nameoptionalstrassetNameoptionalStringAssetNameoptionalstringAssetNameoptional*string#Default: no asset name
Required if using AppScopedStagingSynthesizer.
buildArgsoptional{ [key: string]: string }build_argsoptionaltyping.Mapping[str, str]buildArgsoptionalMap<String, String>BuildArgsoptionalIDictionary<string, string>BuildArgsoptional*map[string]*string#Default: no build args are passed
Since Docker build arguments are resolved before deployment, keys and values cannot refer to unresolved tokens (such as lambda.functionArn or queue.queueUrl).
buildContextsoptional{ [key: string]: string }build_contextsoptionaltyping.Mapping[str, str]buildContextsoptionalMap<String, String>BuildContextsoptionalIDictionary<string, string>BuildContextsoptional*map[string]*string#Default: no additional build contexts
notes
Build contexts can be used to specify additional directories or images to use during the build. Each entry specifies a named build context and its source (a directory path, a URL, or a docker image).
Since Docker build contexts are resolved before deployment, keys and values cannot refer to unresolved tokens (such as lambda.functionArn or queue.queueUrl).
buildSecretsoptional{ [key: string]: string }build_secretsoptionaltyping.Mapping[str, str]buildSecretsoptionalMap<String, String>BuildSecretsoptionalIDictionary<string, string>BuildSecretsoptional*map[string]*string#Default: no build secrets
Docker BuildKit must be enabled to use build secrets.
example
import { DockerBuildSecret } from 'aws-cdk-lib';
const buildSecrets = {
'MY_SECRET': DockerBuildSecret.fromSrc('file.txt')
};
buildSshoptionalstringbuild_sshoptionalstrbuildSshoptionalStringBuildSshoptionalstringBuildSshoptional*string#Default: no --ssh flag
Docker BuildKit must be enabled to use the ssh flag
cacheDisabledoptionalbooleancache_disabledoptionalboolcacheDisabledoptionalBooleanCacheDisabledoptionalboolCacheDisabledoptional*bool#Default: cache is used
cacheFromoptionalDockerCacheOption[]cache_fromoptionaltyping.List[DockerCacheOption]cacheFromoptionalList<DockerCacheOption>CacheFromoptionalDockerCacheOption[]CacheFromoptional*[]DockerCacheOption#Default: no cache from options are passed to the build command
cacheTooptionalDockerCacheOptioncache_tooptionalDockerCacheOptioncacheTooptionalDockerCacheOptionCacheTooptionalDockerCacheOptionCacheTooptionalDockerCacheOption#Default: no cache to options are passed to the build command
Any directory inside with a name that matches the CDK output folder (cdk.out by default) will be excluded from the asset
displayNameoptionalstringdisplay_nameoptionalstrdisplayNameoptionalStringDisplayNameoptionalstringDisplayNameoptional*string#Default: Stack-relative construct path
notes
If supplied, the display name will be used in locations where the asset identifier is printed, like in the CLI progress information. If the same asset is added multiple times, the display name of the first occurrence is used.
If assetName is given, it will also be used as the default displayName. Otherwise, the default is the construct path of the ImageAsset construct, with respect to the enclosing stack. If the asset is produced by a construct helper function (such as lambda.Code.fromAssetImage()), this will look like MyFunction/AssetImage.
We use the stack-relative construct path so that in the common case where you have multiple stacks with the same asset, we won't show something like /MyBetaStack/MyFunction/Code when you are actually deploying to production.
excludeoptionalstring[]excludeoptionaltyping.List[str]excludeoptionalList<String>Excludeoptionalstring[]Excludeoptional*[]*string#Default: nothing is excluded
See ignoreMode to set the matching behavior. Has no effect on Assets bundled using the bundling property.
extraHashoptionalstringextra_hashoptionalstrextraHashoptionalStringExtraHashoptionalstringExtraHashoptional*string#Default: hash is only based on source content
fileoptionalstringfileoptionalstrfileoptionalStringFileoptionalstringFileoptional*string= 'Dockerfile'#followSymlinksoptionalSymlinkFollowModefollow_symlinksoptionalSymlinkFollowModefollowSymlinksoptionalSymlinkFollowModeFollowSymlinksoptionalSymlinkFollowModeFollowSymlinksoptionalSymlinkFollowMode= SymlinkFollowMode.NEVER#ignoreModeoptionalIgnoreModeignore_modeoptionalIgnoreModeignoreModeoptionalIgnoreModeIgnoreModeoptionalIgnoreModeIgnoreModeoptionalIgnoreMode= IgnoreMode.GLOB#invalidationoptionalDockerImageAssetInvalidationOptionsinvalidationoptionalDockerImageAssetInvalidationOptionsinvalidationoptionalDockerImageAssetInvalidationOptionsInvalidationoptionalDockerImageAssetInvalidationOptionsInvalidationoptionalDockerImageAssetInvalidationOptions#Default: hash all parameters
networkModeoptionalNetworkModenetwork_modeoptionalNetworkModenetworkModeoptionalNetworkModeNetworkModeoptionalNetworkModeNetworkModeoptionalNetworkMode#Default: no networking mode specified (the default networking mode NetworkMode.DEFAULT will be used)
Support docker API 1.25+.
outputsoptionalstring[]outputsoptionaltyping.List[str]outputsoptionalList<String>Outputsoptionalstring[]Outputsoptional*[]*string#Default: no outputs are passed to the build command (default outputs are used)
platformoptionalPlatformplatformoptionalPlatformplatformoptionalPlatformPlatformoptionalPlatformPlatformoptionalPlatform#Default: no platform specified (the current machine architecture will be used)
Requires Docker Buildx.
Default: no target
Properties
As this is a plain string, it can be used in construct IDs in order to enforce creation of a new resource when the content hash has changed.
The tag may differ from the assetHash if a stack synthesizer adds a dockerTagPrefix.
Use this reference to pull the asset.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#repositoryIRepositoryrepositoryIRepositoryrepositoryIRepositoryRepositoryIRepositoryRepositoryIRepository#Methods
addResourceMetadata(resource: CfnResource, resourceProperty: string): voiddef add_resource_metadata(self, resource: CfnResource, resource_property: str) -> Nonepublic void addResourceMetadata(CfnResource resource, String resourceProperty)public void AddResourceMetadata(CfnResource resource, string resourceProperty)func AddResourceMetadata(Resource CfnResource, ResourceProperty *string)#notes · 2 parameters
This can be used by tools such as SAM CLI to provide local experience such as local invocation and debugging of Lambda functions.
Asset metadata will only be included if the stack is synthesized with the "aws:cdk:enable-asset-metadata" context key defined, which is the default behavior when synthesizing via the CDK Toolkit.
Parameters
resourceresourceresourceresourceResource— The CloudFormation resource which is using this asset [disable-awslint:ref-via-interface].resourcePropertyresource_propertyresourcePropertyresourcePropertyResourceProperty— The property name where this asset is referenced.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
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.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.
1 parameter · returns
Parameters
mixinsmixinsmixinsmixinsMixins— The mixins to apply.
Returns: This construct for chaining