Skip to content

create_api_key

create_api_key(
    api_id: String,
    *,
    config_overrides: Optional[AppSyncClientConfig] = None,
    description: Optional[String] = None,
    expires: Optional[Long] = None,
) -> CreateApiKeyResponse

Creates a unique key that you can distribute to clients who invoke your API.

Parameters:

  • api_id (String) –

    The ID for your GraphQL API.

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

    A description of the purpose of the API key.

  • expires (Optional[Long], default: None ) –

    From the creation time, the time after which the API key expires. The date is represented as seconds since the epoch, rounded down to the nearest hour. The default value for this parameter is 7 days from creation time. For more information, see .

Raises:

Source code in docs_src/capo_appsync/_services/app_sync.py
def create_api_key(
    self,
    api_id: "capo_appsync.types.string.String",
    *,
    config_overrides: Optional[AppSyncClientConfig] = None,
    description: Optional["capo_appsync.types.string.String"] = None,
    expires: Optional["capo_appsync.types.long.Long"] = None,
) -> "capo_appsync.types.create_api_key_response.CreateApiKeyResponse":
    """<p>Creates a unique key that you can distribute to clients who invoke your API.</p>

    Args:
        api_id: <p>The ID for your GraphQL API.</p>
        description: <p>A description of the purpose of the API key.</p>
        expires: <p>From the creation time, the time after which the API key expires. The date is represented as seconds since the epoch, rounded down to the nearest hour. The default value for this parameter is 7 days from creation time. For more information, see .</p>

    Raises:
        capo_appsync.errors.api_key_limit_exceeded_exception.ApiKeyLimitExceededException: <p>The API key exceeded a limit. Try your request again.</p>
        capo_appsync.errors.api_key_validity_out_of_bounds_exception.ApiKeyValidityOutOfBoundsException: <p>The API key expiration must be set to a value between 1 and 365 days from creation (for <code>CreateApiKey</code>) or from update (for <code>UpdateApiKey</code>).</p>
        capo_appsync.errors.bad_request_exception.BadRequestException: <p>The request is not well formed. For example, a value is invalid or a required field is missing. Check the field values, and then try again.</p>
        capo_appsync.errors.internal_failure_exception.InternalFailureException: <p>An internal AppSync error occurred. Try your request again.</p>
        capo_appsync.errors.limit_exceeded_exception.LimitExceededException: <p>The request exceeded a limit. Try your request again.</p>
        capo_appsync.errors.not_found_exception.NotFoundException: <p>The resource specified in the request was not found. Check the resource, and then try again.</p>
        capo_appsync.errors.unauthorized_exception.UnauthorizedException: <p>You aren't authorized to perform this operation.</p>
        capo_appsync.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_appsync.types.create_api_key_request.CreateApiKeyRequest]",
    ) -> OperationResponse[
        "capo_appsync.types.create_api_key_response.CreateApiKeyResponse"
    ]:
        import capo_appsync._operations.aws_deepdish_control_plane_service.create_api_key

        output, http_response = (
            capo_appsync._operations.aws_deepdish_control_plane_service.create_api_key.create_api_key(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateApiKey")
    )
    input_: capo_appsync.types.create_api_key_request.CreateApiKeyRequest = {
        "api_id": api_id
    }
    if description is not None:
        input_["description"] = description
    if expires is not None:
        input_["expires"] = expires

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