2
1

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 3 years have passed since last update.

AWS IoT SDK for Python v2でフリートプロビジョニング

Last updated at Posted at 2020-06-07

AWS IoTのフリートプロビジョニング機能が面白そうだなぁと思ってAWS IoT Device SDK for PythonのGitHubのREADMEを眺めていると
## New Version Available
の文字が!!!

AWS IoT SDK for Python v2が出てました。
https://github.com/aws/aws-iot-device-sdk-python-v2
(呼び方はAWS IoT SDK for Python v2なのかaws-iot-device-sdk-python-v2なのかAWS IoT Client SDK for Pythonなのかよくわかりません)

READMEによると

This SDK is built on the AWS Common Runtime, a collection of libraries written in C to be cross-platform, high-performance, secure, and reliable.

だそうです。

さらにv2はフリートプロビジョニングのAPIにもすでに対応しており、サンプルも含まれています。
今後はv2が主流でしょうか。

AWSのブログで紹介されていたサンプルと同じ内容をv2で試してみました。

フリートプロビジョニングを用いて、IoTデバイスとAWS IoT Coreの初期セットアップを自動化する方法

環境

Mac
Python 3.8.2

AWS IoT SDK for Python v2のインストール

git clone https://github.com/aws/aws-iot-device-sdk-python-v2.git
pip install ./aws-iot-device-sdk-python-v2

ブートストラップ証明書の配置

証明書は以下の場所に配置しました。

console
.
├── aws-iot-device-sdk-python-v2
└── certs
    ├── bootstrap-certificate.pem.crt
    ├── bootstrap-private.pem.key
    └── root.ca.pem

サンプルの実行

templateNametemplateParametersはいい感じに修正ください。

cd aws-iot-device-sdk-python-v2/samples/

python fleetprovisioning.py \
  --endpoint xxxxxxxxxx.iot.ap-northeast-1.amazonaws.com \
  --root-ca ../../certs/root.ca.pem \
  --cert ../../certs/bootstrap-certificate.pem.crt \
  --key ../../certs/bootstrap-private.pem.key \
  --templateName production_template \
  --templateParameters '{"SerialNumber": 9999, "hasValidAccount": false}'

実行結果(ところどころ伏せたり端折ったりしてます)

Connecting to xxxxxxxxxx.iot.ap-northeast-1.amazonaws.com with client ID 'samples-client-id'...
Connected!
Subscribing to CreateKeysAndCertificate Accepted topic...
Subscribing to CreateKeysAndCertificate Rejected topic...
Subscribing to RegisterThing Accepted topic...
Subscribing to RegisterThing Rejected topic...
Publishing to CreateKeysAndCertificate...
Waiting... CreateKeysAndCertificateResponse: null
Published CreateKeysAndCertificate request..
Received a new message awsiot.iotidentity.CreateKeysAndCertificateResponse(certificate_id='xxxxxxxxxx', certificate_ownership_token='xxxxxxxxxx', certificate_pem='-----BEGIN CERTIFICATE-----\nxxxxxxxxxx\n-----END CERTIFICATE-----\n', private_key='-----BEGIN RSA PRIVATE KEY-----\nxxxxxxxxxx\n-----END RSA PRIVATE KEY-----\n')
Publishing to RegisterThing topic...
Waiting... RegisterThingResponse: null
Published RegisterThing request..
Received a new message awsiot.iotidentity.RegisterThingResponse(device_configuration={}, thing_name='born_9999') 
Exiting Sample: success
Disconnecting...
Disconnected.

参考サイト

https://docs.aws.amazon.com/ja_jp/iot/latest/developerguide/provision-wo-cert.html
https://aws.amazon.com/jp/about-aws/whats-new/2020/04/announcing-general-availability-of-aws-iot-core-fleet-provisioning/
https://aws.amazon.com/jp/blogs/news/how-to-automate-onboarding-of-iot-devices-to-aws-iot-core-at-scale-with-fleet-provisioning/
https://qiita.com/tatsuhiroiida/items/46ef5035f99b304d3d6f

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?