|
| 1 | +.. _atlas-cli-automate: |
| 2 | + |
| 3 | +========================================= |
| 4 | +Automate Processes with the {+atlas-cli+} |
| 5 | +========================================= |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 2 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +To automate a process with the {+atlas-cli+} in a script, use |
| 16 | +the following resources and best practices as guidance. |
| 17 | + |
| 18 | +To learn how to connect to the {+atlas-cli+} programmatically, see |
| 19 | +the :guilabel:`Programmatic User` tabs on :ref:`connect-atlas-cli`. |
| 20 | + |
| 21 | +Resources for Automation with the {+atlas-cli+} |
| 22 | +----------------------------------------------- |
| 23 | + |
| 24 | +.. list-table:: |
| 25 | + :header-rows: 1 |
| 26 | + :widths: 40 60 |
| 27 | + |
| 28 | + * - Resource |
| 29 | + - Objective |
| 30 | + |
| 31 | + * - :ref:`atlas-cli-env-vars` |
| 32 | + - Set environment variables that you can define once and use |
| 33 | + across all of your scripts. |
| 34 | + |
| 35 | + * - :ref:`go-template-output` |
| 36 | + - Use Go templates or |json| paths to customize the output from |
| 37 | + the {+atlas-cli+}. You can include the anticipated custom output in your scripts. |
| 38 | + |
| 39 | +Best Practices for Automation with the {+atlas-cli+} |
| 40 | +---------------------------------------------------- |
| 41 | + |
| 42 | +Follow these best practices when you automate processes with the |
| 43 | +{+atlas-cli+}: |
| 44 | + |
| 45 | +Base Your Script on the Version of the {+atlas-cli+} that You Run |
| 46 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 47 | + |
| 48 | +When you create a script to automate processes, you should base the |
| 49 | +script on the version of the {+atlas-cli+} that you currently run. |
| 50 | +**Don't** build automatic upgrades for the {+atlas-cli+} into your |
| 51 | +script because new {+atlas-cli+} releases could introduce breaking |
| 52 | +changes, which could break your automated processes. |
| 53 | + |
| 54 | +Instead, check release notes for deprecated features and |
| 55 | +breaking changes before you manually upgrade your version of the |
| 56 | +{+atlas-cli+}. |
| 57 | + |
| 58 | +.. _atlas-cli-redirect-stderr: |
| 59 | + |
| 60 | +Redirect ``stderr`` |
| 61 | +~~~~~~~~~~~~~~~~~~~ |
| 62 | + |
| 63 | +The {+atlas-cli+} prints error messages and command deprecation |
| 64 | +warnings in the output for commands. These unanticipated error messages |
| 65 | +and warnings can cause issues for your automated processes that |
| 66 | +anticipate a specific output. To prevent issues, you can redirect |
| 67 | +``stderr`` to an output file in your script. |
| 68 | + |
| 69 | +For example, the following command redirects the ``stderr`` output from |
| 70 | +a script called ``myScript.sh`` to a text file called ``error.txt``: |
| 71 | + |
| 72 | +.. code-block:: |
| 73 | + |
| 74 | + myScript.sh 2> error.txt |
| 75 | + |
| 76 | +In the previous example, all error messages and deprecation warnings |
| 77 | +are stored in ``error.txt`` and don't display in the output, so |
| 78 | +they don't disrupt your automated processes. |
| 79 | + |
| 80 | +Command deprecation messages are similar to the following text: |
| 81 | + |
| 82 | +.. code-block:: |
| 83 | + |
| 84 | + Command "describe" is deprecated, Please use atlas privateEndpoints aws interfaces describe <atlasPrivateEndpointId> [--privateEndpointId privateEndpointID] [--projectId projected] |
| 85 | + |
| 86 | +Update Scripts Regularly |
| 87 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 88 | + |
| 89 | +You should regularly update your scripts to discontinue use of |
| 90 | +deprecated commands because they will be removed in future releases. |
| 91 | +You can learn which commands are deprecated from the |
| 92 | +:ref:`atlas-cli-changelog`. If you |
| 93 | +:ref:`set up a redirect file for stderr <atlas-cli-redirect-stderr>`, |
| 94 | +you can also check that file for deprecation warnings. |
| 95 | + |
| 96 | +.. toctree:: |
| 97 | + :titlesonly: |
| 98 | + |
| 99 | + /atlas-cli-env-variables |
| 100 | + /custom-output-cli |
0 commit comments