Is there any way to record username while creating a new resource in AWS? For instance, if we want to check sometime later that who created a particular resource, can we save it or track it somewhere whilst creation itself.
Question posted in Amazon Web Sevices
The official Amazon Web Services documentation can be found here.
The official Amazon Web Services documentation can be found here.
2
Answers
When AWS receive an API call that requests a resource to be created, it verifies that the credentials are associated with an IAM User or IAM Role that has permission to create the resource.
If they have the appropriate permissions, then the resource is created in the AWS Account associated with those credentials.
However, information about the ‘user’ who requested the resource is not stored against the resource.
Historical information about who issued the API request is available from AWS Config, including the identity that sent the API call, time, parameters and whether it was successful. This is the only true way to know which identity created the resource. (I say ‘identity’ because it might be an IAM User, an IAM Role or even temporary credentials generated via AWS Security Token Service.)
If you want to store information about the user directly on the resource that was created, you would need a process that stores that information in a Tag associated with the resource. Some AWS services allow you to specify a tag in the same API call that created the resource, while other services would require you to tag the resource after the resource has been created. It is sometimes possible to write IAM policies that require a tag to be specified when the resource is created, but this does not apply to all AWS services.
you can build athena query on top of cloudtrail to get the required details of API calls.
pre-requisites:
more details can be found at:
https://docs.aws.amazon.com/athena/latest/ug/cloudtrail-logs.html
sample query to know who created ec2 instance: