Note:

You are viewing the documentation for an older major version of the AWS CLI (version 1).

AWS CLI version 2, the latest major version of AWS CLI, is now stable and recommended for general use. To view this page for the AWS CLI version 2, click here. For more information see the AWS CLI version 2 installation instructions and migration guide.

[ aws . verifiedpermissions ]

create-policy

Description

Creates a Cedar policy and saves it in the specified policy store. You can create either a static policy or a policy linked to a policy template.

  • To create a static policy, provide the Cedar policy text in the StaticPolicy section of the PolicyDefinition .
  • To create a policy that is dynamically linked to a policy template, specify the policy template ID and the principal and resource to associate with this policy in the templateLinked section of the PolicyDefinition . If the policy template is ever updated, any policies linked to the policy template automatically use the updated template.

Note

Creating a policy causes it to be validated against the schema in the policy store. If the policy doesn't pass validation, the operation fails and the policy isn't stored.

Note

Verified Permissions is * eventually consistent * . It can take a few seconds for a new or changed element to propagate through the service and be visible in the results of other Verified Permissions operations.

See also: AWS API Documentation

Synopsis

  create-policy
[--client-token <value>]
--policy-store-id <value>
--definition <value>
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
[--debug]
[--endpoint-url <value>]
[--no-verify-ssl]
[--no-paginate]
[--output <value>]
[--query <value>]
[--profile <value>]
[--region <value>]
[--version <value>]
[--color <value>]
[--no-sign-request]
[--ca-bundle <value>]
[--cli-read-timeout <value>]
[--cli-connect-timeout <value>]

Options

--client-token (string)

Specifies a unique, case-sensitive ID that you provide to ensure the idempotency of the request. This lets you safely retry the request without accidentally performing the same operation a second time. Passing the same value to a later call to an operation requires that you also pass the same value for all other parameters. We recommend that you use a UUID type of value. .

If you don't provide this value, then Amazon Web Services generates a random one for you.

If you retry the operation with the same ClientToken , but with different parameters, the retry fails with an ConflictException error.

Verified Permissions recognizes a ClientToken for eight hours. After eight hours, the next request with the same parameters performs the operation again regardless of the value of ClientToken .

--policy-store-id (string)

Specifies the PolicyStoreId of the policy store you want to store the policy in.

--definition (tagged union structure)

A structure that specifies the policy type and content to use for the new policy. You must include either a static or a templateLinked element. The policy content must be written in the Cedar policy language.

Note

This is a Tagged Union structure. Only one of the following top level keys can be set: static, templateLinked.

static -> (structure)

A structure that describes a static policy. An static policy doesn't use a template or allow placeholders for entities.

description -> (string)

The description of the static policy.

statement -> (string)

The policy content of the static policy, written in the Cedar policy language.

templateLinked -> (structure)

A structure that describes a policy that was instantiated from a template. The template can specify placeholders for principal and resource . When you use CreatePolicy to create a policy from a template, you specify the exact principal and resource to use for the instantiated policy.

policyTemplateId -> (string)

The unique identifier of the policy template used to create this policy.

principal -> (structure)

The principal associated with this template-linked policy. Verified Permissions substitutes this principal for the ?principal placeholder in the policy template when it evaluates an authorization request.

entityType -> (string)

The type of an entity.

Example: "entityType":"*typeName* "

entityId -> (string)

The identifier of an entity.

"entityId":"*identifier* "

resource -> (structure)

The resource associated with this template-linked policy. Verified Permissions substitutes this resource for the ?resource placeholder in the policy template when it evaluates an authorization request.

entityType -> (string)

The type of an entity.

Example: "entityType":"*typeName* "

entityId -> (string)

The identifier of an entity.

"entityId":"*identifier* "

Shorthand Syntax:

static={description=string,statement=string},templateLinked={policyTemplateId=string,principal={entityType=string,entityId=string},resource={entityType=string,entityId=string}}

JSON Syntax:

{
  "static": {
    "description": "string",
    "statement": "string"
  },
  "templateLinked": {
    "policyTemplateId": "string",
    "principal": {
      "entityType": "string",
      "entityId": "string"
    },
    "resource": {
      "entityType": "string",
      "entityId": "string"
    }
  }
}

--cli-input-json (string) Performs service operation based on the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton. If other arguments are provided on the command line, the CLI values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally.

--generate-cli-skeleton (string) Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.

Global Options

--debug (boolean)

Turn on debug logging.

--endpoint-url (string)

Override command's default URL with the given URL.

--no-verify-ssl (boolean)

By default, the AWS CLI uses SSL when communicating with AWS services. For each SSL connection, the AWS CLI will verify SSL certificates. This option overrides the default behavior of verifying SSL certificates.

--no-paginate (boolean)

Disable automatic pagination.

--output (string)

The formatting style for command output.

  • json
  • text
  • table

--query (string)

A JMESPath query to use in filtering the response data.

--profile (string)

Use a specific profile from your credential file.

--region (string)

The region to use. Overrides config/env settings.

--version (string)

Display the version of this tool.

--color (string)

Turn on/off color output.

  • on
  • off
  • auto

--no-sign-request (boolean)

Do not sign requests. Credentials will not be loaded if this argument is provided.

--ca-bundle (string)

The CA certificate bundle to use when verifying SSL certificates. Overrides config/env settings.

--cli-read-timeout (int)

The maximum socket read time in seconds. If the value is set to 0, the socket read will be blocking and not timeout. The default value is 60 seconds.

--cli-connect-timeout (int)

The maximum socket connect time in seconds. If the value is set to 0, the socket connect will be blocking and not timeout. The default value is 60 seconds.

Examples

Note

To use the following examples, you must have the AWS CLI installed and configured. See the Getting started guide in the AWS CLI User Guide for more information.

Unless otherwise stated, all examples have unix-like quotation rules. These examples will need to be adapted to your terminal's quoting rules. See Using quotation marks with strings in the AWS CLI User Guide .

Example 1: To create a static policy

The following create-policy example creates a static policy with a policy scope that specifies both a principal and a resource.

aws verifiedpermissions create-policy \
    --definition file://definition1.txt \
    --policy-store-id PSEXAMPLEabcdefg111111

Contents of file definition1.txt:

{
    "static": {
        "description":  "Grant everyone of janeFriends UserGroup access to the vacationFolder Album",
        "statement": "permit(principal in UserGroup::\"janeFriends\", action, resource in Album::\"vacationFolder\" );"
    }
}

Output:

{
    "createdDate": "2023-06-12T20:33:37.382907+00:00",
    "lastUpdatedDate": "2023-06-12T20:33:37.382907+00:00",
    "policyId": "SPEXAMPLEabcdefg111111",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyType": "STATIC",
    "principal": {
        "entityId": "janeFriends",
        "entityType": "UserGroup"
    },
    "resource": {
        "entityId": "vacationFolder",
        "entityType": "Album"
    }
}

Example 2: To create a static policy that grants access to a resource to everyone

The following create-policy example creates a static policy with a policy scope that specifies only a resource.

aws verifiedpermissions create-policy \
    --definition file://definition2.txt \
    --policy-store-id PSEXAMPLEabcdefg111111

Contents of file definition2.txt:

{
    "static": {
        "description":  "Grant everyone access to the publicFolder Album",
        "statement": "permit(principal, action, resource in Album::\"publicFolder\");"
    }
}

Output:

{
    "createdDate": "2023-06-12T20:39:44.975897+00:00",
    "lastUpdatedDate": "2023-06-12T20:39:44.975897+00:00",
    "policyId": "PbfR73F8oh5MMfr9uRtFDB",
    "policyStoreId": "PSEXAMPLEabcdefg222222",
    "policyType": "STATIC",
    "resource": {
        "entityId": "publicFolder",
        "entityType": "Album"
    }
}

Example 3: To create a template-linked policy that is associated with the specified template

The following create-policy example creates a template-linked policy using the specified policy template and associates the specified principal to use with the new template-linked policy.

aws verifiedpermissions create-policy \
    --definition file://definition.txt \
    --policy-store-id PSEXAMPLEabcdefg111111

Contents of definition.txt:

{
    "templateLinked": {
        "policyTemplateId": "PTEXAMPLEabcdefg111111",
        "principal": {
            "entityType": "User",
            "entityId": "alice"
        }
    }
}

Output:

{
    "createdDate": "2023-06-12T20:49:51.490211+00:00",
    "lastUpdatedDate": "2023-06-12T20:49:51.490211+00:00",
    "policyId": "TPEXAMPLEabcdefg111111",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyType": "TEMPLATE_LINKED",
    "principal": {
        "entityId": "alice",
        "entityType": "User"
    },
    "resource": {
        "entityId": "VacationPhoto94.jpg",
        "entityType": "Photo"
    }
}

For more information about policies, see Amazon Verified Permissions policies in the Amazon Verified Permissions User Guide.

Output

policyStoreId -> (string)

The ID of the policy store that contains the new policy.

policyId -> (string)

The unique ID of the new policy.

policyType -> (string)

The policy type of the new policy.

principal -> (structure)

The principal specified in the new policy's scope. This response element isn't present when principal isn't specified in the policy content.

entityType -> (string)

The type of an entity.

Example: "entityType":"*typeName* "

entityId -> (string)

The identifier of an entity.

"entityId":"*identifier* "

resource -> (structure)

The resource specified in the new policy's scope. This response element isn't present when the resource isn't specified in the policy content.

entityType -> (string)

The type of an entity.

Example: "entityType":"*typeName* "

entityId -> (string)

The identifier of an entity.

"entityId":"*identifier* "

actions -> (list)

The action that a policy permits or forbids. For example, {"actions": [{"actionId": "ViewPhoto", "actionType": "PhotoFlash::Action"}, {"entityID": "SharePhoto", "entityType": "PhotoFlash::Action"}]} .

(structure)

Contains information about an action for a request for which an authorization decision is made.

This data type is used as a request parameter to the IsAuthorized , BatchIsAuthorized , and IsAuthorizedWithToken operations.

Example: { "actionId": "<action name>", "actionType": "Action" }

actionType -> (string)

The type of an action.

actionId -> (string)

The ID of an action.

createdDate -> (timestamp)

The date and time the policy was originally created.

lastUpdatedDate -> (timestamp)

The date and time the policy was last updated.

effect -> (string)

The effect of the decision that a policy returns to an authorization request. For example, "effect": "Permit" .