

Doc AWSSDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. [AWS](https://github.com/awsdocs/aws-doc-sdk-examples) 

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

# AWSSDK 또는 CLI와 `CreateDeployment` 함께 사용
<a name="greengrassv2_example_greengrassv2_CreateDeployment_section"></a>

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

작업 예제는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서는 컨텍스트 내에서 이 작업을 확인할 수 있습니다.
+  [AWS IoT Greengrass V2기본 사항 알아보기](greengrassv2_example_greengrassv2_Scenario_section.md) 

------
#### [ CLI ]

**AWS CLI**  
**예시 1: 배포 생성**  
다음 `create-deployment` 예시에서는 AWSIoT Greengrass 명령줄 인터페이스를 코어 디바이스에 배포합니다.  

```
aws greengrassv2 create-deployment \
    --cli-input-json {{file://cli-deployment.json}}
```
`cli-deployment.json`의 콘텐츠:  

```
{
    "targetArn": "arn:aws:iot:us-west-2:123456789012:thing/MyGreengrassCore",
    "deploymentName": "Deployment for MyGreengrassCore",
    "components": {
        "aws.greengrass.Cli": {
            "componentVersion": "2.0.3"
        }
    },
    "deploymentPolicies": {
        "failureHandlingPolicy": "DO_NOTHING",
        "componentUpdatePolicy": {
            "timeoutInSeconds": 60,
            "action": "NOTIFY_COMPONENTS"
        },
        "configurationValidationPolicy": {
            "timeoutInSeconds": 60
        }
    },
    "iotJobConfiguration": {}
}
```
출력:  

```
{
    "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"
}
```
자세한 내용은 *AWS IoT Greengrass V2 개발자 안내서*의 [배포 생성](https://docs.aws.amazon.com/greengrass/v2/developerguide/create-deployments.html)을 참조하세요.  
**예시 2: 구성 요소 구성을 업데이트하는 배포 생성**  
다음 `create-deployment` 예시에서는 AWSIoT Greengrass nucleus 구성 요소를 코어 디바이스 그룹에 배포합니다. 이 배포는 핵 구성 요소에 대해 다음 구성 업데이트를 적용합니다.  
대상 디바이스의 프록시 설정을 기본값인 프록시 없음 설정으로 재설정합니다. 대상 디바이스의 MQTT 설정을 기본값으로 재설정합니다. 핵의 JVM 옵션을 설정합니다.핵의 로깅 수준을 설정합니다.  

```
aws greengrassv2 create-deployment \
    --cli-input-json {{file://nucleus-deployment.json}}
```
`nucleus-deployment.json`의 콘텐츠:  

```
{
    "targetArn": "arn:aws:iot:us-west-2:123456789012:thinggroup/MyGreengrassCoreGroup",
    "deploymentName": "Deployment for MyGreengrassCoreGroup",
    "components": {
        "aws.greengrass.Nucleus": {
            "componentVersion": "2.0.3",
            "configurationUpdate": {
                "reset": [
                    "/networkProxy",
                    "/mqtt"
                ],
                "merge": "{\"jvmOptions\":\"-Xmx64m\",\"logging\":{\"level\":\"WARN\"}}"
            }
        }
    },
    "deploymentPolicies": {
        "failureHandlingPolicy": "ROLLBACK",
        "componentUpdatePolicy": {
            "timeoutInSeconds": 60,
            "action": "NOTIFY_COMPONENTS"
        },
        "configurationValidationPolicy": {
            "timeoutInSeconds": 60
        }
    },
    "iotJobConfiguration": {}
}
```
출력:  

```
{
    "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
    "iotJobId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222",
    "iotJobArn": "arn:aws:iot:us-west-2:123456789012:job/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222"
}
```
자세한 내용은 *AWS IoT Greengrass V2 개발자 안내서*의 [배포 생성](https://docs.aws.amazon.com/greengrass/v2/developerguide/create-deployments.html) 및 [구성 요소 구성 업로드](https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [CreateDeployment](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/greengrassv2/create-deployment.html)를 참조하세요.

------
#### [ Python ]

**SDK for Python(Boto3)**  
 GitHub에 더 많은 내용이 있습니다. [AWS 코드 예제 리포지토리](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/greengrassv2#code-examples)에서 전체 예제를 확인하고 설정 및 실행하는 방법을 알아보세요.

```
    def create_deployment(
        self,
        target_arn: str,
        deployment_name: str,
        components: dict[str, Any],
        deployment_policies: Optional[dict[str, Any]] = None,
    ) -> dict[str, Any]:
        """
        Creates a deployment targeting a thing group or individual device.

        :param target_arn: The ARN of the target thing or thing group.
        :param deployment_name: A human-readable name for the deployment.
        :param components: A map of component names to deployment configurations.
        :param deployment_policies: Optional deployment policies (failure handling, etc.).
        :return: A dictionary containing the deployment ID and IoT job details.
        """
        try:
            params = dict()
            params["targetArn"] = target_arn
            params["deploymentName"] = deployment_name
            params["components"] = components
            if deployment_policies is not None:
                params["deploymentPolicies"] = deployment_policies
            response = self.client.create_deployment(**params)
            logger.info(
                "Created deployment %s targeting %s.",
                response.get("deploymentId"),
                target_arn,
            )
            return response
        except ClientError as err:
            if err.response["Error"]["Code"] == "ValidationException":
                logger.error(
                    "Invalid deployment parameters. Check that the targetArn is a valid "
                    "thing or thing group ARN and component versions exist. %s",
                    err.response["Error"]["Message"],
                )
            raise
```
+  API 세부 정보는 *AWS SDK for Python (Boto3) API 참조*의 [CreateDeployment](https://docs.aws.amazon.com/goto/boto3/greengrassv2-2020-11-30/CreateDeployment)를 참조하세요.

------