createKey method

Future<CreateKeyResponse> createKey({
  1. required String keyName,
  2. required ApiKeyRestrictions restrictions,
  3. String? description,
  4. DateTime? expireTime,
  5. bool? noExpiry,
  6. Map<String, String>? tags,
})

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.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter keyName : 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.

Parameter restrictions : The API key restrictions for the API key resource.

Parameter description : An optional description for the API key resource.

Parameter expireTime : 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.

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

Parameter tags : 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.

Implementation

Future<CreateKeyResponse> createKey({
  required String keyName,
  required ApiKeyRestrictions restrictions,
  String? description,
  DateTime? expireTime,
  bool? noExpiry,
  Map<String, String>? tags,
}) async {
  final $payload = <String, dynamic>{
    'KeyName': keyName,
    'Restrictions': restrictions,
    if (description != null) 'Description': description,
    if (expireTime != null) 'ExpireTime': iso8601ToJson(expireTime),
    if (noExpiry != null) 'NoExpiry': noExpiry,
    if (tags != null) 'Tags': tags,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/metadata/v0/keys',
    exceptionFnMap: _exceptionFns,
  );
  return CreateKeyResponse.fromJson(response);
}