

# Install the AWS IoT Greengrass log manager component on the device
<a name="gs-publish-edge"></a>

**Note**  
Be aware of the [CloudWatch quotas](https://docs.aws.amazon.com//AmazonCloudWatch/latest/logs/cloudwatch_limits_cwl.html).

Follow these procedures to configure the Amazon Kinesis Video Streams Edge Agent logs to automatically upload to CloudWatch using the AWS IoT Greengrass log manager component. This is an optional step.

**Install the AWS IoT Greengrass log manager component**

1. Confirm that the AWS IoT Greengrass device role has the [appropriate permissions](https://docs.aws.amazon.com//greengrass/v2/developerguide/log-manager-component.html#log-manager-component-requirements).

   1. Sign in to the AWS Management Console and open the IAM console at [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/).

   1. Click **Roles** in the left navigation.

   1. Choose the name of the TES role created in [Set up the AWS IoT Greengrass V2 core device on the device](gs-setup-gg.md). Use the search bar if necessary.

   1. Select the `GreengrassV2TokenExchangeRoleAccess` policy.

   1. Select the JSON tab and verify that the policy looks like the following:

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

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [
                      "logs:CreateLogGroup",
                      "logs:CreateLogStream",
                      "logs:PutLogEvents",
                      "logs:DescribeLogStreams",
                      "s3:GetBucketLocation"
                  ],
                  "Resource": "*"
              }
          ]
      }
      ```

------

   1. If the `GreengrassV2TokenExchangeRoleAccess` policy doesn't exist, or if some required permissions are missing, create a new IAM policy with these permissions and attach it to the TES role created in [Set up the AWS IoT Greengrass V2 core device on the device](gs-setup-gg.md).

1. Sign in to the AWS Management Console and open the AWS IoT Core console at [https://console.aws.amazon.com/iot/](https://console.aws.amazon.com/iot/). Verify that the appropriate Region is selected.

1. In the left navigation, choose **Greengrass devices**, **Deployments**.

   Choose the deployment with the same target as the thing you created in [Set up the AWS IoT Greengrass V2 core device on the device](gs-setup-gg.md).

1. In the top right corner, select **Actions**, then choose **Revise**.

   In the pop-up that appears, choose **Revise deployment**.

1. Complete the following sections:

   1. **Step 1: Specify target.** Choose **Next**.

   1. **Step 2: Select components.**

      1. Verify that the **aws.greengrass.Cli** component and **aws.greengrass.SecretManager** components are still selected.
**Important**  
Don't uninstall these components.

      1. Toggle the **Show only selected components** switch and search for **aws.greengrass.LogManager**.

      1. Select the box next to **aws.greengrass.LogManager**, then choose **Next**.

   1. **Step 3: Configure components.** Configure the AWS IoT Greengrass log manager component to upload the logs generated by the Amazon Kinesis Video Streams Edge Agent.

      Select the **aws.greengrass.LogManager** component, then choose **Configure component**.

      In the screen that appears, paste the following log manager configuration in the **Configuration to merge** box.

      ```
      {
          "logsUploaderConfiguration": {
              "componentLogsConfigurationMap": {
                  "aws.kinesisvideo.KvsEdgeComponent/java_kvs.log": {
                      "diskSpaceLimit": "100",
                      "diskSpaceLimitUnit": "MB",
                      "logFileDirectoryPath": "/greengrass/v2/work/aws.kinesisvideo.KvsEdgeComponent/log",
                      "logFileRegex": "java_kvs.log\\w*"
                  },
                  "aws.kinesisvideo.KvsEdgeComponent/cpp_kvs_edge.log": {
                      "diskSpaceLimit": "100",
                      "diskSpaceLimitUnit": "MB",
                      "logFileDirectoryPath": "/greengrass/v2/work/aws.kinesisvideo.KvsEdgeComponent/log",
                      "logFileRegex": "cpp_kvs_edge.log\\w*"
                  },
                  "aws.kinesisvideo.KvsEdgeComponent/cpp_kvssink.log": {
                      "diskSpaceLimit": "100",
                      "diskSpaceLimitUnit": "MB",
                      "logFileDirectoryPath": "/greengrass/v2/work/aws.kinesisvideo.KvsEdgeComponent/log",
                      "logFileRegex": "cpp_kvssink.log\\w*"
                  },
                  "aws.kinesisvideo.KvsEdgeComponent/cpp_kvs_streams.log": {
                      "diskSpaceLimit": "100",
                      "diskSpaceLimitUnit": "MB",
                      "logFileDirectoryPath": "/greengrass/v2/work/aws.kinesisvideo.KvsEdgeComponent/log",
                      "logFileRegex": "cpp_kvs_streams.log\\w*"
                  }
              }
          },
          "periodicUploadIntervalSec": "1"
      }
      ```
**Important**  
The `logFileDirectoryPath` in the preceding configuration assumes that the default logging output location is used.
**Note**  
For more information about each of the parameters for the log manager configuration, see the [Log manager](https://docs.aws.amazon.com//greengrass/v2/developerguide/log-manager-component.html#log-manager-component-configuration) section of the AWS IoT Greengrass Version 2 Developer Guide.

      Once you finish, select **Confirm**, then choose **Next**.

   1. **Step 4: Configure advanced settings.** Select **Next**.

   1. **Step 5: Review.** Select **Deploy**.

1. Confirm that the AWS log manager component and permissions were installed correctly.

1. On the Ubuntu Amazon EC2 instance, type `sudo /greengrass/v2/bin/greengrass-cli component details --name aws.greengrass.LogManager` to verify the component received the updated configuration.

1. Inspect the AWS IoT Greengrass core logs.

   Type `sudo less /greengrass/v2/logs/greengrass.log`.

   Review for deployment errors.

   If there was an error, revise the deployment to remove the `aws.greengrass.LogManager` component.

   Type `sudo service greengrass restart` to restart the AWS IoT Greengrass core service.

   If the deployment error was related to missing permissions, review [Add permissions to the token exchange service (TES) role](gs-add-permissions.md) to make sure that the TES role has proper permissions. Then, repeat this section.