View a markdown version of this page

AWSSDK 또는 CLI와 CreateComponentVersion 함께 사용 - AWSSDK 코드 예제

Doc AWSSDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. AWS

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

AWSSDK 또는 CLI와 CreateComponentVersion 함께 사용

다음 코드 예제는 CreateComponentVersion의 사용 방법을 보여 줍니다.

작업 예제는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서는 컨텍스트 내에서 이 작업을 확인할 수 있습니다.

CLI
AWS CLI

예시 1: 레시피에서 구성 요소 버전 생성

다음 create-component-version 예시에서는 레시피 파일에서 Hello World 구성 요소의 버전을 생성합니다.

aws greengrassv2 create-component-version \ --inline-recipe fileb://com.example.HelloWorld-1.0.0.json

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": "echo 'Hello {configuration:/Message}'" } } ] }

출력:

{ "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "creationTimestamp": "2021-01-07T16:24:33.650000-08:00", "status": { "componentState": "REQUESTED", "message": "NONE", "errors": {} } }

자세한 내용은 AWS IoT Greengrass V2 개발자 안내서의 사용자 지정 구성 요소 생성 및 배포할 구성 요소 업로드를 참조하세요.

예제 2: AWSLambda 함수에서 구성 요소 버전을 생성하는 방법

다음 create-component-version 예제에서는 AWSLambda 함수에서 Hello World 구성 요소의 버전을 생성합니다.

aws greengrassv2 create-component-version \ --cli-input-json file://lambda-function-component.json

lambda-function-component.json의 콘텐츠:

{ "lambdaFunction": { "lambdaArn": "arn:aws:lambda:us-west-2:123456789012:function:HelloWorldPythonLambda:1", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "componentLambdaParameters": { "eventSources": [ { "topic": "hello/world/+", "type": "IOT_CORE" } ] } } }

출력:

{ "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "creationTimestamp": "2021-01-07T17:05:27.347000-08:00", "status": { "componentState": "REQUESTED", "message": "NONE", "errors": {} } }

자세한 내용은 AWSIoT Greengrass V2 개발자 안내서의 AWSLambda 함수 실행을 참조하세요.

Python
SDK for Python(Boto3)
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요.

def create_component_version( self, recipe: dict[str, Any], tags: Optional[dict[str, str]] = None ) -> dict[str, Any]: """ Creates a component version from an inline JSON recipe. :param recipe: A dictionary representing the component recipe. :param tags: Optional tags to associate with the component. :return: A dictionary containing the component version details. """ try: recipe_bytes = json.dumps(recipe).encode("utf-8") params = dict() params["inlineRecipe"] = recipe_bytes if tags is not None: params["tags"] = tags response = self.client.create_component_version(**params) logger.info( "Created component %s version %s.", response.get("componentName"), response.get("componentVersion"), ) return response except ClientError as err: if err.response["Error"]["Code"] == "ConflictException": logger.error( "A component version with the same name and version already exists. " "Use a different version number or delete the existing version first. %s", err.response["Error"]["Message"], ) raise