Menu
AWS Greengrass
Developer Guide

Create a Device Definition

A device definition is a list of AWS Greengrass devices (things) that are members of the AWS Greengrass group and associated configuration data. This data specifies which devices should sync local thing shadow data with AWS IoT. The device list in this scenario consists of a robot arm and switch. Therefore, you must add the RobotArm_Thing and Switch_Thing AWS IoT things to the device list.

First, create a device list:

Copy
aws greengrass create-device-definition --name "DeviceDefinitionName"

The --name argument specifies a name for the device definition.

The output from the create-device-definition CLI command will look like this:

Copy
{ "LastUpdatedTimestamp": "2017-05-17T00:00:00.000Z", "CreationTimestamp":"2017-05-17T00:00:00.000Z", "Id":"c595e5c8-5dd0-4b3b-8262-0e94d4d18bfd", "Arn":"arn:aws:greengrass:us-west-2:123451234510:/greengrass/definition/devices/c595e5c8-5dd0-4b3b-8262-0e94d4d18bfd", "Name":"<DeviceDefinitionName>", }

Next, create a device definition version by adding AWS IoT things to the list:

Copy
aws greengrass create-device-definition-version --device-definition-id "<DeviceDefinitionId>" --devices '[ { "Id": "<DeviceElementId>", "CertificateArn": "<RobotArm-Cert-Arn>", "SyncShadow": true, "ThingArn": "<RobotArm_Thing-Arn>" }, { "Id": "<DeviceElementId>", "CertificateArn": "<Switch-Cert-Arn>", "SyncShadow": false, "ThingArn": "<Switch_Thing-Arn>" } ]'

Arguments for the create-device-definition-version CLI command

--device-definition-id

The ID of the device definition, returned from the create-device-definition CLI command. In the preceding example, it would be c595e5c8-5dd0-4b3b-8262-0e94d4d18bfd.

--devices

A list of JSON objects for each device in the device definition version.

Id

A ID for this entry in the list.

CertificateArn

The ARN of the device's certificate.

SyncShadow

true if the device's shadow should be synchronized with the cloud. Otherwise, false.

ThingArn

The ARN of the device.

The output from the create-device-definition-version CLI command looks like this:

Copy
{ "Arn" : "arn:aws:greengrass:us-west-2:123451234510:/greengrass/definition/devices/c595e5c8-5dd0-4b3b-8262-0e94d4d18bfd/versions/3c57969a-3a98-4092-8388-cece2b39f009", "Id" : "c595e5c8-5dd0-4b3b-8262-0e94d4d18bfd", "Version" : "3c57969a-3a98-4092-8388-cece2b39f009", "CreationTimestamp" : "2017-05-17T18:18:28.393Z" }

Save the device definition version ARN from the CLI command output. You will use it later to add the list to a group.

To view the device definition version, use the get-device-definition-version CLI command:

Copy
aws greengrass get-device-definition-version --device-definition-id DeviceDefinitionId --device-definition-version-id "<DeviceDefinitionVersionId>"

Arguments to the get-device-definition-version CLI command:

--device-definition-id

The ID of the device definition, returned from the create-device-definition CLI command.

--device-definition-version-id

The ID of the device definition version, returned from the create-device-definition-version CLI command.

The output from the get-device-definition-version CLI command looks like this:

Copy
{ "Definition": { "Devices": [ { "CertificateArn": "arn:aws:iot:us-west-2:123451234510:cert/a2909c1e38379f82fedf89011c98613fef6fa96071c3dd64a297fde6a414e150", "ThingArn": "arn:aws:iot:us-west-2:123451234510:thing/RobotArm_Thing", "SyncShadow": true, "Id": "robot-arm" }, { "CertificateArn": "arn:aws:iot:us-west-2:123451234510:cert/62017e65eb92d502459ba0f06211ba49c68a9d4763dd1901e2ea4dc73048ef15", "ThingArn": "arn:aws:iot:us-west-2:123451234510:thing/Switch_Thing", "SyncShadow": false, "Id": "switch" } ] }, "Version": "3c57969a-3a98-4092-8388-cece2b39f009", "CreationTimestamp": "2017-05-17T18:18:28.393Z", "Id": "c595e5c8-5dd0-4b3b-8262-0e94d4d18bfd", "Arn": "arn:aws:greengrass:us-west-2:123451234510:/greengrass/definition/devices/c595e5c8-5dd0-4b3b-8262-0e94d4d18bfd/versions/3c57969a-3a98-4092-8388-cece2b39f009" }

You see that the SyncShadow field for StorylineUpdate_RobotArm is set to true. This will sync the local shadow status for StorylineUpdate_RobotArm. Whenever there's a shadow update for the StorylineUpdate_RobotArm, it will also be reflected in the AWS IoT shadow in the cloud .