ステップ 3: コンポーネントを AWS IoT Greengrass サービスにパブリッシュします。 - AWS IoT Greengrass

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

ステップ 3: コンポーネントを AWS IoT Greengrass サービスにパブリッシュします。

このセクションでは、Hello World コンポーネントを AWS IoT Greengrass クラウドサービスに公開します。 AWS IoT Greengrass クラウドサービスでコンポーネントが利用可能になったら、コアデバイスにデプロイできます。GDK CLI を使用して、開発用コンピュータから AWS IoT Greengrass クラウドサービスにコンポーネントを発行します。GDK CLI が、ユーザーに代わってコンポーネントの recipe とアーティファクトをアップロードします。

Hello World コンポーネントを AWS IoT Greengrass サービスに発行するには
  1. GDK CLI を使用して次のコマンドを実行し、コンポーネントを構築します。コンポーネントビルドコマンド は、GDK CLI 設定ファイルに基づいて、recipe とアーティファクトを作成します。このプロセスでは、GDK CLI が、コンポーネントのソースコードが含まれる ZIP ファイルを作成します。

    gdk component build

    次の例に示すようなメッセージが表示されます。

    [2022-04-28 11:20:16] INFO - Getting project configuration from gdk-config.json [2022-04-28 11:20:16] INFO - Found component recipe file 'recipe.yaml' in the project directory. [2022-04-28 11:20:16] INFO - Building the component 'com.example.BatteryAwareHelloWorld' with the given project configuration. [2022-04-28 11:20:16] INFO - Using 'zip' build system to build the component. [2022-04-28 11:20:16] WARNING - This component is identified as using 'zip' build system. If this is incorrect, please exit and specify custom build command in the 'gdk-config.json'. [2022-04-28 11:20:16] INFO - Zipping source code files of the component. [2022-04-28 11:20:16] INFO - Copying over the build artifacts to the greengrass component artifacts build folder. [2022-04-28 11:20:16] INFO - Updating artifact URIs in the recipe. [2022-04-28 11:20:16] INFO - Creating component recipe in 'C:\Users\finthomp\greengrassv2\com.example.BatteryAwareHelloWorld\greengrass-build\recipes'.
  2. 次のコマンドを実行して、コンポーネントを AWS IoT Greengrass クラウドサービスに発行します。コンポーネントパブリッシュコマンドは、S3 バケットにコンポーネントの ZIP ファイルのアーティファクトをアップロードします。その後、コンポーネント recipe 内の ZIP ファイルの S3 URI を更新し、recipe を AWS IoT Greengrass サービスにアップロードします。このプロセスでは、GDK CLI は AWS IoT Greengrass クラウドサービスで既に利用可能な Hello World コンポーネントのバージョンをチェックするため、そのバージョンより後の次のパッチバージョンを選択できます。コンポーネントがまだない場合は、GDK CLI は 1.0.0 バージョンを使用します。

    gdk component publish

    次の例に示すようなメッセージが表示されます。出力には、GDK CLI が作成したコンポーネントのバージョンが示されます。

    [2022-04-28 11:20:29] INFO - Getting project configuration from gdk-config.json [2022-04-28 11:20:29] INFO - Found component recipe file 'recipe.yaml' in the project directory. [2022-04-28 11:20:29] INFO - Found credentials in shared credentials file: ~/.aws/credentials [2022-04-28 11:20:30] INFO - No private version of the component 'com.example.BatteryAwareHelloWorld' exist in the account. Using '1.0.0' as the next version to create. [2022-04-28 11:20:30] INFO - Publishing the component 'com.example.BatteryAwareHelloWorld' with the given project configuration. [2022-04-28 11:20:30] INFO - Uploading the component built artifacts to s3 bucket. [2022-04-28 11:20:30] INFO - Uploading component artifacts to S3 bucket: greengrass-component-artifacts-us-west-2-123456789012. If this is your first time using this bucket, add the 's3:GetObject' permission to each core device's token exchange role to allow it to download the component artifacts. For more information, see https://docs.aws.amazon.com/greengrass/v2/developerguide/device-service-role.html. [2022-04-28 11:20:30] INFO - Not creating an artifacts bucket as it already exists. [2022-04-28 11:20:30] INFO - Updating the component recipe com.example.BatteryAwareHelloWorld-1.0.0. [2022-04-28 11:20:31] INFO - Creating a new greengrass component com.example.BatteryAwareHelloWorld-1.0.0 [2022-04-28 11:20:31] INFO - Created private version '1.0.0' of the component in the account.'com.example.BatteryAwareHelloWorld'.
  3. S3 バケット名を出力からコピーします。後ほど、このバケット名を使用して、コアデバイスがこのバケットからコンポーネントアーティファクトをダウンロードできるようにします。

  4. (オプション) AWS IoT Greengrass コンソールでコンポーネントを表示して、正常にアップロードされたことを確認します。以下の操作を実行します。

    1. AWS IoT Greengrass コンソールのナビゲーションメニューで、[Components] (コンポーネント) を選択します。

    2. [Components] (コンポーネント) ページで、[My components] (マイコンポーネント) タブを選択し、次に com.example.BatteryAwareHelloWorld を選択します。

      このページには、コンポーネントの recipe と、コンポーネントに関するその他の情報が表示されます。

  5. コアデバイスが S3 バケット内のコンポーネントアーティファクトにアクセスすることを許可します。

    各コアデバイスには、 AWS クラウドとやり取り AWS IoT してログを送信できるコアデバイス IAM ロールがあります。このデバイスロールは、デフォルトでは S3 バケットへのアクセスを許可しないため、コアデバイスが S3 バケットからコンポーネントアーティファクトを取得できるようにするポリシーを作成して、アタッチする必要があります。

    デバイスのロールで S3 バケットへのアクセスが既に許可されている場合は、このステップを省略できます。そうでない場合は、次に示す方法で、アクセスを許可する IAM ポリシーを作成し、ロールにアタッチします。

    1. [IAM console] (IAM コンソール) ナビゲーションメニューで、[Policies] (ポリシー) を選択し、[Create policy] (ポリシーの作成) を選択します。

    2. JSON タブで、プレースホルダーコンテンツを以下のポリシーに置き換えます。greengrass-component-artifacts-us-west-2-123456789012 を、GDK CLI がコンポーネントのアーティファクトをアップロードした S3 バケットの名前に置き換えます。

      例えば、GDK CLI の設定ファイルで greengrass-component-artifacts および us-west-2 を指定し、 AWS アカウント ID が 123456789012 の場合、GDK CLI は greengrass-component-artifacts-us-west-2-123456789012 という名前の S3 バケットを使用します。

      { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": "arn:aws:s3:::greengrass-component-artifacts-us-west-2-123456789012/*" } ] }
    3. [Next (次へ)] を選択します。

    4. [ポリシーの詳細セクション] で、[名前] に「MyGreengrassV2ComponentArtifactPolicy」と入力します。

    5. [Create policy] を選択します。

    6. [IAM console] (IAM コンソール) ナビゲーションメニューで、[Role] (ロール) をクリックし、コアデバイスのロールの名前を選択します。 AWS IoT Greengrass Core ソフトウェアをインストールしたときに、このロール名を指定しました。名前を指定していない場合、デフォルトで GreengrassV2TokenExchangeRole が設定されます。

    7. [Permissions] (アクセス許可) タブを選択し、[Add permissions] (アクセス許可の追加) を選択してから、[Attach policies] (ポリシーの添付) を選択します。

    8. [アクセス許可の追加] ページで、作成した MyGreengrassV2ComponentArtifactPolicy ポリシーの横にあるチェックボックスを選択し、[アクセス許可の追加] を選択します。