쿠키 기본 설정 선택

당사는 사이트와 서비스를 제공하는 데 필요한 필수 쿠키 및 유사한 도구를 사용합니다. 고객이 사이트를 어떻게 사용하는지 파악하고 개선할 수 있도록 성능 쿠키를 사용해 익명의 통계를 수집합니다. 필수 쿠키는 비활성화할 수 없지만 '사용자 지정' 또는 ‘거부’를 클릭하여 성능 쿠키를 거부할 수 있습니다.

사용자가 동의하는 경우 AWS와 승인된 제3자도 쿠키를 사용하여 유용한 사이트 기능을 제공하고, 사용자의 기본 설정을 기억하고, 관련 광고를 비롯한 관련 콘텐츠를 표시합니다. 필수가 아닌 모든 쿠키를 수락하거나 거부하려면 ‘수락’ 또는 ‘거부’를 클릭하세요. 더 자세한 내용을 선택하려면 ‘사용자 정의’를 클릭하세요.

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

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

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

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

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

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

  • 각 아티팩트의 Amazon Simple Storage Service(Amazon S3)URI를 구성 요소 레시피에 추가합니다.

  • 구성 요소 레시피 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를 사용할 수 있습니다. 123456789012를 AWS 계정 ID로,를이 자습서에서 사용하는 AWS 리전 region로 바꿉니다.

    3. AWS 리전에서이 자습서에 사용할 AWS 리전을 선택합니다.

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

    5. 버킷에서 생성한 버킷을 선택하고 hello_world.py 스크립트를 버킷의 artifacts/com.example.HelloWorld/1.0.0 폴더에 업로드합니다. S3 버킷에 객체를 업로드하는 데 대한 자세한 내용은 Amazon Simple Storage Service 사용 설명서객체 업로드를 참조하세요.

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

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

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

    디바이스의 역할이 이미 S3 버킷에 대한 액세스를 허용하는 경우 이 단계를 건너뛸 수 있습니다. 그렇지 않으면 다음과 같이 액세스를 허용하는 IAM 정책을 생성하고 역할에 연결합니다.

    1. IAM 콘솔 탐색 메뉴에서 정책을 선택한 다음 정책 생성을 선택합니다.

    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. URI 각 Artifacts 섹션의 자리 표시자를 hello_world.py 객체URI의 S3로 바꿉니다.

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

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

AWS IoT Greengrass 에서 구성 요소 생성(콘솔)

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

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

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

    2. 버킷 이름에 고유한 버킷 이름을 입력합니다. 예를 들어 greengrass-component-artifacts-region-123456789012를 사용할 수 있습니다. 123456789012를 AWS 계정 ID로,를이 자습서에서 사용하는 AWS 리전 region로 바꿉니다.

    3. AWS 리전에서이 자습서에 사용할 AWS 리전을 선택합니다.

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

    5. 버킷에서 생성한 버킷을 선택하고 hello_world.py 스크립트를 버킷의 artifacts/com.example.HelloWorld/1.0.0 폴더에 업로드합니다. S3 버킷에 객체를 업로드하는 데 대한 자세한 내용은 Amazon Simple Storage Service 사용 설명서객체 업로드를 참조하세요.

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

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

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

    디바이스의 역할이 이미 S3 버킷에 대한 액세스를 허용하는 경우 이 단계를 건너뛸 수 있습니다. 그렇지 않으면 다음과 같이 액세스를 허용하는 IAM 정책을 생성하고 역할에 연결합니다.

    1. IAM 콘솔 탐색 메뉴에서 정책을 선택한 다음 정책 생성을 선택합니다.

    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. URI 각 Artifacts 섹션의 자리 표시자를 hello_world.py 객체URI의 S3로 바꿉니다.

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

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

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

    기존 S3 버킷을 사용하거나 다음 명령을 실행하여 버킷을 생성할 수 있습니다. 이 명령은 AWS 계정 ID 및 로 버킷을 생성 AWS 리전 하여 고유한 버킷 이름을 생성합니다. 123456789012를 AWS 계정 ID로 바꾸고를이 자습서에서 AWS 리전 사용하는 region로 바꿉니다.

    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-bucket을 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. 다음 명령을 실행하여 정책을 코어 디바이스 역할에 연결합니다. 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 S3URI를 구성 요소 레시피에 추가합니다.

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

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

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

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

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

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

    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 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 구성 요소를 업로드하려면
  1. 에서 S3 버킷을 사용하여 AWS IoT Greengrass 구성 요소 아티팩트 AWS 계정 를 호스팅합니다. 구성 요소를 코어 디바이스에 배포하면 디바이스가 버킷에서 구성 요소의 아티팩트를 다운로드합니다.

    기존 S3 버킷을 사용하거나 다음 명령을 실행하여 버킷을 생성할 수 있습니다. 이 명령은 AWS 계정 ID 및 로 버킷을 생성 AWS 리전 하여 고유한 버킷 이름을 생성합니다. 123456789012를 AWS 계정 ID로 바꾸고를이 자습서에서 AWS 리전 사용하는 region로 바꿉니다.

    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-bucket을 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
      aws iam create-policy \\ --policy-name MyGreengrassV2ComponentArtifactPolicy \\ --policy-document file://component-artifact-policy.json

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

    3. 다음 명령을 실행하여 정책을 코어 디바이스 역할에 연결합니다. 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
      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
    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 S3URI를 구성 요소 레시피에 추가합니다.

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

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

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

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

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

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

    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 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
    "Artifacts": [ { "URI": "s3://amzn-s3-demo-bucket/artifacts/com.example.HelloWorld/1.0.0/hello_world.py" } ]

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

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

    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" } ] } ] }
  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
    aws greengrassv2 create-component-version --inline-recipe fileb://recipes/com.example.HelloWorld-1.0.0.json

    요청에 성공하는 경우 응답은 다음 예제와 유사합니다.

    { "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 코어 디바이스 또는 다른 코어 디바이스에 다시 배포할 수 있습니다.

프라이버시사이트 이용 약관쿠키 기본 설정
© 2025, Amazon Web Services, Inc. 또는 계열사. All rights reserved.