The following code examples show how to use GetContextKeysForPrincipalPolicy
.
- AWS CLI
-
To list the context keys referenced by all policies associated with an IAM principal
The following
get-context-keys-for-principal-policy
command retrieves all policies that are attached to the usersaanvi
and any groups she is a member of. It then parses each and lists the context keys used by those policies. Use this command to identify which context key values you must supply to successfully use thesimulate-custom-policy
andsimulate-principal-policy
commands. You can also retrieve the list of context keys used by an arbitrary JSON policy by using theget-context-keys-for-custom-policy
command.aws iam get-context-keys-for-principal-policy \ --policy-source-arn
arn:aws:iam::123456789012:user/saanvi
Output:
{ "ContextKeyNames": [ "aws:username", "aws:CurrentTime" ] }
For more information, see Using the IAM Policy Simulator (AWS CLI and AWS API) in the AWS IAM User Guide.
-
For API details, see GetContextKeysForPrincipalPolicy
in AWS CLI Command Reference.
-
For a complete list of AWS SDK developer guides and code examples, see Using this service with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.