

# Complete prerequisites to deploy the Edge Manager agent

SageMaker Edge Manager uses Amazon IoT Greengrass V2 to simplify the deployment of the Edge Manager agent, your machine learning models, and your inference application to your devices with the use of components. To make it easier to maintain your Amazon IAM roles, Edge Manager allows you to reuse your existing Amazon IoT role alias. If you do not have one yet, Edge Manager generates a role alias as part of the Edge Manager packaging job. You no longer need to associate a role alias generated from the SageMaker Edge Manager packaging job with your Amazon IoT role. 

Before you start, you must complete the following prerequisites:

1. Install the Amazon IoT Greengrass Core software. For detailed information, see [Install the Amazon IoT Greengrass Core software](https://docs.amazonaws.cn/greengrass/v2/developerguide/getting-started.html#install-greengrass-v2).

1. Set up Amazon IoT Greengrass V2. For more information, see [Install Amazon IoT Greengrass Core software with manual resource provisioning](https://docs.amazonaws.cn/greengrass/v2/developerguide/manual-installation.html).
**Note**  
Make sure the Amazon IoT thing name is all lowercase and does not contain characters except (optionally) dashes (`‐`).
The IAM Role must start with `SageMaker*`

1. Attach the following permission and inline policy to the IAM role created during Amazon IoT Greengrass V2 setup.
   + Navigate to the IAM console [https://console.amazonaws.cn/iam/](https://console.amazonaws.cn/iam/).
   + Search for the role you created by typing in rhe role name in the **Search** field.
   + Choose your role.
   + Next, choose **Attach policies**.
   + Search for **AmazonSageMakerEdgeDeviceFleetPolicy**.
   + Select **AmazonSageMakerFullAccess** (This is an optional step that makes it easier for you to reuse this IAM role in model compilation and packaging).
   + Add required permissions to a role's permissions policy, don't attach inline policies to IAM users.

------
#### [ JSON ]

****  

     ```json
     {
         "Version":"2012-10-17",		 	 	 
         "Statement":[
           {
             "Sid":"GreengrassComponentAccess",
             "Effect":"Allow",
             "Action":[
                 "greengrass:CreateComponentVersion",
                 "greengrass:DescribeComponent"
             ],
             "Resource":"*"
            }
         ]
     }
     ```

------
   + Choose **Attach policy**.
   + Choose **Trust relationship**.
   + Choose **Edit trust relationship**.
   + Replace the content with the following.

------
#### [ JSON ]

****  

     ```json
     {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
         {
           "Effect": "Allow",
           "Principal": {
             "Service": "credentials.iot.amazonaws.com"
           },
           "Action": "sts:AssumeRole"
         },
         {
           "Effect": "Allow",
           "Principal": {
             "Service": "sagemaker.amazonaws.com"
           },
           "Action": "sts:AssumeRole"
         }
       ]
     }
     ```

------

1. Create an Edge Manager device fleet. For information on how to create a fleet, see [Setup for Devices and Fleets in SageMaker Edge Manager](edge-device-fleet.md).

1. Register your device with the same name as your Amazon IoT thing name created during the Amazon IoT Greengrass V2 setup.

1. Create at least one custom private Amazon IoT Greengrass component. This component is the application that runs inference on the device. For more information, see [Create a Hello World custom component](edge-greengrass-custom-component.md#edge-greengrass-create-custom-component-how)

**Note**  
The SageMaker Edge Manager and Amazon IoT Greengrass integration only works for Amazon IoT Greengrass v2.
Both your Amazon IoT thing name and Edge Manager device name must be the same.
SageMaker Edge Manager does not load local Amazon IoT certificates and call the Amazon IoT credential provider endpoint directly. Instead, SageMaker Edge Manager uses the Amazon IoT Greengrass v2 TokenExchangeService and it fetches a temporary credential from a TES endpoint.