How to Use the AWS Command Line Interface
This course introduces you to the AWS Command Line Interface.
- Install and configure the AWS Command Line Interface
- Manage CLI credential profiles
- Structure CLI commands
- Better control the outputted response data
- Use input functionality to make working with the CLI easier
- Those looking to get more familiar with the AWS Command Line Interface
- Have a good understanding of command line basics
- Understand some of the fundamental AWS services, such as Amazon EC2, Amazon DynamoDB, Amazon S3, and IAM
- Familiarity with JSON and YAML will help to better understand some of the practical parts of the course.
- For more information on some of these services, check out the following courseware titled:
If you’re newer to AWS, the one downside to the CLI Is that you have to get used to the syntax. You may find, at first, the console is much easier to use, because it prompts you visually, with menus, lists, and wizards.
However, the CLI has a few features to make the transition from the console a bit easier. One of these features is called CLI auto prompt. This will help prompt you to finish commands, so you don’t have to worry about getting the exact proper syntax correct as you’re typing your commands.
First, you must enable the feature. You can do this by using environment variables or changing the config file, but I’m going to do this by attaching the string –cli-auto-prompt to a command.
I’ll use the aws dynamodb create-table command, and then specify the string –cli-auto-prompt.
From here, I can view the list of parameters for this operation. I can use my arrow keys, and scroll down to the option I’m looking for, or I can start typing a particular parameter. For example, I’ll start tying table- and then it provides me a list of options to choose from.
So, you can see that it guides you through choosing the correct options and auto-fills the syntax for you.
The second feature that makes inputs easier is wizards. Often in the console, you’ll have wizards that make the setup of services like dynamoDB and Lambda a lot easier. Currently, the CLI has only a few of these wizards available for services like Lambda, DynamoDB, EventBridge, and IAM.
I’ll show you what this looks like using the IAM example, using the command aws iam wizard new-role. I’ll press enter, and it gives me a graphic interface to create my role. Then I can begin filling out the details of my new role using this GUI-type interface.
The third and final input feature is the CLI skeleton feature. This is helpful when you potentially have a lot of parameters you need to set for a command. Instead of typing out all of the parameters in the CLI command, you can save this skeleton to a file, and modify the parameters in a file instead.
So for example, I’ll type in the command aws dynamodb create-table –generate-cli-skeleton, and then save that response into a file called input-skeleton.json.
From there, you can vim into the input-skeleton.json file, and then see all of the empty parameters you can set for the table. So for example, I can edit this file directly and edit my table name to be cars. I can also delete any information that isn’t necessary, such as the secondary indexes. And then you can save this file.
I have a completed file already, called input.json that creates a table called cars. And I’ll use this file instead to execute the creation of my table. To do this, I can use the command aws dynamodb create-table –cli-input-json and then the file name file://input.json to create a new table.
All right, and it looks like my table was successfully created. To verify, I can type in the command aws dynamodb list-tables, and I can see the cars table is there. I hope some of these make your life a little easier - that's all for this one, see you next time.
Alana Layton is an experienced technical trainer, technical content developer, and cloud engineer living out of Seattle, Washington. Her career has included teaching about AWS all over the world, creating AWS content that is fun, and working in consulting. She currently holds six AWS certifications. Outside of Cloud Academy, you can find her testing her knowledge in bar trivia, reading, or training for a marathon.