

# AssociateServiceRoleToAccount
<a name="API_AssociateServiceRoleToAccount"></a>

Associates a Greengrass service role with Amazon IoT Greengrass for your Amazon Web Services account in this Amazon Web Services Region. Amazon IoT Greengrass uses this role to verify the identity of client devices and manage core device connectivity information. The role must include the [AWSGreengrassResourceAccessRolePolicy](https://console.amazonaws.cn/iam/home#/policies/arn:awsiam::aws:policy/service-role/AWSGreengrassResourceAccessRolePolicy) managed policy or a custom policy that defines equivalent permissions for the Amazon IoT Greengrass features that you use. For more information, see [Greengrass service role](https://docs.amazonaws.cn/greengrass/v2/developerguide/greengrass-service-role.html) in the * Amazon IoT Greengrass Version 2 Developer Guide*.

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

```
PUT /greengrass/servicerole HTTP/1.1
Content-type: application/json

{
   "RoleArn": "{{string}}"
}
```

## URI Request Parameters
<a name="API_AssociateServiceRoleToAccount_RequestParameters"></a>

The request does not use any URI parameters.

## Request Body
<a name="API_AssociateServiceRoleToAccount_RequestBody"></a>

The request accepts the following data in JSON format.

 ** [RoleArn](#API_AssociateServiceRoleToAccount_RequestSyntax) **   <a name="greengrassv2-AssociateServiceRoleToAccount-request-RoleArn"></a>
The Amazon Resource Name (ARN) of the service role to associate with Amazon IoT Greengrass for your Amazon Web Services account in this Amazon Web Services Region.  
Type: String  
Required: Yes

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

```
HTTP/1.1 200
Content-type: application/json

{
   "AssociatedAt": "string"
}
```

## Response Elements
<a name="API_AssociateServiceRoleToAccount_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.

 ** [AssociatedAt](#API_AssociateServiceRoleToAccount_ResponseSyntax) **   <a name="greengrassv2-AssociateServiceRoleToAccount-response-AssociatedAt"></a>
The time when the service role was associated with Amazon IoT Greengrass for your Amazon Web Services account in this Amazon Web Services Region.  
Type: String

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

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

 ** InternalServerException **   
 Amazon IoT Greengrass can't process your request right now. Try again later.    
 ** retryAfterSeconds **   
The amount of time to wait before you retry the request.
HTTP Status Code: 500

 ** ValidationException **   
The request isn't valid. This can occur if your request contains malformed JSON or unsupported characters.    
 ** fields **   
The list of fields that failed to validate.  
 ** reason **   
The reason for the validation exception.
HTTP Status Code: 400

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

For more information about using this API in one of the language-specific Amazon SDKs, see the following:
+  [Amazon Command Line Interface V2](https://docs.amazonaws.cn/goto/cli2/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for .NET V4](https://docs.amazonaws.cn/goto/DotNetSDKV4/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for C\+\+](https://docs.amazonaws.cn/goto/SdkForCpp/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for Go v2](https://docs.amazonaws.cn/goto/SdkForGoV2/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for Java V2](https://docs.amazonaws.cn/goto/SdkForJavaV2/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for JavaScript V3](https://docs.amazonaws.cn/goto/SdkForJavaScriptV3/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for Kotlin](https://docs.amazonaws.cn/goto/SdkForKotlin/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for PHP V3](https://docs.amazonaws.cn/goto/SdkForPHPV3/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for Python](https://docs.amazonaws.cn/goto/boto3/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 
+  [Amazon SDK for Ruby V3](https://docs.amazonaws.cn/goto/SdkForRubyV3/greengrassv2-2020-11-30/AssociateServiceRoleToAccount) 