AWS cdk 如何在 c# 中标记资源?
AWS cdk how to tag resources in c#?
我试图让标签在 C# AWS CDK 项目中工作,但除了 Depreciated 语法之外,我似乎无法让任何东西工作。例如在下面的代码中:
using Amazon.CDK;
using Amazon.CDK.AWS.S3;
namespace HelloCdk
{
public class HelloCdkStack : Stack
{
internal HelloCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
{
// The code that defines your stack goes here
var g_bucket = new Bucket(this, "GameContent", new BucketProps
{
Versioned = false,
PublicReadAccess = true,
AutoDeleteObjects = true, //delete and
RemovalPolicy = RemovalPolicy.DESTROY, //destroy bucket when CF Stack deleted.
WebsiteIndexDocument = "index.html",
WebsiteErrorDocument = "index.html"
});
Tag.Add(g_bucket, "key", "value");
}
}
}
当我发出 cdk synth
命令时,上面的代码将会成功。但是,我收到一条警告消息:
warning CS0618: 'Tag.Add(Construct, string, string, ITagProps?)' is obsolete: 'use "Tags.of(scope).add()"'
但是,当我尝试使用“Tags.of...”时,cdk synth
命令会抛出以下错误:
error CS1061: 'TagManager' does not contain a definition for 'of' and no accessible extension method 'of'...
我需要更改什么才能使推荐的标记方法起作用?
带有 Tags.of
的源代码不应编译,因为没有为 .NET 定义这样的方法。
文档指定 Tags.Of
- https://docs.aws.amazon.com/cdk/latest/guide/tagging.html
Tags.Of(myConstruct).Add("key", "value");
(!) 请注意,堆栈对象具有标签 属性,因此请确保您不访问堆栈的标签 属性,而是访问标签 class.
我试图让标签在 C# AWS CDK 项目中工作,但除了 Depreciated 语法之外,我似乎无法让任何东西工作。例如在下面的代码中:
using Amazon.CDK;
using Amazon.CDK.AWS.S3;
namespace HelloCdk
{
public class HelloCdkStack : Stack
{
internal HelloCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
{
// The code that defines your stack goes here
var g_bucket = new Bucket(this, "GameContent", new BucketProps
{
Versioned = false,
PublicReadAccess = true,
AutoDeleteObjects = true, //delete and
RemovalPolicy = RemovalPolicy.DESTROY, //destroy bucket when CF Stack deleted.
WebsiteIndexDocument = "index.html",
WebsiteErrorDocument = "index.html"
});
Tag.Add(g_bucket, "key", "value");
}
}
}
当我发出 cdk synth
命令时,上面的代码将会成功。但是,我收到一条警告消息:
warning CS0618: 'Tag.Add(Construct, string, string, ITagProps?)' is obsolete: 'use "Tags.of(scope).add()"'
但是,当我尝试使用“Tags.of...”时,cdk synth
命令会抛出以下错误:
error CS1061: 'TagManager' does not contain a definition for 'of' and no accessible extension method 'of'...
我需要更改什么才能使推荐的标记方法起作用?
带有 Tags.of
的源代码不应编译,因为没有为 .NET 定义这样的方法。
文档指定 Tags.Of
- https://docs.aws.amazon.com/cdk/latest/guide/tagging.html
Tags.Of(myConstruct).Add("key", "value");
(!) 请注意,堆栈对象具有标签 属性,因此请确保您不访问堆栈的标签 属性,而是访问标签 class.