AWS IoT 1-Click Projects examples using AWS CLI - AWS Command Line Interface

AWS IoT 1-Click Projects examples using AWS CLI

The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with AWS IoT 1-Click Projects.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use associate-device-with-placement.

AWS CLI

To associate an AWS IoT 1-Click device with an existing placement

The following associate-device-with-placement example associates the specified AWS IoT 1-Click device with an existing placement.

aws iot1click-projects associate-device-with-placement \ --project-name AnytownDumpsters \ --placement-name customer217 \ --device-template-name empty-dumpster-request \ --device-id G030PM0123456789

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use create-placement.

AWS CLI

To create an AWS IoT 1-Click placement for a project

The following create-placement example create an AWS IoT 1-Click placement for the specified project.

aws iot1click-projects create-placement \ --project-name AnytownDumpsters \ --placement-name customer217 \ --attributes "{"location": "123 Any Street Anytown, USA 10001", "phone": "123-456-7890"}"

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use create-project.

AWS CLI

To create an AWS IoT 1-Click project for zero or more placements

The following create-project example creates an AWS IoT 1-Click project for a placement.

aws iot1click-projects create-project --cli-input-json file://create-project.json

Contents of create-project.json:

{ "projectName": "AnytownDumpsters", "description": "All dumpsters in the Anytown region.", "placementTemplate": { "defaultAttributes": { "City" : "Anytown" }, "deviceTemplates": { "empty-dumpster-request" : { "deviceType": "button" } } } }

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

  • For API details, see CreateProject in AWS CLI Command Reference.

The following code example shows how to use delete-placement.

AWS CLI

To delete a placement from a project

The following delete-placement example deletes the specified placement from a project.

aws iot1click-projects delete-placement \ --project-name AnytownDumpsters \ --placement-name customer217

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use delete-project.

AWS CLI

To delete a project from your AWS account

The following delete-project example deletes the specified project from your AWS account.

aws iot1click-projects delete-project \ --project-name AnytownDumpsters

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

  • For API details, see DeleteProject in AWS CLI Command Reference.

The following code example shows how to use describe-placement.

AWS CLI

To describe a placement for a project

The following describe-placement example describes a placement for the specified project.

aws iot1click-projects describe-placement \ --project-name AnytownDumpsters \ --placement-name customer217

Output:

{ "placement": { "projectName": "AnytownDumpsters", "placementName": "customer217", "attributes": { "phone": "123-555-0110", "location": "123 Any Street Anytown, USA 10001" }, "createdDate": 1563488454, "updatedDate": 1563488454 } }

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use describe-project.

AWS CLI

To describe an AWS IoT 1-Click project

The following describe-project example describes the specified AWS IoT 1-Click project.

aws iot1click-projects describe-project \ --project-name AnytownDumpsters

Output:

{ "project": { "arn": "arn:aws:iot1click:us-west-2:012345678901:projects/AnytownDumpsters", "projectName": "AnytownDumpsters", "description": "All dumpsters in the Anytown region.", "createdDate": 1563483100, "updatedDate": 1563483100, "placementTemplate": { "defaultAttributes": { "City": "Anytown" }, "deviceTemplates": { "empty-dumpster-request": { "deviceType": "button", "callbackOverrides": {} } } }, "tags": {} } }

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use disassociate-device-from-placement.

AWS CLI

To disassociate a device from a placement

The following disassociate-device-from-placement example disassociates the specified device from a placement.

aws iot1click-projects disassociate-device-from-placement \ --project-name AnytownDumpsters \ --placement-name customer217 \ --device-template-name empty-dumpster-request

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use get-devices-in-placement.

AWS CLI

To list all devices in a placement contained in a project

The following get-devices-in-placement example lists all devices in a the specified placement contained in the specified project.

aws iot1click-projects get-devices-in-placement \ --project-name AnytownDumpsters \ --placement-name customer217

Output:

{ "devices": { "empty-dumpster-request": "G030PM0123456789" } }

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use list-placements.

AWS CLI

To list all AWS IoT 1-Click placements for a project

The following list-placements example lists all AWS IoT 1-Click placements for the specified project.

aws iot1click-projects list-placements \ --project-name AnytownDumpsters

Output:

{ "placements": [ { "projectName": "AnytownDumpsters", "placementName": "customer217", "createdDate": 1563488454, "updatedDate": 1563488454 } ] }

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use list-projects.

AWS CLI

To list all AWS IoT 1-Click projects

The following list-projects example list all AWS IoT 1-Click projects in your account.

aws iot1click-projects list-projects

Output:

{ "projects": [ { "arn": "arn:aws:iot1click:us-west-2:012345678901:projects/AnytownDumpsters", "projectName": "AnytownDumpsters", "createdDate": 1563483100, "updatedDate": 1563483100, "tags": {} } ] }

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

  • For API details, see ListProjects in AWS CLI Command Reference.

The following code example shows how to use list-tags-for-resource.

AWS CLI

To list the tags for a project resource

The following list-tags-for-resource example list the tags for the specified project resource.

aws iot1click-projects list-tags-for-resource \ --resource-arn "arn:aws:iot1click:us-west-2:123456789012:projects/AnytownDumpsters"

Output:

{ "tags": { "Manager": "Li Juan", "Account": "45215" } }

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use tag-resource.

AWS CLI

To add tags to a project resource

The following tag-resource example adds two tags to the specified project resource.

aws iot1click-projects tag-resource \ --cli-input-json file://devices-tag-resource.json

Contents of devices-tag-resource.json:

{ "resourceArn": "arn:aws:iot1click:us-west-2:123456789012:projects/AnytownDumpsters", "tags": { "Account": "45215", "Manager": "Li Juan" } }

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

  • For API details, see TagResource in AWS CLI Command Reference.

The following code example shows how to use untag-resource.

AWS CLI

To remove tags from a project resource

The following untag-resource example removes the tag with the key name Manager from the specified project.

aws iot1click-projects untag-resource \ --resource-arn "arn:aws:iot1click:us-west-2:123456789012:projects/AnytownDumpsters" \ --tag-keys "Manager"

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

  • For API details, see UntagResource in AWS CLI Command Reference.

The following code example shows how to use update-placement.

AWS CLI

To update the "attributes" key-value pairs of a placement

The following update-placement example update the "attributes" key-value pairs of a placement.

aws iot1click-projects update-placement \ --cli-input-json file://update-placement.json

Contents of update-placement.json:

{ "projectName": "AnytownDumpsters", "placementName": "customer217", "attributes": { "phone": "123-456-7890", "location": "123 Any Street Anytown, USA 10001" } }

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

The following code example shows how to use update-project.

AWS CLI

To update settings for a project

The following update-project example updates the description for a project.

aws iot1click-projects update-project \ --project-name AnytownDumpsters \ --description "All dumpsters (yard waste, recycling, garbage) in the Anytown region."

This command produces no output.

For more information, see Using AWS IoT 1-Click with the AWS CLI in the AWS IoT 1-Click Developer Guide.

  • For API details, see UpdateProject in AWS CLI Command Reference.