5단계: AWS IoT Greengrass 서비스에서 구성 요소 생성 - AWS IoT Greengrass

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

5단계: AWS IoT Greengrass 서비스에서 구성 요소 생성

코어 디바이스에서 구성 요소 개발을 마치면 의 AWS IoT Greengrass 서비스에 업로드할 수 AWS 클라우드있습니다. AWS IoT Greengrass 콘솔에서 구성 요소를 직접 만들 수도 있습니다. AWS IoT Greengrass 개별 장치 또는 장치 집합에 배포할 수 있도록 구성 요소를 호스팅하는 구성 요소 관리 서비스를 제공합니다. AWS IoT Greengrass 서비스에 구성 요소를 업로드하려면 다음 단계를 완료하십시오.

  • 구성 요소 아티팩트를 S3 버킷에 업로드합니다.

  • 각 아티팩트의 아마존 심플 스토리지 서비스 (Amazon URI S3) 를 구성 요소 레시피에 추가합니다.

  • 구성 요소 AWS IoT Greengrass 레시피에서 구성 요소를 생성합니다.

이 섹션에서는 Greengrass 코어 디바이스에서 다음 단계를 완료하여 Hello World 구성 요소를 서비스에 업로드합니다 AWS IoT Greengrass .

  1. AWS 계정의 S3 버킷을 사용하여 AWS IoT Greengrass 구성 요소 아티팩트를 호스팅하십시오. 구성 요소를 코어 디바이스에 배포하면 디바이스가 버킷에서 구성 요소의 아티팩트를 다운로드합니다.

    기존 S3 버킷을 사용하거나 새 버킷을 생성할 수 있습니다.

    1. Amazon S3 콘솔의 버킷에서 버킷 생성을 선택합니다.

    2. 버킷 이름에 고유한 버킷 이름을 입력합니다. 예를 들어 greengrass-component-artifacts-region-123456789012를 사용할 수 있습니다. Replace 123456789012 AWS 계정 ID와 함께 region 이 튜토리얼에서 사용한 AWS 리전 것과 함께.

    3. AWS 지역의 경우 이 자습서에 사용할 AWS 지역을 선택합니다.

    4. 버킷 생성을 선택합니다.

    5. 버킷에서 생성한 버킷을 선택하고 버킷의 artifacts/com.example.HelloWorld/1.0.0 폴더에 hello_world.py 스크립트를 업로드합니다. S3 버킷에 객체를 업로드하는 방법에 대한 자세한 내용은 Amazon 심플 스토리지 서비스 사용 설명서의 객체 업로드를 참조하십시오.

    6. S3 버킷에 URI 있는 hello_world.py 객체의 S3를 복사합니다. 이는 다음 예제와 URI 비슷해야 합니다. amzn-s3-demo-버킷을 S3 버킷 이름으로 바꾸십시오.

      s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py
  2. 코어 디바이스가 S3 버킷의 구성 요소 아티팩트에 액세스할 수 있도록 허용합니다.

    각 코어 디바이스에는 클라우드와 상호 AWS IoT 작용하고 AWS 클라우드로 로그를 전송할 수 있는 핵심 디바이스 IAM 역할이 있습니다. 이 디바이스 역할은 기본적으로 S3 버킷에 대한 액세스를 허용하지 않으므로 코어 디바이스가 S3 버킷에서 구성 요소 아티팩트를 검색하도록 허용하는 정책을 생성하여 연결해야 합니다.

    디바이스 역할이 이미 S3 버킷에 대한 액세스를 허용하고 있다면 이 단계를 건너뛰어도 됩니다. 그렇지 않으면 다음과 같이 액세스를 허용하는 IAM 정책을 생성하여 역할에 연결하십시오.

    1. IAM콘솔 탐색 메뉴에서 [Policies] 를 선택한 다음 [Create policy] 를 선택합니다.

    2. JSON탭에서 자리 표시자 콘텐츠를 다음 정책으로 대체하십시오. amzn-s3-demo-bucket을 다운로드할 코어 디바이스의 구성 요소 아티팩트가 포함된 S3 버킷의 이름으로 바꾸십시오.

      { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*" } ] }
    3. Next(다음)를 선택합니다.

    4. 정책 세부 정보 섹션의 이름에 을 입력합니다. MyGreengrassV2ComponentArtifactPolicy

    5. 정책 생성을 선택합니다.

    6. IAM콘솔 탐색 메뉴에서 역할을 선택한 다음 코어 장치의 역할 이름을 선택합니다. AWS IoT Greengrass Core 소프트웨어를 설치할 때 이 역할 이름을 지정했습니다. 이름을 지정하지 않은 경우 기본값은 입니다GreengrassV2TokenExchangeRole.

    7. 권한에서 권한 추가를 선택한 다음 정책 연결을 선택합니다.

    8. 권한 추가 페이지에서 생성한 MyGreengrassV2ComponentArtifactPolicy 정책 옆의 확인란을 선택한 다음 권한 추가를 선택합니다.

  3. 구성 요소 레시피를 사용하여 AWS IoT Greengrass 콘솔에서 구성 요소를 만들 수 있습니다.

    1. AWS IoT Greengrass 콘솔 탐색 메뉴에서 구성 요소를 선택한 다음 구성 요소 생성을 선택합니다.

    2. 구성 요소 정보에서 레시피 입력을 다음과 같이 선택합니다JSON. 플레이스홀더 레시피는 다음 예와 비슷해야 합니다.

      { "RecipeFormatVersion": "2020-01-25", "ComponentName": "com.example.HelloWorld", "ComponentVersion": "1.0.0", "ComponentDescription": "My first AWS IoT Greengrass component.", "ComponentPublisher": "Amazon", "ComponentConfiguration": { "DefaultConfiguration": { "Message": "world" } }, "Manifests": [ { "Platform": { "os": "linux" }, "Lifecycle": { "run": "python3 -u {artifacts:path}/hello_world.py \"{configuration:/Message}\"" }, "Artifacts": [ { "URI": "s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py" } ] }, { "Platform": { "os": "windows" }, "Lifecycle": { "run": "py -3 -u {artifacts:path}/hello_world.py \"{configuration:/Message}\"" }, "Artifacts": [ { "URI": "s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py" } ] } ] }
    3. Artifacts 섹션의 플레이스홀더를 URI 객체의 URI S3로 바꾸십시오. hello_world.py

    4. 구성 요소 생성을 선택합니다.

    5. com.example에서. HelloWorld구성 요소 페이지에서 구성 요소 상태가 배포 가능인지 확인합니다.

헬로 월드 컴포넌트를 업로드하려면
  1. 내 S3 버킷을 사용하여 AWS IoT Greengrass 구성 요소 아티팩트를 호스팅하십시오 AWS 계정 . 구성 요소를 코어 디바이스에 배포하면 디바이스가 버킷에서 구성 요소의 아티팩트를 다운로드합니다.

    기존 S3 버킷을 사용하거나 다음 명령을 실행하여 버킷을 생성할 수 있습니다. 이 명령은 AWS 계정 ID를 사용하여 버킷을 생성하고 고유한 버킷 이름을 형성합니다. AWS 리전 Replace 123456789012 AWS 계정 ID와 함께 region 이 튜토리얼에서 사용한 AWS 리전 것과 함께 말이죠.

    aws s3 mb s3://greengrass-component-artifacts-123456789012-region

    이 명령은 요청이 성공하면 다음 정보를 출력합니다.

    make_bucket: greengrass-component-artifacts-123456789012-region
  2. 코어 디바이스가 S3 버킷의 구성 요소 아티팩트에 액세스할 수 있도록 허용합니다.

    각 코어 디바이스에는 코어 디바이스와 상호 AWS IoT 작용하고 로그를 전송할 수 있는 핵심 디바이스 IAM 역할이 있습니다. AWS 클라우드이 디바이스 역할은 기본적으로 S3 버킷에 대한 액세스를 허용하지 않으므로 코어 디바이스가 S3 버킷에서 구성 요소 아티팩트를 검색하도록 허용하는 정책을 생성하고 연결해야 합니다.

    코어 디바이스의 역할이 이미 S3 버킷에 대한 액세스를 허용한 경우에는 이 단계를 건너뛰어도 됩니다. 그렇지 않으면 다음과 같이 액세스를 허용하는 IAM 정책을 생성하여 역할에 연결하십시오.

    1. 라는 component-artifact-policy.json 파일을 만들고 다음을 JSON 파일에 복사합니다. 이 정책은 S3 버킷의 모든 파일에 대한 액세스를 허용합니다. amzn-s3-demo-버킷을 S3 버킷 이름으로 대체합니다.

      { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject" ], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*" } ] }
    2. 다음 명령을 실행하여 의 정책 문서에서 정책을 생성합니다. component-artifact-policy.json

      Linux or Unix
      aws iam create-policy \\ --policy-name MyGreengrassV2ComponentArtifactPolicy \\ --policy-document file://component-artifact-policy.json
      Windows Command Prompt (CMD)
      aws iam create-policy ^ --policy-name MyGreengrassV2ComponentArtifactPolicy ^ --policy-document file://component-artifact-policy.json
      PowerShell
      aws iam create-policy ` --policy-name MyGreengrassV2ComponentArtifactPolicy ` --policy-document file://component-artifact-policy.json

      출력의 정책 메타데이터에서 Amazon 리소스 이름 (ARN) 정책을 복사합니다. 다음 단계에서 이 정책을 핵심 디바이스 역할에 연결하는 ARN 데 사용합니다.

    3. 다음 명령을 실행하여 정책을 핵심 장치 역할에 연결합니다. Replace GreengrassV2TokenExchangeRole 코어 디바이스의 역할 이름과 함께. AWS IoT Greengrass Core 소프트웨어를 설치할 때 이 역할 이름을 지정했습니다. 정책을 이전 단계의 ARN 정책으로 교체합니다. ARN

      Linux or Unix
      aws iam attach-role-policy \\ --role-name GreengrassV2TokenExchangeRole \\ --policy-arn arn:aws:iam::123456789012:policy/MyGreengrassV2ComponentArtifactPolicy
      Windows Command Prompt (CMD)
      aws iam attach-role-policy ^ --role-name GreengrassV2TokenExchangeRole ^ --policy-arn arn:aws:iam::123456789012:policy/MyGreengrassV2ComponentArtifactPolicy
      PowerShell
      aws iam attach-role-policy ` --role-name GreengrassV2TokenExchangeRole ` --policy-arn arn:aws:iam::123456789012:policy/MyGreengrassV2ComponentArtifactPolicy

      명령 출력이 없으면 성공한 것입니다. 이제 코어 디바이스는 이 S3 버킷에 업로드한 아티팩트에 액세스할 수 있습니다.

  3. Hello World Python 스크립트 아티팩트를 S3 버킷에 업로드합니다.

    다음 명령을 실행하여 스크립트가 AWS IoT Greengrass 코어에 있는 버킷의 동일한 경로에 스크립트를 업로드합니다. amzn-s3-demo-bucket을 S3 버킷 이름으로 대체합니다.

    Linux or Unix
    aws s3 cp \ artifacts/com.example.HelloWorld/1.0.0/hello_world.py \ s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py
    Windows Command Prompt (CMD)
    aws s3 cp ^ artifacts/com.example.HelloWorld/1.0.0/hello_world.py ^ s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py
    PowerShell
    aws s3 cp ` artifacts/com.example.HelloWorld/1.0.0/hello_world.py ` s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py

    이 명령은 요청이 성공하면 로 시작하는 줄을 출력합니다. upload:

  4. 아티팩트의 Amazon URI S3를 구성 요소 레시피에 추가합니다.

    Amazon URI S3는 버킷 이름과 버킷 내 아티팩트 객체 경로로 구성됩니다. 이전 단계에서 아티팩트를 업로드한 URI 대상이 스크립트 아티팩트의 Amazon URI S3입니다. 이는 다음 예제와 URI 비슷해야 합니다. amzn-s3-demo-버킷을 S3 버킷 이름으로 바꾸십시오.

    s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py

    레시피에 아티팩트를 추가하려면 Amazon URI S3를 사용하여 구조가 Artifacts 포함된 목록을 추가하십시오.

    JSON
    "Artifacts": [ { "URI": "s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py" } ]

    텍스트 편집기에서 레시피 파일을 엽니다.

    예를 들어, Linux 기반 시스템에서는 다음 명령을 실행하여 GNU nano를 사용하여 파일을 생성할 수 있습니다.

    nano recipes/com.example.HelloWorld-1.0.0.json

    레시피에 아티팩트를 추가합니다. 레시피 파일은 다음 예제와 비슷해야 합니다.

    { "RecipeFormatVersion": "2020-01-25", "ComponentName": "com.example.HelloWorld", "ComponentVersion": "1.0.0", "ComponentDescription": "My first AWS IoT Greengrass component.", "ComponentPublisher": "Amazon", "ComponentConfiguration": { "DefaultConfiguration": { "Message": "world" } }, "Manifests": [ { "Platform": { "os": "linux" }, "Lifecycle": { "run": "python3 -u {artifacts:path}/hello_world.py \"{configuration:/Message}\"" }, "Artifacts": [ { "URI": "s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py" } ] }, { "Platform": { "os": "windows" }, "Lifecycle": { "run": "py -3 -u {artifacts:path}/hello_world.py \"{configuration:/Message}\"" }, "Artifacts": [ { "URI": "s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py" } ] } ] }
    YAML
    Artifacts: - URI: s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py

    텍스트 편집기에서 레시피 파일을 엽니다.

    예를 들어, Linux 기반 시스템에서는 다음 명령을 실행하여 GNU nano를 사용하여 파일을 생성할 수 있습니다.

    nano recipes/com.example.HelloWorld-1.0.0.yaml

    레시피에 아티팩트를 추가합니다. 레시피 파일은 다음 예제와 비슷해야 합니다.

    --- RecipeFormatVersion: '2020-01-25' ComponentName: com.example.HelloWorld ComponentVersion: '1.0.0' ComponentDescription: My first AWS IoT Greengrass component. ComponentPublisher: Amazon ComponentConfiguration: DefaultConfiguration: Message: world Manifests: - Platform: os: linux Lifecycle: run: | python3 -u {artifacts:path}/hello_world.py "{configuration:/Message}" Artifacts: - URI: s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py - Platform: os: windows Lifecycle: run: | py -3 -u {artifacts:path}/hello_world.py "{configuration:/Message}" Artifacts: - URI: s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py
  5. AWS IoT Greengrass 레시피에서 구성 요소 리소스를 생성합니다. 다음 명령을 실행하여 레시피에서 구성 요소를 생성합니다. 레시피는 바이너리 파일로 제공됩니다.

    JSON
    aws greengrassv2 create-component-version --inline-recipe fileb://recipes/com.example.HelloWorld-1.0.0.json
    YAML
    aws greengrassv2 create-component-version --inline-recipe fileb://recipes/com.example.HelloWorld-1.0.0.yaml

    요청이 성공하면 응답은 다음 예제와 비슷해 보입니다.

    { "arn": "arn:aws:greengrass:region:123456789012:components:com.example.HelloWorld:versions:1.0.0", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "creationTimestamp": "Mon Nov 30 09:04:05 UTC 2020", "status": { "componentState": "REQUESTED", "message": "NONE", "errors": {} } }

    arn출력에서 를 복사하여 다음 단계에서 구성 요소의 상태를 확인합니다.

    참고

    AWS IoT Greengrass 콘솔의 구성 요소 페이지에서도 Hello World 구성 요소를 볼 수 있습니다.

  6. 구성 요소가 생성되고 배포할 준비가 되었는지 확인합니다. 구성 요소를 만들 때의 상태는 입니다REQUESTED. 그런 다음 구성 요소를 배포할 수 있는지 AWS IoT Greengrass 확인합니다. 다음 명령을 실행하여 구성 요소 상태를 쿼리하고 구성 요소가 배포 가능한지 확인할 수 있습니다. 를 이전 arn 단계의 ARN 것으로 바꾸십시오.

    aws greengrassv2 describe-component --arn "arn:aws:greengrass:region:123456789012:components:com.example.HelloWorld:versions:1.0.0"

    구성 요소가 검증되면 응답은 구성 요소 상태가 다음과 DEPLOYABLE 같음을 나타냅니다.

    { "arn": "arn:aws:greengrass:region:123456789012:components:com.example.HelloWorld:versions:1.0.0", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "creationTimestamp": "2020-11-30T18:04:05.823Z", "publisher": "Amazon", "description": "My first Greengrass component.", "status": { "componentState": "DEPLOYABLE", "message": "NONE", "errors": {} }, "platforms": [ { "os": "linux", "architecture": "all" } ] }

이제 Hello World 구성 요소를 에서 사용할 수 있습니다. AWS IoT Greengrass이 Greengrass 코어 디바이스 또는 다른 코어 디바이스에 다시 배포할 수 있습니다.