0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[JAWS-UG CLI] IoT #10 モノからのデバイス証明書のデタッチ

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

0.3. モノ名の指定

コマンド
aws iot list-things 
結果(例)
      {
        "things": [
          {
              "attributes": {},
              "thingName": "handson-20161117"
          }
        ]
      }

証明書をデタッチするモノを指定します。

変数の設定
IOT_THING_NAME='<証明書をデタッチするモノ名>'

1. 事前作業

証明書IDの指定

コマンド
aws iot list-thing-principals  \
        --thing-name ${IOT_THING_NAME}
結果(例)
      {
        "principals": [
          "arn:aws:iot:ap-northeast-1:XXXXXXXXXXXX:cert/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        ]
      }
コマンド
aws iot list-thing-principals \
        --thing-name ${IOT_THING_NAME} \
        --query 'principals[]' \
        --output text \
      | sed 's/arn:.*:cert\///'
結果(例)
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

この値を変数に取り込みます。

変数の設定
IOT_CERT_ID='<証明書ID>'

ARNを取得します。

コマンド
IOT_CERT_ARN=$( \
        aws iot describe-certificate \
          --certificate-id ${IOT_CERT_ID} \
          --query 'certificateDescription.certificateArn' \
          --output text \
      ) \
        && echo ${IOT_CERT_ARN}
結果(例)
      arn:aws:iot:ap-northeast-1:XXXXXXXXXXXX:cert/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2. モノから証明書をデタッチする

変数の確認
cat << ETX

        IOT_THING_NAME: ${IOT_THING_NAME}
        IOT_CERT_ARN    ${IOT_CERT_ARN}

ETX
コマンド
aws iot detach-thing-principal \
        --thing-name ${IOT_THING_NAME} \
        --principal ${IOT_CERT_ARN}
結果(例)
      (戻り値なし)

3. 事後作業

コマンド
aws iot list-thing-principals  \
        --thing-name ${IOT_THING_NAME}
結果
      {
          "principals": []
      }

完了

0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?