public void run() throws IOException {
        List<Stack> stacks = opsworksUtil.getStacksByName(stackName);
        if (stacks.isEmpty()) {
            throw new IllegalArgumentException("No stack found with name '" + stackName + "'");
        }

        for (Stack stack : stacks) {
            List<App> apps = opsworksUtil.getAppsByName(stack.getStackId(), appName);
            if (apps.isEmpty()) {
                throw new IllegalArgumentException("No app found with name '" + appName + "'");
            }

            List<Instance> instances =
                    opsworks.describeInstances(new DescribeInstancesRequest().withStackId(stack.getStackId())).getInstances();
            List<String> instanceIds = new ArrayList<String>(instances.size());
            for (Instance instance : instances) {
                if (instance.getStatus().equals("online"))
                    instanceIds.add(instance.getInstanceId());
            }

            if (instanceIds.isEmpty()) {
                throw new IllegalStateException("No online instances found");
            }

            for (App app : apps) {
                CreateDeploymentRequest request = new CreateDeploymentRequest();
                request.setStackId(stack.getStackId());
                request.setAppId(app.getAppId());
                request.setCustomJson(customJsonOverride);
                request.setCommand(new DeploymentCommand().withName(command));

                if (instanceIds.size() > 0) {
                    request.setInstanceIds(instanceIds);
                }

                opsworks.createDeployment(request);
            }
        }
    }