View a markdown version of this page

Use CreateDeployment with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use CreateDeployment with an AWS SDK or CLI

The following code examples show how to use CreateDeployment.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

CLI
AWS CLI

Example 1: To create a deployment

The following create-deployment example deploys the AWS IoT Greengrass Command Line Interface to a core device.

aws greengrassv2 create-deployment \ --cli-input-json file://cli-deployment.json

Contents of 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": {} }

Output:

{ "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }

For more information, see Create deployments in the AWS IoT Greengrass V2 Developer Guide.

Example 2: To create a deployment that updates component configurations

The following create-deployment example deploys the AWS IoT Greengrass nucleus component to a group of core devices. This deployment applies the following configuration updates for the nucleus component:

Reset the target devices' proxy settings to their default no proxy settings.Reset the target devices' MQTT settings to their defaults.Sets the JVM options for the nucleus' JVM.Sets the logging level for the nucleus.

aws greengrassv2 create-deployment \ --cli-input-json file://nucleus-deployment.json

Contents of 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": {} }

Output:

{ "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" }

For more information, see Create deployments and Update component configurations in the AWS IoT Greengrass V2 Developer Guide.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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
  • For API details, see CreateDeployment in AWS SDK for Python (Boto3) API Reference.