Skip to content

create_constraint

create_constraint(
    portfolio_id: Id,
    product_id: Id,
    parameters: ConstraintParameters,
    type: ConstraintType,
    idempotency_token: IdempotencyToken,
    *,
    config_overrides: Optional[ServiceCatalogClientConfig] = None,
    accept_language: Optional[AcceptLanguage] = None,
    description: Optional[ConstraintDescription] = None,
) -> CreateConstraintOutput

Creates a constraint.

A delegated admin is authorized to invoke this command.

Parameters:

  • accept_language (Optional[AcceptLanguage], default: None ) –

    The language code.

    • jp - Japanese

    • zh - Chinese

  • portfolio_id (Id) –

    The portfolio identifier.

  • product_id (Id) –

    The product identifier.

  • parameters (ConstraintParameters) –

    The constraint parameters, in JSON format. The syntax depends on the constraint type as follows:

    LAUNCH

    You are required to specify either the RoleArn or the LocalRoleName but can't use both.

    Specify the RoleArn property as follows:

    {"RoleArn" : "arn:aws:iam::123456789012:role/LaunchRole"}

    Specify the LocalRoleName property as follows:

    {"LocalRoleName": "SCBasicLaunchRole"}

    If you specify the LocalRoleName property, when an account uses the launch constraint, the IAM role with that name in the account will be used. This allows launch-role constraints to be account-agnostic so the administrator can create fewer resources per shared account.

    The given role name must exist in the account used to create the launch constraint and the account of the user who launches a product with this launch constraint.

    You cannot have both a LAUNCH and a STACKSET constraint.

    You also cannot have more than one LAUNCH constraint on a product and portfolio.

    NOTIFICATION

    Specify the NotificationArns property as follows:

    {"NotificationArns" : ["arn:aws:sns:us-east-1:123456789012:Topic"]}

    RESOURCE_UPDATE

    Specify the TagUpdatesOnProvisionedProduct property as follows:

    {"Version":"2.0","Properties":{"TagUpdateOnProvisionedProduct":"String"}}

    The TagUpdatesOnProvisionedProduct property accepts a string value of ALLOWED or NOT_ALLOWED.

    STACKSET

    Specify the Parameters property as follows:

    {"Version": "String", "Properties": {"AccountList": [ "String" ], "RegionList": [ "String" ], "AdminRole": "String", "ExecutionRole": "String"}}

    You cannot have both a LAUNCH and a STACKSET constraint.

    You also cannot have more than one STACKSET constraint on a product and portfolio.

    Products with a STACKSET constraint will launch an CloudFormation stack set.

    TEMPLATE

    Specify the Rules property. For more information, see Template Constraint Rules.

  • type (ConstraintType) –

    The type of constraint.

    • LAUNCH

    • NOTIFICATION

    • RESOURCE_UPDATE

    • STACKSET

    • TEMPLATE

  • description (Optional[ConstraintDescription], default: None ) –

    The description of the constraint.

  • idempotency_token (IdempotencyToken) –

    A unique identifier that you provide to ensure idempotency. If multiple requests differ only by the idempotency token, the same response is returned for each repeated request.

Raises:

Source code in docs_src/capo_service_catalog/_services/service_catalog.py
def create_constraint(
    self,
    portfolio_id: "capo_service_catalog.types.id.Id",
    product_id: "capo_service_catalog.types.id.Id",
    parameters: "capo_service_catalog.types.constraint_parameters.ConstraintParameters",
    type: "capo_service_catalog.types.constraint_type.ConstraintType",
    idempotency_token: "capo_service_catalog.types.idempotency_token.IdempotencyToken",
    *,
    config_overrides: Optional[ServiceCatalogClientConfig] = None,
    accept_language: Optional[
        "capo_service_catalog.types.accept_language.AcceptLanguage"
    ] = None,
    description: Optional[
        "capo_service_catalog.types.constraint_description.ConstraintDescription"
    ] = None,
) -> "capo_service_catalog.types.create_constraint_output.CreateConstraintOutput":
    """<p>Creates a constraint.</p> <p>A delegated admin is authorized to invoke this command.</p>

    Args:
        accept_language: <p>The language code.</p> <ul> <li> <p> <code>jp</code> - Japanese</p> </li> <li> <p> <code>zh</code> - Chinese</p> </li> </ul>
        portfolio_id: <p>The portfolio identifier.</p>
        product_id: <p>The product identifier.</p>
        parameters: <p>The constraint parameters, in JSON format. The syntax depends on the constraint type as follows:</p> <dl> <dt>LAUNCH</dt> <dd> <p>You are required to specify either the <code>RoleArn</code> or the <code>LocalRoleName</code> but can't use both.</p> <p>Specify the <code>RoleArn</code> property as follows:</p> <p> <code>{"RoleArn" : "arn:aws:iam::123456789012:role/LaunchRole"}</code> </p> <p>Specify the <code>LocalRoleName</code> property as follows:</p> <p> <code>{"LocalRoleName": "SCBasicLaunchRole"}</code> </p> <p>If you specify the <code>LocalRoleName</code> property, when an account uses the launch constraint, the IAM role with that name in the account will be used. This allows launch-role constraints to be account-agnostic so the administrator can create fewer resources per shared account.</p> <note> <p>The given role name must exist in the account used to create the launch constraint and the account of the user who launches a product with this launch constraint.</p> </note> <p>You cannot have both a <code>LAUNCH</code> and a <code>STACKSET</code> constraint.</p> <p>You also cannot have more than one <code>LAUNCH</code> constraint on a product and portfolio.</p> </dd> <dt>NOTIFICATION</dt> <dd> <p>Specify the <code>NotificationArns</code> property as follows:</p> <p> <code>{"NotificationArns" : ["arn:aws:sns:us-east-1:123456789012:Topic"]}</code> </p> </dd> <dt>RESOURCE_UPDATE</dt> <dd> <p>Specify the <code>TagUpdatesOnProvisionedProduct</code> property as follows:</p> <p> <code>{"Version":"2.0","Properties":{"TagUpdateOnProvisionedProduct":"String"}}</code> </p> <p>The <code>TagUpdatesOnProvisionedProduct</code> property accepts a string value of <code>ALLOWED</code> or <code>NOT_ALLOWED</code>.</p> </dd> <dt>STACKSET</dt> <dd> <p>Specify the <code>Parameters</code> property as follows:</p> <p> <code>{"Version": "String", "Properties": {"AccountList": [ "String" ], "RegionList": [ "String" ], "AdminRole": "String", "ExecutionRole": "String"}}</code> </p> <p>You cannot have both a <code>LAUNCH</code> and a <code>STACKSET</code> constraint.</p> <p>You also cannot have more than one <code>STACKSET</code> constraint on a product and portfolio.</p> <p>Products with a <code>STACKSET</code> constraint will launch an CloudFormation stack set.</p> </dd> <dt>TEMPLATE</dt> <dd> <p>Specify the <code>Rules</code> property. For more information, see <a href="http://docs.aws.amazon.com/servicecatalog/latest/adminguide/reference-template_constraint_rules.html">Template Constraint Rules</a>.</p> </dd> </dl>
        type: <p>The type of constraint.</p> <ul> <li> <p> <code>LAUNCH</code> </p> </li> <li> <p> <code>NOTIFICATION</code> </p> </li> <li> <p> <code>RESOURCE_UPDATE</code> </p> </li> <li> <p> <code>STACKSET</code> </p> </li> <li> <p> <code>TEMPLATE</code> </p> </li> </ul>
        description: <p>The description of the constraint.</p>
        idempotency_token: <p>A unique identifier that you provide to ensure idempotency. If multiple requests differ only by the idempotency token, the same response is returned for each repeated request.</p>

    Raises:
        capo_service_catalog.errors.duplicate_resource_exception.DuplicateResourceException: <p>The specified resource is a duplicate.</p>
        capo_service_catalog.errors.invalid_parameters_exception.InvalidParametersException: <p>One or more parameters provided to the operation are not valid.</p>
        capo_service_catalog.errors.limit_exceeded_exception.LimitExceededException: <p>The current limits of the service would have been exceeded by this operation. Decrease your resource use or increase your service limits and retry the operation.</p>
        capo_service_catalog.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource was not found.</p>
        capo_service_catalog.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_service_catalog.types.create_constraint_input.CreateConstraintInput]",
    ) -> OperationResponse[
        "capo_service_catalog.types.create_constraint_output.CreateConstraintOutput"
    ]:
        import capo_service_catalog._operations.aws242_service_catalog_service.create_constraint

        output, http_response = (
            capo_service_catalog._operations.aws242_service_catalog_service.create_constraint.create_constraint(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateConstraint")
    )
    input_: capo_service_catalog.types.create_constraint_input.CreateConstraintInput = {
        "portfolio_id": portfolio_id,
        "product_id": product_id,
        "parameters": parameters,
        "type": type,
        "idempotency_token": idempotency_token,
    }
    if accept_language is not None:
        input_["accept_language"] = accept_language
    if description is not None:
        input_["description"] = description

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