Skip to content

Instantly share code, notes, and snippets.

@rdsedmundo
Last active April 26, 2022 17:56
Show Gist options
  • Save rdsedmundo/8ba233fd7eb5ad2b465232ceea706d63 to your computer and use it in GitHub Desktop.
Save rdsedmundo/8ba233fd7eb5ad2b465232ceea706d63 to your computer and use it in GitHub Desktop.
cloudtrail
# https://aws.amazon.com/premiumsupport/knowledge-center/troubleshoot-iam-permission-errors/
( echo "Time,Identity ARN,Event ID,Service,Action,Error,Message";
aws cloudtrail lookup-events --start-time "2020-01-01T00:00:00Z" --end-time "2020-01-01T23:59:59Z" --query "Events[*].CloudTrailEvent" --output text \
| jq -r ". | select(.userIdentity.arn == \"your-arn\" and .eventType == \"AwsApiCall\" and .errorCode != null
and (.errorCode | ascii_downcase | (contains(\"accessdenied\") or contains(\"unauthorized\"))))
| [.eventTime, .userIdentity.arn, .eventID, .eventSource, .eventName, .errorCode, .errorMessage] | @csv"
) | column -t -s'",'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment