Skip to content

create_resource_policy_statement

create_resource_policy_statement(
    resource_arn: AmazonResourceName,
    statement_id: Name,
    effect: Effect,
    principal: PrincipalList,
    action: OperationList,
    *,
    config_overrides: Optional[LexModelsV2ClientConfig] = None,
    condition: Optional[ConditionMap] = None,
    expected_revision_id: Optional[RevisionId] = None,
) -> CreateResourcePolicyStatementResponse

Adds a new resource policy statement to a bot or bot alias. If a resource policy exists, the statement is added to the current resource policy. If a policy doesn't exist, a new policy is created.

You can't create a resource policy statement that allows cross-account access.

You need to add the CreateResourcePolicy or UpdateResourcePolicy action to the bot role in order to call the API.

Parameters:

  • resource_arn (AmazonResourceName) –

    The Amazon Resource Name (ARN) of the bot or bot alias that the resource policy is attached to.

  • statement_id (Name) –

    The name of the statement. The ID is the same as the Sid IAM property. The statement name must be unique within the policy. For more information, see IAM JSON policy elements: Sid.

  • effect (Effect) –

    Determines whether the statement allows or denies access to the resource.

  • principal (PrincipalList) –

    An IAM principal, such as an IAM user, IAM role, or Amazon Web Services services that is allowed or denied access to a resource. For more information, see Amazon Web Services JSON policy elements: Principal.

  • action (OperationList) –

    The Amazon Lex action that this policy either allows or denies. The action must apply to the resource type of the specified ARN. For more information, see Actions, resources, and condition keys for Amazon Lex V2.

  • condition (Optional[ConditionMap], default: None ) –

    Specifies a condition when the policy is in effect. If the principal of the policy is a service principal, you must provide two condition blocks, one with a SourceAccount global condition key and one with a SourceArn global condition key.

    For more information, see IAM JSON policy elements: Condition .

  • expected_revision_id (Optional[RevisionId], default: None ) –

    The identifier of the revision of the policy to edit. If this revision ID doesn't match the current revision ID, Amazon Lex throws an exception.

    If you don't specify a revision, Amazon Lex overwrites the contents of the policy with the new values.

Raises:

  • ConflictException –

    The action that you tried to perform couldn't be completed because the resource is in a conflicting state. For example, deleting a bot that is in the CREATING state. Try your request again.

  • InternalServerException –

    The service encountered an unexpected condition. Try your request again.

  • PreconditionFailedException –

    Your request couldn't be completed because one or more request fields aren't valid. Check the fields in your request and try again.

  • ResourceNotFoundException –

    You asked to describe a resource that doesn't exist. Check the resource that you are requesting and try again.

  • ServiceQuotaExceededException –

    You have reached a quota for your bot.

  • ThrottlingException –

    Your request rate is too high. Reduce the frequency of requests.

  • ValidationException –

    One of the input parameters in your request isn't valid. Check the parameters and try your request again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_lex_models_v2/_services/lex_models_v2.py
def create_resource_policy_statement(
    self,
    resource_arn: "capo_lex_models_v2.types.amazon_resource_name.AmazonResourceName",
    statement_id: "capo_lex_models_v2.types.name.Name",
    effect: "capo_lex_models_v2.types.effect.Effect",
    principal: "capo_lex_models_v2.types.principal_list.PrincipalList",
    action: "capo_lex_models_v2.types.operation_list.OperationList",
    *,
    config_overrides: Optional[LexModelsV2ClientConfig] = None,
    condition: Optional[
        "capo_lex_models_v2.types.condition_map.ConditionMap"
    ] = None,
    expected_revision_id: Optional[
        "capo_lex_models_v2.types.revision_id.RevisionId"
    ] = None,
) -> "capo_lex_models_v2.types.create_resource_policy_statement_response.CreateResourcePolicyStatementResponse":
    """<p>Adds a new resource policy statement to a bot or bot alias. If a resource policy exists, the statement is added to the current resource policy. If a policy doesn't exist, a new policy is created.</p> <p>You can't create a resource policy statement that allows cross-account access.</p> <p>You need to add the <code>CreateResourcePolicy</code> or <code>UpdateResourcePolicy</code> action to the bot role in order to call the API.</p>

    Args:
        resource_arn: <p>The Amazon Resource Name (ARN) of the bot or bot alias that the resource policy is attached to.</p>
        statement_id: <p>The name of the statement. The ID is the same as the <code>Sid</code> IAM property. The statement name must be unique within the policy. For more information, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_sid.html">IAM JSON policy elements: Sid</a>. </p>
        effect: <p>Determines whether the statement allows or denies access to the resource.</p>
        principal: <p>An IAM principal, such as an IAM user, IAM role, or Amazon Web Services services that is allowed or denied access to a resource. For more information, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html">Amazon Web Services JSON policy elements: Principal</a>.</p>
        action: <p>The Amazon Lex action that this policy either allows or denies. The action must apply to the resource type of the specified ARN. For more information, see <a href="https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonlexv2.html"> Actions, resources, and condition keys for Amazon Lex V2</a>.</p>
        condition: <p>Specifies a condition when the policy is in effect. If the principal of the policy is a service principal, you must provide two condition blocks, one with a SourceAccount global condition key and one with a SourceArn global condition key.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html">IAM JSON policy elements: Condition </a>.</p>
        expected_revision_id: <p>The identifier of the revision of the policy to edit. If this revision ID doesn't match the current revision ID, Amazon Lex throws an exception.</p> <p>If you don't specify a revision, Amazon Lex overwrites the contents of the policy with the new values.</p>

    Raises:
        capo_lex_models_v2.errors.conflict_exception.ConflictException: <p>The action that you tried to perform couldn't be completed because the resource is in a conflicting state. For example, deleting a bot that is in the CREATING state. Try your request again. </p>
        capo_lex_models_v2.errors.internal_server_exception.InternalServerException: <p>The service encountered an unexpected condition. Try your request again.</p>
        capo_lex_models_v2.errors.precondition_failed_exception.PreconditionFailedException: <p>Your request couldn't be completed because one or more request fields aren't valid. Check the fields in your request and try again.</p>
        capo_lex_models_v2.errors.resource_not_found_exception.ResourceNotFoundException: <p>You asked to describe a resource that doesn't exist. Check the resource that you are requesting and try again.</p>
        capo_lex_models_v2.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>You have reached a quota for your bot. </p>
        capo_lex_models_v2.errors.throttling_exception.ThrottlingException: <p>Your request rate is too high. Reduce the frequency of requests.</p>
        capo_lex_models_v2.errors.validation_exception.ValidationException: <p>One of the input parameters in your request isn't valid. Check the parameters and try your request again.</p>
        capo_lex_models_v2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_lex_models_v2.types.create_resource_policy_statement_request.CreateResourcePolicyStatementRequest]",
    ) -> OperationResponse[
        "capo_lex_models_v2.types.create_resource_policy_statement_response.CreateResourcePolicyStatementResponse"
    ]:
        import capo_lex_models_v2._operations.lex_model_building_service_v2.create_resource_policy_statement

        output, http_response = (
            capo_lex_models_v2._operations.lex_model_building_service_v2.create_resource_policy_statement.create_resource_policy_statement(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateResourcePolicyStatement")
    )
    input_: capo_lex_models_v2.types.create_resource_policy_statement_request.CreateResourcePolicyStatementRequest = {
        "resource_arn": resource_arn,
        "statement_id": statement_id,
        "effect": effect,
        "principal": principal,
        "action": action,
    }
    if condition is not None:
        input_["condition"] = condition
    if expected_revision_id is not None:
        input_["expected_revision_id"] = expected_revision_id

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output