10 Things You May Not Know About CLI
See some things about CLI that you might not know about.
Join the DZone community and get the full member experience.Join For Free
I was playing around with the CLI to see how I can incorporate it into demos and wanted to share a couple of things to remind people of its capabilities.
1. Log In as a Human
Note for interactive usage of the CLI, i.e., as a human, you can log in to the platform using your organization's domain name and password if your organization is delegating authentication to your corporate IdP. Typing the command below will open a browser for you to log in:
amplify auth login.
2. Log In as a Machine
If you want to run the CLI unattended for example, in CI/CD scripts, you can use a service account for logging into the platform
amplify auth login -client-id <DOSA Service Account> -secret-file <Private Key>
3. Select the Organization
When you have logged in, you can select the organization that you want to use when running the command line.
4. Data Returned in Different Formats
Here is the list of configured environments in my organization:
The above specifies the format of output which can be JSON or YAML.
5. Filter Returned Lists Using jq
As the return from the command line is JSON, you can manipulate and filter the resulting data using jq.
For example, the following command will get the list of environments in JSON but will filter the result to only have the environment that has the title " Azure Environment":
amplify central get environments -o json | jq '. | select(.title=="Azure Environment")
The output of running the above command:
6. The Resources in the Central Can Be Manipulated Easily
It's possible to update existing resources in Amplify Central by using the "apply" command. So, if you get a resource (see screenshot above), you can edit it to the necessary changes and "apply"' back to Central:
amplify central apply -f upload.json
7. As Response Format Is JSON, Use jq to Manipulate JSON
By piping the outputs of one command you can chain things together. Here we get the list of environments as JSON, find the one with the title Azure Environment and change it to "Hello world":
amplify central get environments -o json | jq '. | select(.title=="Azure
Environment")' | jq '.title="Hello world"'
8. Putting All the Above Together
Here is a script I ended up with which will change the image used for an environment (on the script - it's been a long time since I did any bash). Summary - base64 encode the contents of a file, find the environment to change with the name "cisco-b2bi" change image data and store to file 'upload.json'. Use the apply command to update the resource:
9. There Are a Lot of Resources That Can Be Manipulated
If you run the following command, you get a list of resources that can be manipulated in a similar fashion:
amplify central get
10. I Can't Think of a 10th
I can't think of a t0 - as this is about scripting then go try it out!
Published at DZone with permission of David Mckenna, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.