Skip to content

create_key async

create_key(
    key_name: ResourceName,
    restrictions: ApiKeyRestrictions,
    *,
    config_overrides: Optional[AsyncLocationClientConfig] = None,
    description: Optional[ResourceDescription] = None,
    expire_time: Optional[Timestamp] = None,
    no_expiry: Optional[bool] = None,
    tags: Optional[TagMap] = None,
) -> CreateKeyResponse

Creates an API key resource in your Amazon Web Services account, which lets you grant actions for Amazon Location resources to the API key bearer.

For more information, see Use API keys to authenticate in the Amazon Location Service Developer Guide.

Parameters:

  • key_name (ResourceName) –

    A custom name for the API key resource.

    Requirements:

    • Contain only alphanumeric characters (A–Z, a–z, 0–9), hyphens (-), periods (.), and underscores (_).

    • Must be a unique API key name.

    • No spaces allowed. For example, ExampleAPIKey.

  • restrictions (ApiKeyRestrictions) –

    The API key restrictions for the API key resource.

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

    An optional description for the API key resource.

  • expire_time (Optional[Timestamp], default: None ) –

    The optional timestamp for when the API key resource will expire in ISO 8601 format: YYYY-MM-DDThh:mm:ss.sssZ. One of NoExpiry or ExpireTime must be set.

  • no_expiry (Optional[bool], default: None ) –

    Optionally set to true to set no expiration time for the API key. One of NoExpiry or ExpireTime must be set.

  • tags (Optional[TagMap], default: None ) –

    Applies one or more tags to the map resource. A tag is a key-value pair that helps manage, identify, search, and filter your resources by labelling them.

    Format: "key" : "value"

    Restrictions:

    • Maximum 50 tags per resource

    • Each resource tag must be unique with a maximum of one value.

    • Maximum key length: 128 Unicode characters in UTF-8

    • Maximum value length: 256 Unicode characters in UTF-8

    • Can use alphanumeric characters (A–Z, a–z, 0–9), and the following characters: + - = . _ : / @.

    • Cannot use "aws:" as a prefix for a key.

Raises:

Source code in docs_src/capo_location/_services/async_location.py
async def create_key(
    self,
    key_name: "capo_location.types.resource_name.ResourceName",
    restrictions: "capo_location.types.api_key_restrictions.ApiKeyRestrictions",
    *,
    config_overrides: Optional[AsyncLocationClientConfig] = None,
    description: Optional[
        "capo_location.types.resource_description.ResourceDescription"
    ] = None,
    expire_time: Optional["capo_location.types.timestamp.Timestamp"] = None,
    no_expiry: Optional[bool] = None,
    tags: Optional["capo_location.types.tag_map.TagMap"] = None,
) -> "capo_location.types.create_key_response.CreateKeyResponse":
    """<p>Creates an API key resource in your Amazon Web Services account, which lets you grant actions for Amazon Location resources to the API key bearer.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html">Use API keys to authenticate</a> in the <i>Amazon Location Service Developer Guide</i>.</p>

    Args:
        key_name: <p>A custom name for the API key resource.</p> <p>Requirements:</p> <ul> <li> <p>Contain only alphanumeric characters (A–Z, a–z, 0–9), hyphens (-), periods (.), and underscores (_). </p> </li> <li> <p>Must be a unique API key name.</p> </li> <li> <p>No spaces allowed. For example, <code>ExampleAPIKey</code>.</p> </li> </ul>
        restrictions: <p>The API key restrictions for the API key resource.</p>
        description: <p>An optional description for the API key resource.</p>
        expire_time: <p>The optional timestamp for when the API key resource will expire in <a href="https://www.iso.org/iso-8601-date-and-time-format.html"> ISO 8601</a> format: <code>YYYY-MM-DDThh:mm:ss.sssZ</code>. One of <code>NoExpiry</code> or <code>ExpireTime</code> must be set.</p>
        no_expiry: <p>Optionally set to <code>true</code> to set no expiration time for the API key. One of <code>NoExpiry</code> or <code>ExpireTime</code> must be set.</p>
        tags: <p>Applies one or more tags to the map resource. A tag is a key-value pair that helps manage, identify, search, and filter your resources by labelling them.</p> <p>Format: <code>"key" : "value"</code> </p> <p>Restrictions:</p> <ul> <li> <p>Maximum 50 tags per resource</p> </li> <li> <p>Each resource tag must be unique with a maximum of one value.</p> </li> <li> <p>Maximum key length: 128 Unicode characters in UTF-8</p> </li> <li> <p>Maximum value length: 256 Unicode characters in UTF-8</p> </li> <li> <p>Can use alphanumeric characters (A–Z, a–z, 0–9), and the following characters: + - = . _ : / @. </p> </li> <li> <p>Cannot use "aws:" as a prefix for a key.</p> </li> </ul>

    Raises:
        capo_location.errors.access_denied_exception.AccessDeniedException: <p>The request was denied because of insufficient access or permissions. Check with an administrator to verify your permissions.</p>
        capo_location.errors.conflict_exception.ConflictException: <p>The request was unsuccessful because of a conflict.</p>
        capo_location.errors.internal_server_exception.InternalServerException: <p>The request has failed to process because of an unknown server error, exception, or failure.</p>
        capo_location.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The operation was denied because the request would exceed the maximum <a href="https://docs.aws.amazon.com/location/previous/developerguide/location-quotas.html">quota</a> set for Amazon Location Service.</p>
        capo_location.errors.throttling_exception.ThrottlingException: <p>The request was denied because of request throttling.</p>
        capo_location.errors.validation_exception.ValidationException: <p>The input failed to meet the constraints specified by the AWS service. </p>
        capo_location.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_location.types.create_key_request.CreateKeyRequest]",
    ) -> AsyncOperationResponse[
        "capo_location.types.create_key_response.CreateKeyResponse"
    ]:
        import capo_location._operations.location_service.create_key

        (
            output,
            http_response,
        ) = await capo_location._operations.location_service.create_key.async_create_key(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_location.types.create_key_request.CreateKeyRequest",
    ) -> dict[str, Any]:
        import capo_location.types.create_key_request

        return capo_location.types.create_key_request.redact_sensitive(input_)

    def _redact_output(
        output: "capo_location.types.create_key_response.CreateKeyResponse",
    ) -> dict[str, Any]:
        import capo_location.types.create_key_response

        return capo_location.types.create_key_response.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateKey", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_location.types.create_key_request.CreateKeyRequest = {
        "key_name": key_name,
        "restrictions": restrictions,
    }
    if description is not None:
        input_["description"] = description
    if expire_time is not None:
        input_["expire_time"] = expire_time
    if no_expiry is not None:
        input_["no_expiry"] = no_expiry
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output