尝试在运行时检索我的Amazon EC2实例上设置的标签

发布于 2025-02-10 12:32:43 字数 848 浏览 0 评论 0原文

我有一个AWS Workspace EC2实例,上面设置了一些标签。我可以在AWS工作区控制台中清楚地看到标签名称及其值。我想在.NET中的实例上在运行时检索标签及其值。我找到了这篇文章,但是已经7岁了,非常过时。 https://gist.github.com/github.com/gortok/690899999999999db5fe293eec5

执行此操作的代码示例?谁能将我指向包括需要什么的正确Nuget软件包?我已经在下面包含有关其他各种AWS服务的包装参考。

    <PackageReference Include="AWSSDK.CloudFront" Version="3.7.3.10" />
    <PackageReference Include="AWSSDK.Core" Version="3.7.12.3" />
    <PackageReference Include="AWSSDK.EC2" Version="3.7.75.1" />
    <PackageReference Include="AWSSDK.S3" Version="3.7.1.19" />
    <PackageReference Include="AWSSDK.SimpleSystemsManagement" Version="3.7.5.2" />
    <PackageReference Include="AWSSDK.SQS" Version="3.7.0.48" />

I have an AWS Workspace EC2 instance that has a few tags set on it. I can clearly see the tag names and their values in the AWS Workspaces console. I would like to retrieve the tags and their values at runtime on the instance in .NET. I found this article, but it is 7 years old and very out of date. https://gist.github.com/gortok/6908999db5fe293eec5c

Can anybody help me find a modern code example for doing this? Can anyone point me at the correct NuGet package that includes what is needed? I already include the package references below for various other AWS services.

    <PackageReference Include="AWSSDK.CloudFront" Version="3.7.3.10" />
    <PackageReference Include="AWSSDK.Core" Version="3.7.12.3" />
    <PackageReference Include="AWSSDK.EC2" Version="3.7.75.1" />
    <PackageReference Include="AWSSDK.S3" Version="3.7.1.19" />
    <PackageReference Include="AWSSDK.SimpleSystemsManagement" Version="3.7.5.2" />
    <PackageReference Include="AWSSDK.SQS" Version="3.7.0.48" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画离情绘悲伤 2025-02-17 12:32:43

为了在.NET中的EC2实例上描述您的标签,您可以使用 amazonec2client.describetags 是.net v3 的 aws sdk的一部分(您引用的代码示例是.NET EC2 SDK的较旧版本)。

代码是:

var client = new AmazonEC2Client();
var response = client.DescribeTags(new DescribeTagsRequest 
{
    Filters = new List<Filter> {
        new Filter {
            Name = "resource-id",
            Values = new List<string> {
                "i-1234567890abcdef8"
            }
        }
    }
});

List<TagDescription> tags = response.Tags;

如果您不熟悉此SDK,请参考.NET开发人员指南 AWS SDK

.net aws sdk是什么a>

有关此服务包装的信息,请参见:

与亚马逊EC2合作

To describe your tags on an EC2 instance in .NET, you can use the AmazonEC2Client.DescribeTags method that is part of the AWS SDK for .NET v3 (the code example you referenced is an older version of the .NET EC2 SDK).

Code is:

var client = new AmazonEC2Client();
var response = client.DescribeTags(new DescribeTagsRequest 
{
    Filters = new List<Filter> {
        new Filter {
            Name = "resource-id",
            Values = new List<string> {
                "i-1234567890abcdef8"
            }
        }
    }
});

List<TagDescription> tags = response.Tags;

If you are not familiar with this SDK, please reference the AWS SDK for .NET Developer Guide.

What is the AWS SDK for .NET

Information about the packages for this service can be found here:

Working with Amazon EC2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文