Skip to content

Create example of getting a reference to a resource by tag value #45

Open
@Doug-AWS

Description

@Doug-AWS

Replaces this issue created by Doug-AWS on Mar 11 in the CDK repo: aws/aws-cdk#1990.

Original description:

User wrote:

I'm trying to get a subnetId with a tag (actually the tag is applied by creation through CDK, so it's especially troublesome to not be able to find this).

In this example, you show how to apply a tag, but not how to find a resource with a Tag. Presently, I need to replace something like the following in the AWS SDK:

Filter filter = new Filter().withName("vpc-id").withValues(vpcId).withName("tag:Name").withValues("infraStack/CodeBuild VPC/PrivateSubnet1");

DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest().withFilters(filter);

String subnetId = null;

try {
subnetId = getClient().describeSubnets(describeSubnetsRequest).getSubnets().iterator().next().getSubnetId();

Right now CDK doesn't necessarily have API or user guide documentation on how to do this--or I'm not finding it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2The issue should be resolved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions