Who created this AWS resource? Finding the owner with tags and CloudTrail
Every AWS account has resources nobody remembers making. Before you delete one, or chase a security risk, you need to know who made it and whether they still need it. AWS records the answer in two places: tags, if someon
Every AWS account has resources nobody remembers making. Before you delete one, or chase a security risk, you need to know who made it and whether they still need it. AWS records the answer in two places: tags, if someone added them, and CloudTrail.
1. Look at the tags
If your team tags resources with Owner, CreatedBy, Contact or Team, that's the quickest answer. Tag Editor (in Resource Groups) searches every region at once. From the command line, this lists everything in a region with an Owner tag:
aws resourcegroupstaggingapi get-resources --tag-filters Key=Owner \
--query 'ResourceTagMappingList[].[ResourceARN,Tags[?Key==`Owner`].Value|[0]]' --output table
Resources made by CloudFormation carry aws:cloudformation:stack-name, which tells you which stack, and so usually which team.
2. Search CloudTrail for the create event
CloudTrail's event history keeps the last 90 days of management events in each region, free and on in every account. Search it in the region the resource lives in:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=ResourceName,AttributeValue=vol-0123456789abcdef0 \
--query 'Events[].[EventName,Username,EventTime]' --output table
Look for the create event: RunInstances, CreateVolume, CreateLoadBalancer, CreateBucket and so on. Global services such as IAM log to us-east-1. The person shows up as:
- An IAM user: the user name.
- IAM Identity Center (SSO): an assumed role whose session name is their Identity Center user name, often their email address.
- A pipeline or service role: the role name. Then the question is who runs that pipeline, and its commit history usually says.
3. Older than 90 days?
If your organisation has a CloudTrail trail delivering to S3, the older events are there and Athena can search them. Without a trail, an untagged resource older than 90 days has no recorded creator. Then ask: post what it is, where it is and what it costs in your team's channel, and set a date after which it goes if nobody claims it.
4. Make the next one easy
-
Tag on creation:
default_tagsin the Terraform AWS provider, or tags on the CloudFormation stack. -
Require the tag: a tag policy in AWS Organizations, or the AWS Config rule
required-tags. - Keep a trail: a CloudTrail trail to S3 means "who made this?" can always be answered.
The full guide is at getstrays.com/guides/find-aws-resource-owner. costwatch, a free open-source scanner, does the lookup for everything it finds with --owners.
Disclosure: I built Strays, a read-only tool that does this every week and asks each owner in Slack or Teams.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.