LoginSignup
0

More than 5 years have passed since last update.

[JAWS-UG CLI] IoT #5 モノの作成

Posted at

前提条件

IoTへの権限

AWS IoTに対してフル権限があること。

AWS CLI

以下のバージョンで動作確認済

  • AWS CLI 1.11.14
コマンド
aws --version
結果(例)
      aws-cli/1.11.14 Python/2.7.10 Darwin/15.6.0 botocore/1.4.71

バージョンが古い場合は最新版に更新しましょう。

コマンド
sudo -H pip install -U awscli

0. 準備

0.1. リージョンの決定

変数の設定
export AWS_DEFAULT_REGION='ap-northeast-1'

0.2. 変数の確認

プロファイルが想定のものになっていることを確認します。

変数の確認
aws configure list
結果(例)
            Name                    Value             Type    Location
            ----                    -----             ----    --------
         profile       iotFull-handson-mbpr13        env    AWS_DEFAULT_PROFILE
      access_key     ****************XXXX shared-credentials-file
      secret_key     ****************XXXX shared-credentials-file
          region        ap-northeast-1        env    AWS_DEFAULT_REGION

1. 事前作業

1.1. モノ名の決定

変数の設定
IOT_THING_NAME="handson-thing-$( date '+%Y%m%d' )" \
        && echo ${IOT_THING_NAME}

同名のモノの不存在確認

コマンド
aws iot describe-thing \
        --thing-name ${IOT_THING_NAME}
結果(例)
      An error occurred (ResourceNotFoundException) when calling the DescribeThing operation: Failed to describe thing handson-thing-20161117 because it does not exist in our ecosystem for your account

2. モノの作成

変数の確認
cat << ETX

        IOT_THING_NAME: ${IOT_THING_NAME}

ETX
コマンド
aws iot create-thing \
        --thing-name ${IOT_THING_NAME}
結果(例)
      {
        "thingArn": "arn:aws:iot:ap-northeast-1:XXXXXXXXXXXX:thing/handson-thing-20161117",
        "thingName": "handson-thing-20161117"
      }

3. 事後作業

3.1. モノの確認

コマンド
aws iot describe-thing \
        --thing-name ${IOT_THING_NAME}
結果(例)
      {
          "attributes": {},
          "version": 1,
          "thingName": "handson-thing-20161117",
          "defaultClientId": "handson-thing-20161117"
      }

3.2. エンドポイントの確認

コマンド
IOT_ENDPOINT=$( \
        aws iot describe-endpoint \
          --query 'endpointAddress' \
          --output text \
) \
        && echo ${IOT_ENDPOINT}
結果(例)
      xxxxxxxxxxxxxx.iot.ap-northeast-1.amazonaws.com

エンドポイント情報は後で使用するのでメモしておいてください。

完了

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0