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

AWS IoT embedded c SDK 向けThing作成スクリプト

Last updated at Posted at 2020-03-10

Embedded C SDK 向けに、コードのクローン、Thingの作成、ポリシーの作成、証明書の作成、ポリシーのアタッチなど、諸々を行うスクリプトです。
以前書いた記事の手順2〜5を一発で行います。

注意:
エラーケースやスクリプト実行の冪等性等は一切考慮してません。
Policyはセキュリティを考慮した設定が必要です。

ポリシーは、予め以下を作成し保存しておく。

policy.json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action":["iot:*"],
    "Resource": ["*"]
  }]
}
setup.sh

# thing name は適宜変更
THING_NAME=samplething
POLICY_NAME=${THING_NAME}_Policy

aws iot create-thing --thing-name ${THING_NAME}

git clone https://github.com/aws/aws-iot-device-sdk-embedded-C.git
git clone -b mbedtls-2.16 --recursive https://github.com/ARMmbed/mbedtls.git aws-iot-device-sdk-embedded-C/external_libs/mbedTLS/.

cd aws-iot-device-sdk-embedded-C/certs

wget -O rootca.pem \
    https://www.amazontrust.com/repository/AmazonRootCA1.pem

aws iot create-keys-and-certificate --set-as-active \
    --certificate-pem-outfile    ${THING_NAME}_certificate.pem \
    --public-key-outfile         ${THING_NAME}_public_key.pem  \
    --private-key-outfile        ${THING_NAME}_private_key.pem \
    --query certificateArn

cd ../..

echo -n CERTIFICATE_ARN: 
read str 
CERTIFICATE_ARN=$str

aws iot create-policy                     \
        --policy-name ${POLICY_NAME}      \
        --policy-document file://policy.json
        
aws iot attach-thing-principal             \
        --thing-name $THING_NAME           \
        --principal $CERTIFICATE_ARN
        
aws iot attach-principal-policy            \
        --policy-name $POLICY_NAME         \
        --principal $CERTIFICATE_ARN
        
0
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
0
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?