

# CreateAlias
<a name="API_CreateAlias"></a>

Creates an alias for a directory and assigns the alias to the directory. The alias is used to construct the access URL for the directory, such as `http://<alias>.awsapps.com`.

**Important**  
After an alias has been created, it cannot be deleted or reused, so this operation should only be used when absolutely necessary.

## Request Syntax
<a name="API_CreateAlias_RequestSyntax"></a>

```
{
   "Alias": "string",
   "DirectoryId": "string"
}
```

## Request Parameters
<a name="API_CreateAlias_RequestParameters"></a>

The request accepts the following data in JSON format.

 ** [Alias](#API_CreateAlias_RequestSyntax) **   <a name="DirectoryService-CreateAlias-request-Alias"></a>
The requested alias.  
The alias must be unique amongst all aliases in AWS. This operation throws an `EntityAlreadyExistsException` error if the alias already exists.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 62.  
Pattern: `^(?!D-|d-)([\da-zA-Z]+)([-]*[\da-zA-Z])*`   
Required: Yes

 ** [DirectoryId](#API_CreateAlias_RequestSyntax) **   <a name="DirectoryService-CreateAlias-request-DirectoryId"></a>
The identifier of the directory for which to create the alias.  
Type: String  
Pattern: `^d-[0-9a-f]{10}$`   
Required: Yes

## Response Syntax
<a name="API_CreateAlias_ResponseSyntax"></a>

```
{
   "Alias": "string",
   "DirectoryId": "string"
}
```

## Response Elements
<a name="API_CreateAlias_ResponseElements"></a>

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

 ** [Alias](#API_CreateAlias_ResponseSyntax) **   <a name="DirectoryService-CreateAlias-response-Alias"></a>
The alias for the directory.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 62.  
Pattern: `^(?!D-|d-)([\da-zA-Z]+)([-]*[\da-zA-Z])*` 

 ** [DirectoryId](#API_CreateAlias_ResponseSyntax) **   <a name="DirectoryService-CreateAlias-response-DirectoryId"></a>
The identifier of the directory.  
Type: String  
Pattern: `^d-[0-9a-f]{10}$` 

## Errors
<a name="API_CreateAlias_Errors"></a>

For information about the errors that are common to all actions, see [Common Error Types](CommonErrors.md).

 ** ClientException **   
A client exception has occurred.    
 ** Message **   
The descriptive message for the exception.  
 ** RequestId **   
The AWS request identifier.
HTTP Status Code: 400

 ** EntityAlreadyExistsException **   
The specified entity already exists.    
 ** Message **   
The descriptive message for the exception.  
 ** RequestId **   
The AWS request identifier.
HTTP Status Code: 400

 ** EntityDoesNotExistException **   
The specified entity could not be found.    
 ** Message **   
The descriptive message for the exception.  
 ** RequestId **   
The AWS request identifier.
HTTP Status Code: 400

 ** InvalidParameterException **   
One or more parameters are not valid.    
 ** Message **   
The descriptive message for the exception.  
 ** RequestId **   
The AWS request identifier.
HTTP Status Code: 400

 ** ServiceException **   
An exception has occurred in AWS Directory Service.    
 ** Message **   
The descriptive message for the exception.  
 ** RequestId **   
The AWS request identifier.
HTTP Status Code: 500

## Examples
<a name="API_CreateAlias_Examples"></a>

The following examples are formatted for legibility.

### Example Request
<a name="API_CreateAlias_Example_1"></a>

This example illustrates one usage of CreateAlias.

```
POST / HTTP/1.1
Host: ds.us-west-2.amazonaws.com
Accept-Encoding: identity
Content-Length: 52X-Amz-Target:DirectoryService_20150416.CreateAlias
X-Amz-Date: 20161209T175951Z
User-Agent: aws-cli/1.11.24 Python/2.7.9 Windows/7 botocore/1.4.81
Content-Type: application/x-amz-json-1.1
Authorization: AWS4-HMAC-SHA256 
 Credential=AKIAI7E3BYXS3example/20161209/us-west-2/ds/aws4_request,
 SignedHeaders=content-type;host;x-amz-date;x-amz-target,
 Signature=673029721752b71c1ff4752d0e42e6a05283c305238538d746c2b42d7864ec11
 
 {
   "DirectoryId": "d-926example",
   "Alias": "myaccess"
 }
```

### Example Response
<a name="API_CreateAlias_Example_2"></a>

This example illustrates one usage of CreateAlias.

```
HTTP/1.1 200 OK
x-amzn-RequestId: 49abfbf6-be39-11e6-9458-41d91ee57463
Content-Type: application/x-amz-json-1.1
Content-Length: 49
Date: Fri, 09 Dec 2016 17:59:57 GMT

{
  "Alias": "myaccess",
  "DirectoryId": "d-926example"
}
```

## See Also
<a name="API_CreateAlias_SeeAlso"></a>

For more information about using this API in one of the language-specific AWS SDKs, see the following:
+  [AWS Command Line Interface V2](https://docs.aws.amazon.com/goto/cli2/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for .NET V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for C\$1\$1](https://docs.aws.amazon.com/goto/SdkForCpp/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for Go v2](https://docs.aws.amazon.com/goto/SdkForGoV2/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for Java V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for Kotlin](https://docs.aws.amazon.com/goto/SdkForKotlin/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/ds-2015-04-16/CreateAlias) 
+  [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/ds-2015-04-16/CreateAlias) 