diff --git a/v2/apps.md b/v2/apps.md
index 02d6268a..2d235a05 100644
--- a/v2/apps.md
+++ b/v2/apps.md
@@ -6,17 +6,14 @@ The AWS Cloud Development Kit \(AWS CDK\) application is called an *app*\. A CDK
+ [Defining apps](#apps_construct)
+ [Working with apps](#apps-work)
-## Defining apps
You create an app by importing and using the [https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.App.html](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.App.html) class from the AWS Construct Library\. You then define your stacks within the app and define your constructs within stacks\. An app must contain at least one stack\.
With this structure in place, you can synthesize stacks before deployment\. Synthesizing stacks involves creating an AWS CloudFormation template per stack that is then used to deploy to AWS CloudFormation to provision your AWS resources\. To learn more about stacks, see [Stacks](stacks.md)\.
-The `App` construct doesn't require any initialization arguments\. It is the only construct that can be used as a root for the construct tree\.
-The following is an example of a new AWS CDK app that includes a stack named `MyFirstStack`\. The stack is then synthesized, producing an AWS CloudFormation template:
+---
-------
#### [ TypeScript ]
```
@@ -25,7 +22,8 @@ new MyFirstStack(app, 'hello-cdk');
app.synth();
```
-------
+---
+
#### [ JavaScript ]
```
@@ -34,7 +32,8 @@ new MyFirstStack(app, 'hello-cdk');
app.synth();
```
-------
+---
+
#### [ Python ]
```
@@ -43,7 +42,8 @@ MyFirstStack(app, "hello-cdk")
app.synth()
```
-------
+---
+
#### [ Java ]
```
@@ -52,7 +52,8 @@ new MyFirstStack(app, "hello-cdk");
app.synth();
```
-------
+---
+
#### [ C\# ]
```
@@ -61,7 +62,23 @@ new MyFirstStack(app, "hello-cdk");
app.Synth();
```
-------
+---
+
+#### [ Go ]
+
+```
+app := awscdk.NewApp(nil)
+
+MyFirstStack(app, "MyFirstStack", &MyFirstStackProps{
+ awscdk.StackProps{
+ Env: env(),
+ },
+})
+
+app.Synth(nil)
+```
+
+---
Stacks within a single app can easily refer to each other's resources and properties\. The AWS CDK infers dependencies between stacks so that they can be deployed in the correct order\. You can deploy any or all of the stacks within an app with a single `cdk deploy` command\.
@@ -71,7 +88,7 @@ Stacks within a single app can easily refer to each other's resources and proper
The following diagram shows the phases that the AWS CDK goes through when you call cdk deploy\. This command deploys the resources that your app defines\.
-![\[Image NOT FOUND\]](http://docs.aws.amazon.com/cdk/v2/guide/images/Lifecycle.png)
+![[Image NOT FOUND]](http://docs.aws.amazon.com/cdk/v2/guide/images/Lifecycle.png)
An AWS CDK app goes through the following phases in its lifecycle\.
@@ -91,8 +108,7 @@ This is the final stage of the execution of your AWS CDK app\. It's triggered by
In this phase, the AWS CDK Toolkit takes the deployment artifacts cloud assembly produced by the synthesis phase and deploys it to an AWS environment\. It uploads assets to Amazon S3 and Amazon ECR, or wherever they need to go\. Then, it starts an AWS CloudFormation deployment to deploy the application and create the resources\.
By the time the AWS CloudFormation deployment phase \(step 5\) starts, your AWS CDK app has already finished and exited\. This has the following implications:
-+ The AWS CDK app can't respond to events that happen during deployment, such as a resource being created or the whole deployment finishing\. To run code during the deployment phase, you must inject it into the AWS CloudFormation template as a [custom resource](cfn_layer.md#develop-customize-custom)\. For more information about adding a custom resource to your app, see the [AWS CloudFormation module](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudformation-readme.html), or the [custom\-resource](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/custom-resource/) example\.
-+ The AWS CDK app might have to work with values that can't be known at the time it runs\. For example, if the AWS CDK app defines an Amazon S3 bucket with an automatically generated name, and you retrieve the `bucket.bucketName` \(Python: `bucket_name`\) attribute, that value is not the name of the deployed bucket\. Instead, you get a `Token` value\. To determine whether a particular value is available, call `cdk.isUnresolved(value)` \(Python: `is_unresolved`\)\. See [Tokens](tokens.md) for details\.
+
### Cloud assemblies
@@ -104,7 +120,8 @@ To interact with the cloud assembly that your AWS CDK app creates, you typically
The CDK Toolkit needs to know how to execute your AWS CDK app\. If you created the project from a template using the `cdk init` command, your app's `cdk.json` file includes an `app` key\. This key specifies the necessary command for the language that the app is written in\. If your language requires compilation, the command line performs this step before running the app, so you can't forget to do it\.
-------
+---
+
#### [ TypeScript ]
```
@@ -113,7 +130,8 @@ The CDK Toolkit needs to know how to execute your AWS CDK app\. If you created t
}
```
-------
+---
+
#### [ JavaScript ]
```
@@ -122,7 +140,8 @@ The CDK Toolkit needs to know how to execute your AWS CDK app\. If you created t
}
```
-------
+---
+
#### [ Python ]
```
@@ -131,7 +150,8 @@ The CDK Toolkit needs to know how to execute your AWS CDK app\. If you created t
}
```
-------
+---
+
#### [ Java ]
```
@@ -140,7 +160,8 @@ The CDK Toolkit needs to know how to execute your AWS CDK app\. If you created t
}
```
-------
+---
+
#### [ C\# ]
```
@@ -149,7 +170,17 @@ The CDK Toolkit needs to know how to execute your AWS CDK app\. If you created t
}
```
-------
+---
+
+#### [ Go ]
+
+```
+{
+ "app": "go mod download && go run my-app.go"
+}
+```
+
+---
If you didn't create your project using the CDK Toolkit, or if you want to override the command line given in `cdk.json`, you can use the \-\-app option when issuing the `cdk` command\.
@@ -157,10 +188,8 @@ If you didn't create your project using the CDK Toolkit, or if you want to overr
$ cdk --app 'executable' cdk-command ...
```
-The *executable* part of the command indicates the command that should be run to execute your CDK application\. Use quotation marks as shown, since such commands contain spaces\. The *cdk\-command* is a subcommand like synth or deploy that tells the CDK Toolkit what you want to do with your app\. Follow this with any additional options needed for that subcommand\.
+The _executable_ part of the command indicates the command that should be run to execute your CDK application\. Use quotation marks as shown, since such commands contain spaces\. The _cdk\-command_ is a subcommand like synth or deploy that tells the CDK Toolkit what you want to do with your app\. Follow this with any additional options needed for that subcommand\.
The CLI can also interact directly with an already\-synthesized cloud assembly\. To do that, pass the directory in which the cloud assembly is stored in \-\-app\. The following example lists the stacks defined in the cloud assembly stored under `./my-cloud-assembly`\.
-```
-$ cdk --app ./my-cloud-assembly ls
```
\ No newline at end of file
diff --git a/v2/aspects.md b/v2/aspects.md
index 8dda72f4..526f28aa 100644
--- a/v2/aspects.md
+++ b/v2/aspects.md
@@ -4,42 +4,55 @@ Aspects are a way to apply an operation to all constructs in a given scope\. The
To apply an aspect to a construct and all constructs in the same scope, call [https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Aspects.html#static-ofscope](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Aspects.html#static-ofscope)`.of(SCOPE).add()` with a new aspect, as shown in the following example\.
-------
+---
+
#### [ TypeScript ]
```
Aspects.of(myConstruct).add(new SomeAspect(...));
```
-------
+---
+
#### [ JavaScript ]
```
Aspects.of(myConstruct).add(new SomeAspect(...));
```
-------
+---
+
#### [ Python ]
```
Aspects.of(my_construct).add(SomeAspect(...))
```
-------
+---
+
#### [ Java ]
```
Aspects.of(myConstruct).add(new SomeAspect(...));
```
-------
+---
+
#### [ C\# ]
```
Aspects.Of(myConstruct).add(new SomeAspect(...));
```
-------
+---
+
+#### [ Go ]
+
+```
+awscdk.Aspects_Of(stack).Add(awscdk.NewTag(...))
+```
+
+---
The AWS CDK uses aspects to [tag resources](tagging.md), but the framework can also be used for other purposes\. For example, you can use it to validate or change the AWS CloudFormation resources that are defined for you by higher\-level constructs\.
@@ -47,7 +60,8 @@ The AWS CDK uses aspects to [tag resources](tagging.md), but the framework can a
Aspects employ the [visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern)\. An aspect is a class that implements the following interface\.
-------
+---
+
#### [ TypeScript ]
```
@@ -55,17 +69,20 @@ interface IAspect {
visit(node: IConstruct): void;}
```
-------
+---
+
#### [ JavaScript ]
JavaScript doesn't have interfaces as a language feature\. Therefore, an aspect is simply an instance of a class having a `visit` method that accepts the node to be operated on\.
-------
+---
+
#### [ Python ]
Python doesn't have interfaces as a language feature\. Therefore, an aspect is simply an instance of a class having a `visit` method that accepts the node to be operated on\.
-------
+---
+
#### [ Java ]
```
@@ -74,7 +91,8 @@ public interface IAspect {
}
```
-------
+---
+
#### [ C\# ]
```
@@ -84,7 +102,17 @@ public interface IAspect
}
```
-------
+---
+
+#### [ Go ]
+
+```
+type IAspect interface {
+ Visit(node constructs.IConstruct)
+}
+```
+
+---
When you call `Aspects.of(SCOPE).add(...)`, the construct adds the aspect to an internal list of aspects\. You can obtain the list with `Aspects.of(SCOPE)`\.
@@ -98,7 +126,8 @@ Aspects don't propagate across `Stage` construct boundaries, because `Stages` ar
The following example validates that all buckets created in the stack have versioning enabled\. The aspect adds an error annotation to the constructs that fail the validation\. This results in the synth operation failing and prevents deploying the resulting cloud assembly\.
-------
+---
+
#### [ TypeScript ]
```
@@ -122,7 +151,8 @@ class BucketVersioningChecker implements IAspect {
Aspects.of(stack).add(new BucketVersioningChecker());
```
-------
+---
+
#### [ JavaScript ]
```
@@ -146,7 +176,8 @@ class BucketVersioningChecker {
Aspects.of(stack).add(new BucketVersioningChecker());
```
-------
+---
+
#### [ Python ]
```
@@ -168,7 +199,8 @@ class BucketVersioningChecker:
Aspects.of(stack).add(BucketVersioningChecker())
```
-------
+---
+
#### [ Java ]
```
@@ -195,7 +227,8 @@ public class BucketVersioningChecker implements IAspect
Aspects.of(stack).add(new BucketVersioningChecker());
```
-------
+---
+
#### [ C\# ]
```
@@ -219,4 +252,4 @@ class BucketVersioningChecker : Amazon.Jsii.Runtime.Deputy.DeputyBase, IAspect
Aspects.Of(stack).add(new BucketVersioningChecker());
```
-------
\ No newline at end of file
+---
diff --git a/v2/assets.md b/v2/assets.md
index d461c9ed..f60cf402 100644
--- a/v2/assets.md
+++ b/v2/assets.md
@@ -36,7 +36,8 @@ You can define local files and directories as assets, and the AWS CDK packages a
The following example defines a local directory asset and a file asset\.
-------
+---
+
#### [ TypeScript ]
```
@@ -53,7 +54,8 @@ const fileAsset = new Asset(this, 'SampleSingleFileAsset', {
});
```
-------
+---
+
#### [ JavaScript ]
```
@@ -70,7 +72,8 @@ const fileAsset = new Asset(this, 'SampleSingleFileAsset', {
});
```
-------
+---
+
#### [ Python ]
```
@@ -90,7 +93,8 @@ file_asset = Asset(self, 'SampleSingleFileAsset',
)
```
-------
+---
+
#### [ Java ]
```
@@ -110,7 +114,8 @@ Asset fileAsset = Asset.Builder.create(this, "SampleSingleFileAsset")
.path(new File(startDir, "file-asset.txt").toString()).build();
```
-------
+---
+
#### [ C\# ]
```
@@ -130,7 +135,26 @@ var fileAsset = new Asset(this, "SampleSingleFileAsset", new AssetProps
});
```
-------
+---
+
+#### [ Go ]
+
+```
+ dirName, err := os.Getwd()
+ if err != nil {
+ panic(err)
+ }
+
+ awss3assets.NewAsset(stack, jsii.String("SampleZippedDirAsset"), &awss3assets.AssetProps{
+ Path: jsii.String(path.Join(dirName, "sample-asset-directory")),
+ })
+
+ awss3assets.NewAsset(stack, jsii.String("SampleSingleFileAsset"), &awss3assets.AssetProps{
+ Path: jsii.String(path.Join(dirName, "file-asset.txt")),
+ })
+```
+
+---
In most cases, you don't need to directly use the APIs in the `aws-s3-assets` module\. Modules that support assets, such as `aws-lambda`, have convenience methods so that you can use assets\. For Lambda functions, the [fromAsset\(\)](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Code.html#static-fromwbrassetpath-options) static method enables you to specify a directory or a \.zip file in the local file system\.
@@ -150,7 +174,8 @@ def lambda_handler(event, context):
The code for the main AWS CDK app should look like the following\.
-------
+---
+
#### [ TypeScript ]
```
@@ -172,7 +197,8 @@ export class HelloAssetStack extends cdk.Stack {
}
```
-------
+---
+
#### [ JavaScript ]
```
@@ -195,7 +221,8 @@ class HelloAssetStack extends cdk.Stack {
module.exports = { HelloAssetStack }
```
-------
+---
+
#### [ Python ]
```
@@ -216,7 +243,8 @@ class HelloAssetStack(Stack):
handler="index.lambda_handler")
```
-------
+---
+
#### [ Java ]
```
@@ -241,12 +269,13 @@ public class HelloAssetStack extends Stack {
Function.Builder.create(this, "myLambdaFunction")
.code(Code.fromAsset(new File(startDir, "handler").toString()))
.runtime(Runtime.PYTHON_3_6)
- .handler("index.lambda_handler").build();
+ .handler("index.lambda_handler").build();
}
}
```
-------
+---
+
#### [ C\# ]
```
@@ -268,7 +297,47 @@ public class HelloAssetStack : Stack
}
```
-------
+---
+
+#### [ Go ]
+
+```
+import (
+ "os"
+ "path"
+
+ "github.com/aws/aws-cdk-go/awscdk/v2"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awslambda"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awss3assets"
+
+ "github.com/aws/constructs-go/constructs/v10"
+ "github.com/aws/jsii-runtime-go"
+)
+
+
+func HelloAssetStack(scope constructs.Construct, id string, props *HelloAssetStackProps) awscdk.Stack {
+ var sprops awscdk.StackProps
+ if props != nil {
+ sprops = props.StackProps
+ }
+ stack := awscdk.NewStack(scope, &id, &sprops)
+
+ dirName, err := os.Getwd()
+ if err != nil {
+ panic(err)
+ }
+
+ awslambda.NewFunction(stack, jsii.String("myLambdaFunction"), &awslambda.FunctionProps{
+ Code: awslambda.AssetCode_FromAsset(jsii.String(path.Join(dirName, "handler")), &awss3assets.AssetOptions{}),
+ Runtime: awslambda.Runtime_PYTHON_3_6(),
+ Handler: jsii.String("index.lambda_handler"),
+ })
+
+ return stack
+}
+```
+
+---
The `Function` method uses assets to bundle the contents of the directory and use it for the function's code\.
@@ -281,7 +350,8 @@ Amazon S3 asset types also expose [deploy\-time attributes](resources.md#resourc
The following example uses deploy\-time attributes to pass the location of an image asset into a Lambda function as environment variables\. \(The kind of file doesn't matter; the PNG image used here is only an example\.\)
-------
+---
+
#### [ TypeScript ]
```
@@ -304,7 +374,8 @@ new lambda.Function(this, "myLambdaFunction", {
});
```
-------
+---
+
#### [ JavaScript ]
```
@@ -327,7 +398,8 @@ new lambda.Function(this, "myLambdaFunction", {
});
```
-------
+---
+
#### [ Python ]
```
@@ -351,7 +423,8 @@ lambda_.Function(self, "myLambdaFunction",
S3_OBJECT_URL=image_asset.s3_object_url))
```
-------
+---
+
#### [ Java ]
```
@@ -385,7 +458,8 @@ public class FunctionStack extends Stack {
}
```
-------
+---
+
#### [ C\# ]
```
@@ -414,7 +488,42 @@ new Function(this, "myLambdaFunction", new FunctionProps
});
```
-------
+---
+
+#### [ Go ]
+
+```
+import (
+ "os"
+ "path"
+
+ "github.com/aws/aws-cdk-go/awscdk/v2"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awslambda"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awss3assets"
+)
+
+dirName, err := os.Getwd()
+if err != nil {
+ panic(err)
+}
+
+imageAsset := awss3assets.NewAsset(stack, jsii.String("SampleAsset"), &awss3assets.AssetProps{
+ Path: jsii.String(path.Join(dirName, "images/my-image.png")),
+})
+
+awslambda.NewFunction(stack, jsii.String("myLambdaFunction"), &awslambda.FunctionProps{
+ Code: awslambda.AssetCode_FromAsset(jsii.String(path.Join(dirName, "handler"))),
+ Runtime: awslambda.Runtime_PYTHON_3_6(),
+ Handler: jsii.String("index.lambda_handler"),
+ Environment: &map[string]*string{
+ "S3_BUCKET_NAME": imageAsset.S3BucketName(),
+ "S3_OBJECT_KEY": imageAsset.S3ObjectKey(),
+ "S3_URL": imageAsset.S3ObjectUrl(),
+ },
+})
+```
+
+---
### Permissions
@@ -422,7 +531,8 @@ If you use Amazon S3 assets directly through the [aws\-s3\-assets](https://docs.
The following example grants an IAM group read permissions on a file asset\.
-------
+---
+
#### [ TypeScript ]
```
@@ -437,7 +547,8 @@ const group = new iam.Group(this, 'MyUserGroup');
asset.grantRead(group);
```
-------
+---
+
#### [ JavaScript ]
```
@@ -452,7 +563,8 @@ const group = new iam.Group(this, 'MyUserGroup');
asset.grantRead(group);
```
-------
+---
+
#### [ Python ]
```
@@ -469,7 +581,8 @@ dirname = os.path.dirname(__file__)
asset.grant_read(group)
```
-------
+---
+
#### [ Java ]
```
@@ -494,7 +607,8 @@ public class GrantStack extends Stack {
}
```
-------
+---
+
#### [ C\# ]
```
@@ -511,15 +625,45 @@ var group = new Group(this, "MyUserGroup");
asset.GrantRead(group);
```
-------
+---
+
+#### [ Go ]
+
+```
+import (
+ "os"
+ "path"
+
+ "github.com/aws/aws-cdk-go/awscdk/v2"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awsiam"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awss3assets"
+)
+
+
+dirName, err := os.Getwd()
+if err != nil {
+ panic(err)
+}
+
+asset := awss3assets.NewAsset(stack, jsii.String("MyFile"), &awss3assets.AssetProps{
+ Path: jsii.String(path.Join(dirName, "my-image.png")),
+})
+
+group := awsiam.NewGroup(stack, jsii.String("MyUserGroup"), &awsiam.GroupProps{})
+
+asset.GrantRead(group)
+```
+
+---
## Docker image assets
The AWS CDK supports bundling local Docker images as assets through the [aws\-ecr\-assets](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets-readme.html) module\.
-The following example defines a Docker image that is built locally and pushed to Amazon ECR\. Images are built from a local Docker context directory \(with a Dockerfile\) and uploaded to Amazon ECR by the AWS CDK CLI or your app's CI/CD pipeline\. The images can be naturally referenced in your AWS CDK app\.
+The following example defines a Docker image that is built locally and pushed to Amazon ECR\. Images are built from a local Docker context directory \(with a Dockerfile\) and uploaded to Amazon ECR by the AWS CDK CLI or your app's CI/CD pipeline\. The images can be naturally referenced in your AWS CDK app\.
+
+---
-------
#### [ TypeScript ]
```
@@ -530,7 +674,8 @@ const asset = new DockerImageAsset(this, 'MyBuildImage', {
});
```
-------
+---
+
#### [ JavaScript ]
```
@@ -541,7 +686,8 @@ const asset = new DockerImageAsset(this, 'MyBuildImage', {
});
```
-------
+---
+
#### [ Python ]
```
@@ -554,7 +700,8 @@ asset = DockerImageAsset(self, 'MyBuildImage',
directory=os.path.join(dirname, 'my-image'))
```
-------
+---
+
#### [ Java ]
```
@@ -566,7 +713,8 @@ DockerImageAsset asset = DockerImageAsset.Builder.create(this, "MyBuildImage")
.directory(new File(startDir, "my-image").toString()).build();
```
-------
+---
+
#### [ C\# ]
```
@@ -579,15 +727,40 @@ var asset = new DockerImageAsset(this, "MyBuildImage", new DockerImageAssetProps
});
```
-------
+---
+
+#### [ Go ]
+
+```
+import (
+ "os"
+ "path"
+
+ "github.com/aws/aws-cdk-go/awscdk/v2"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awsecrassets"
+)
+
+
+dirName, err := os.Getwd()
+if err != nil {
+ panic(err)
+}
+
+asset := awsecrassets.NewDockerImageAsset(stack, jsii.String("MyBuildImage"), &awsecrassets.DockerImageAssetProps{
+ Directory: jsii.String(path.Join(dirName, "my-image")),
+})
+```
+
+---
The `my-image` directory must include a Dockerfile\. The AWS CDK CLI builds a Docker image from `my-image`, pushes it to an Amazon ECR repository, and specifies the name of the repository as an AWS CloudFormation parameter to your stack\. Docker image asset types expose [deploy\-time attributes](resources.md#resources_attributes) that can be referenced in AWS CDK libraries and apps\. The AWS CDK CLI command cdk synth displays asset properties as AWS CloudFormation parameters\.
### Amazon ECS task definition example
-A common use case is to create an Amazon ECS [TaskDefinition](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.TaskDefinition.html) to run Docker containers\. The following example specifies the location of a Docker image asset that the AWS CDK builds locally and pushes to Amazon ECR\.
+A common use case is to create an Amazon ECS [TaskDefinition](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.TaskDefinition.html) to run Docker containers\. The following example specifies the location of a Docker image asset that the AWS CDK builds locally and pushes to Amazon ECR\.
+
+---
-------
#### [ TypeScript ]
```
@@ -609,7 +782,8 @@ taskDefinition.addContainer("my-other-container", {
});
```
-------
+---
+
#### [ JavaScript ]
```
@@ -631,12 +805,13 @@ taskDefinition.addContainer("my-other-container", {
});
```
-------
+---
+
#### [ Python ]
```
import aws_cdk.aws_ecs as ecs
-import aws_cdk.aws_ecr_assets as ecr_assets
+import aws_cdk.aws_ecr_assets as ecr_assets
import os.path
dirname = os.path.dirname(__file__)
@@ -652,7 +827,8 @@ task_definition.add_container("my-other-container",
image=ecs.ContainerImage.from_docker_image_asset(asset))
```
-------
+---
+
#### [ Java ]
```
@@ -678,7 +854,8 @@ taskDefinition.addContainer("my-other-container",
.build();
```
-------
+---
+
#### [ C\# ]
```
@@ -703,13 +880,48 @@ taskDefinition.AddContainer("my-other-container", new ContainerDefinitionOptions
});
```
-------
+---
+
+#### [ Go ]
+
+```
+import (
+ "os"
+ "path"
+
+ "github.com/aws/aws-cdk-go/awscdk/v2"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awsecrassets"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awsecs"
+)
+
+
+dirName, err := os.Getwd()
+if err != nil {
+ panic(err)
+}
+
+taskDefinition := awsecs.NewTaskDefinition(stack, jsii.String("TaskDef"), &awsecs.TaskDefinitionProps{
+ MemoryMiB: jsii.String("1024"),
+ Cpu: jsii.String("512"),
+})
+
+asset := awsecrassets.NewDockerImageAsset(stack, jsii.String("MyBuildImage"), &awsecrassets.DockerImageAssetProps{
+ Directory: jsii.String(path.Join(dirName, "my-image")),
+})
+
+taskDefinition.AddContainer(jsii.String("MyOtherContainer"), &awsecs.ContainerDefinitionOptions{
+ Image: awsecs.ContainerImage_FromDockerImageAsset(asset),
+})
+```
+
+---
### Deploy\-time attributes example
The following example shows how to use the deploy\-time attributes `repository` and `imageUri` to create an Amazon ECS task definition with the AWS Fargate launch type\. Note that the Amazon ECR repo lookup requires the image's tag, not its URI, so we snip it from the end of the asset's URI\.
-------
+---
+
#### [ TypeScript ]
```
@@ -731,7 +943,8 @@ taskDefinition.addContainer("my-other-container", {
});
```
-------
+---
+
#### [ JavaScript ]
```
@@ -753,7 +966,8 @@ taskDefinition.addContainer("my-other-container", {
});
```
-------
+---
+
#### [ Python ]
```
@@ -774,7 +988,8 @@ task_definition.add_container("my-other-container",
asset.repository, asset.image_uri.rpartition(":")[-1]))
```
-------
+---
+
#### [ Java ]
```
@@ -803,7 +1018,8 @@ taskDefinition.addContainer("my-other-container",
asset.getRepository(), imageTag)).build());
```
-------
+---
+
#### [ C\# ]
```
@@ -827,13 +1043,48 @@ taskDefinition.AddContainer("my-other-container", new ContainerDefinitionOptions
});
```
-------
+---
+
+#### [ Go ]
+
+```
+import (
+ "os"
+ "path"
+
+ "github.com/aws/aws-cdk-go/awscdk/v2"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awsecrassets"
+ "github.com/aws/aws-cdk-go/awscdk/v2/awsecs"
+)
+
+
+dirName, err := os.Getwd()
+if err != nil {
+ panic(err)
+}
+
+asset := awsecrassets.NewDockerImageAsset(stack, jsii.String("MyImage"), &awsecrassets.DockerImageAssetProps{
+ Directory: jsii.String(path.Join(dirName, "demo-image")),
+})
+
+taskDefinition := awsecs.NewFargateTaskDefinition(stack, jsii.String("TaskDef"), &awsecs.FargateTaskDefinitionProps{
+ MemoryLimitMiB: jsii.Number(1024),
+ Cpu: jsii.Number(512),
+})
+
+taskDefinition.AddContainer(jsii.String("MyOtherContainer"), &awsecs.ContainerDefinitionOptions{
+ Image: awsecs.ContainerImage_FromEcrRepository(asset.Repository(), asset.ImageTag()),
+})
+```
+
+---
### Build arguments example
You can provide customized build arguments for the Docker build step through the `buildArgs` \(Python: `build_args`\) property option when the AWS CDK CLI builds the image during deployment\.
-------
+---
+
#### [ TypeScript ]
```
@@ -845,7 +1096,8 @@ const asset = new DockerImageAsset(this, 'MyBuildImage', {
});
```
-------
+---
+
#### [ JavaScript ]
```
@@ -857,7 +1109,8 @@ const asset = new DockerImageAsset(this, 'MyBuildImage', {
});
```
-------
+---
+
#### [ Python ]
```
@@ -866,7 +1119,8 @@ asset = DockerImageAsset(self, "MyBulidImage",
build_args=dict(HTTP_PROXY="http://10.20.30.2:1234"))
```
-------
+---
+
#### [ Java ]
```
@@ -877,7 +1131,8 @@ DockerImageAsset asset = DockerImageAsset.Builder.create(this, "my-image"),
.build();
```
-------
+---
+
#### [ C\# ]
```
@@ -890,13 +1145,31 @@ var asset = new DockerImageAsset(this, "MyBuildImage", new DockerImageAssetProps
});
```
-------
+---
+
+#### [ Go ]
+
+```
+dirName, err := os.Getwd()
+if err != nil {
+ panic(err)
+}
+
+asset := awsecrassets.NewDockerImageAsset(stack, jsii.String("MyBuildImage"), &awsecrassets.DockerImageAssetProps{
+ Directory: jsii.String(path.Join(dirName, "my-image")),
+ BuildArgs: &map[string]*string{
+ "HTTP_PROXY": jsii.String("http://10.20.30.2:1234"),
+ },
+})
+```
+
+---
### Permissions
-If you use a module that supports Docker image assets, such as [aws\-ecs](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs-readme.html), the AWS CDK manages permissions for you when you use assets directly or through [ContainerImage\.fromEcrRepository](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerImage.html#static-fromwbrecrwbrrepositoryrepository-tag) \(Python: `from_ecr_repository`\)\. If you use Docker image assets directly, make sure that the consuming principal has permissions to pull the image\.
+If you use a module that supports Docker image assets, such as [aws\-ecs](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs-readme.html), the AWS CDK manages permissions for you when you use assets directly or through [ContainerImage\.fromEcrRepository](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerImage.html#static-fromwbrecrwbrrepositoryrepository-tag) \(Python: `from_ecr_repository`\)\. If you use Docker image assets directly, make sure that the consuming principal has permissions to pull the image\.
-In most cases, you should use [asset\.repository\.grantPull](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr.Repository.html#grantwbrpullgrantee) method \(Python: `grant_pull`\. This modifies the IAM policy of the principal to enable it to pull images from this repository\. If the principal that is pulling the image is not in the same account, or if it's an AWS service that doesn't assume a role in your account \(such as AWS CodeBuild\), you must grant pull permissions on the resource policy and not on the principal's policy\. Use the [asset\.repository\.addToResourcePolicy](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr.Repository.html#addwbrtowbrresourcewbrpolicystatement) method \(Python: `add_to_resource_policy`\) to grant the appropriate principal permissions\.
+In most cases, you should use [asset\.repository\.grantPull](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr.Repository.html#grantwbrpullgrantee) method \(Python: `grant_pull`\. This modifies the IAM policy of the principal to enable it to pull images from this repository\. If the principal that is pulling the image is not in the same account, or if it's an AWS service that doesn't assume a role in your account \(such as AWS CodeBuild\), you must grant pull permissions on the resource policy and not on the principal's policy\. Use the [asset\.repository\.addToResourcePolicy](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr.Repository.html#addwbrtowbrresourcewbrpolicystatement) method \(Python: `add_to_resource_policy`\) to grant the appropriate principal permissions\.
## AWS CloudFormation resource metadata
@@ -904,9 +1177,10 @@ In most cases, you should use [asset\.repository\.grantPull](https://docs.aws.am
This section is relevant only for construct authors\. In certain situations, tools need to know that a certain CFN resource is using a local asset\. For example, you can use the AWS SAM CLI to invoke Lambda functions locally for debugging purposes\. See [AWS SAM integration](sam.md) for details\.
To enable such use cases, external tools consult a set of metadata entries on AWS CloudFormation resources:
-+ `aws:asset:path` – Points to the local path of the asset\.
-+ `aws:asset:property` – The name of the resource property where the asset is used\.
+
+- `aws:asset:path` – Points to the local path of the asset\.
+- `aws:asset:property` – The name of the resource property where the asset is used\.
Using these two metadata entries, tools can identify that assets are used by a certain resource, and enable advanced local experiences\.
-To add these metadata entries to a resource, use the `asset.addResourceMetadata` \(Python: `add_resource_metadata`\) method\.
\ No newline at end of file
+To add these metadata entries to a resource, use the `asset.addResourceMetadata` \(Python: `add_resource_metadata`\) method\.