AWS CLI code example style guide¶
Danger
The AWS CLI repository is a public GitHub repository and submitting examples before a feature launch produces issues. You must be able to run the command from the public installation source.
This page outlines the code example guidelines for AWS Command Line Interface (AWS CLI) examples as part of the contribution process.
Before you start¶
Create all examples using a plain text editor or code editor like Notepad, Notepad++, or VS Code. Do not use word processors like Word or Outlook. We suggest you use an editor where you can easily see whitespace.
Always sanitize sensitive information in your examples.
Example file (template)¶
Download the .rst
template: command-name.zip
For details on each part of the template, see the style guide. The general format of your .rst
file looks like the following:
command-name.rst
**To list the available widgets**
The following ``command-name`` example lists the available widgets in your AWS account. ::
aws awesomeservice command-name \
--parameter1 file://myfile.json \
--parameter2 value2 \
--lastparam lastvalue
Contents of ``myfile.json``::
{
"somekey": "some value"
}
Output::
{
"All of the output": "goes here",
"More Output": [
{ "arrayitem1": 1 },
{ "arrayitem2": 2 }
]
"Each indent": "Must be 4 spaces"
}
For more information, see `This is the topic title <https://link.to.the/topic/page>`__ in the *Name of your guide*.
Some commands require multiple examples to cover typical use cases. To add multiple examples for one command, copy the template and paste it in the same file following the first example. Use a different title and description to distinguish between multiple examples.
Style guide¶
General¶
Confirm your examples are real working examples that others can copy/paste without needing major changes.
CLI examples must be formatted as reStructured Text (reST).
Examples must contain only ASCII characters, they cannot contain characters such as fancy quotes or tab indenting.
a-z, 0-9, !"#$%&'()*+,-./\:;<=>?@[]^_`{}|
Do not use tab indenting. Indents should include exactly 4 spaces per level of indentation.
All examples for a command are in a singular
.rst
file. When contributing examples, confirm you are not unintentionally overwriting existing examples.Examples should be formatted for Linux terminals. If you are formatting for another operating system, such as Windows, it must be listed in the title of the example.
To keep consistency across the AWS CLI examples, set your profile’s output to
json
format. Do not explicitly include an--output
parameter in the example unless you must show the output in a format that is notjson
.Note down any AWS resources you might create for these examples. After you’re done running commands for your examples, delete any testing resources that you created to avoid any unnecessary ongoing costs.
All sections of content must have blank lines separating them from other content:
**To list users** The following ``list-users`` example lists users in the specified account ::
Sanitizing sensitive information¶
Sanitize your examples. Replace all sensitive information with placeholders such as:
Account IDs: 123456789012
If your example requires multiple account IDs, then use this pattern:
123456789111, 123456789222, 123456789333, …GUIDs: a1b2c3d4-5678-90ab-cdef-EXAMPLE11111
If your example requires multiple GUIDs, then use this pattern:
**** a1b2c3d4-5678-90ab-cdef-EXAMPLE22222, a1b2c3d4-5678-90ab-cdef-EXAMPLE33333, …Regions: us-west-2
Unless the resource can only exist in a different region.Bucket names: amzn-s3-demo-bucket
If your example requires multiple buckets, then use this pattern:
amzn-s3-demo-bucket1, amzn-s3-demo-bucket2, amzn-s3-demo-bucket3, …
Example file location¶
AWS CLI examples are located in the
/aws-cli/awscli/examples
folder in the repository. Services are organized by the command group name.
Example: The examples for theaws autoscaling-plans create-scaling-plan
command is located in theexamples/autoscaling-plans
folder.If there is no folder for the command service, create the folder named exactly after the command group and place your examples in it.
Examples for
wait
commands are in a command group’s subfolder namedwait
.
Example: Theaws ecs wait services-stable
will be in theexamples/ec2/wait
folder.
Filename¶
Name your file the exact name of your command, with the
.rst
extension.
Example: A command example oflist-user
must have a filename oflist-user.rst
Examples for
wait
commands need a file for each sub-command.
Example: If your command isaws ecs wait services-stable
, then you should have a file namedservices-stable.rst
.
Title¶
Example
**To list users**
Format the title in the form of “
To do something
”. You must surround the title with double asterisks with no spaces between the title and the asterisks.If there is more than one example in the file, number each example in the title as follows.
**Example 1: To do this one way**
**Example 2: To do it another way**
Examples should be formatted for Linux terminals. If you are formatting for another operating system, such as Windows, it must be listed in the title of the example.
**To do it another way (Windows)**
Description¶
Example
The following ``list-users`` example lists the users in the specified account. ::
The description must begin with the expression
The following ``command-name`` example ...
Any time a command or parameter name is used, it must be surrounded by two back-tick characters
``
at both the start and end.Follow the initial phrase with an active verb describing what the command does and keep it simple and present tense.
Describe how the command helps the customer complete their scenario.
The description must end with a period, followed by a space and two colons
::
If any of your examples are for the “wait” command with a sub-command: Modify the description with your sub-command name and a description of what it checks for.
Example:The following ``wait sub-command-name`` example pauses and resumes only after it can confirm that the specified table exists. ::
Command¶
Example
aws awesomeservice command-name \
--parameter1 file://myfile.json \
--parameter2 value2 \
--lastparam lastvalue
Provide your tested and working command example.
Examples should be formatted for Linux terminals. If you are formatting for another operating system, such as Windows, it must be listed in the title of the example.
Every line except the last must end with the Linux line continuation mark of a space and a backslash. The only exception is if you are documenting a command that runs only on an operating system that uses a different line continuation character.
The first line is the basic command indented 4 spaces.
Every parameter must be on its own line, indented 8 spaces, two dashes, the parameter name and the parameter value.
Use value and resource names that are more use-case oriented than “
username1
” or “mytestbucket
” while still clearly indicating what it is. Use parameter names and values that are suitable for a scenario.Do not use the
--output
parameter. Assume and usejson
output as the default unless it is critical to your example to use another style.Do not use the
--region
parameter unless it is critical to this example. Most customers set a default region in their config file and then refer to it only when really required.
File contents¶
Example
Contents of ``myfile.json``::
{
"somekey": "some value"
}
If you use a file in your example command, the contents of the file must be provided. This includes files referenced by
--cli-input-json
,--cli-input-yaml
for all parameters, and thefile://
syntax for a single parameter.The introduction line must be left aligned, with no leading spaces. The file name must have two back ticks
``
preceding and following with no spaces. Add two colons immediately after the last back tick with no spaces.Contents of ``myfile.json``::
After a blank line, enter your file content, with all indentations preserved, but with each line indented an additional 4 spaces
There must be a “contents of” section for every file your command has.
Output¶
There are two possible ways example command output is displayed:
Under normal circumstances the command produces output, sample output must be provided.
Under normal circumstances the command produces no output.
Command produces output¶
Example
Output::
{
"All of the output": "goes here",
"More Output": [
{ "arrayitem1": 1 },
{ "arrayitem2": 2 }
]
"Each indent": "Must be 4 spaces"
}
The output content must be a working example.
To keep consistency through out the CLI Reference examples, show the
json
version of the output. If it is critical to your example, you can show another output type. If you use an output type other thanjson
, then include the--output
parameter in your example command.The header line must be left aligned, with no leading spaces, and two colons immediately after the last back tick with no spaces.
Output::
Enter a blank line, and then paste your output, with each line indentation being an additional 4 spaces.
Command produces no output¶
Example
This command produces no output.
Do not include the Output::
line and instead use the following to indicate that there is no output for this command.
This command produces no output.
For more information link¶
Example
For more information, see `This is the topic title <https://link.to.the/topic/page>`__ in the *Name of the guide*.
Every example must have at least one AWS link that points the user to more information about the concepts in the example. Link to a conceptual topic in the relevant User Guide or Developer Guide that explains the resource, the operation, or the general principle that the example demonstrates.
Do not link to the API reference for the command as it’s the same generated text as the CLI reference page.
The see more information sentence is formatted as “For more information, see Topic link in the Name of the guide.”
To create the topic link, format it as follows:
`This is the topic title <https://link.to.the/topic/page>`__
The link begins with a single back tick, followed by the title text for the link.
The title text must be followed by a single space, then the
<
that introduces the link.The link URL must be between
<>
characters with no extra spaces.The
<>
must be followed by a closing back tick`
(no spaces) and two underscores.
The guide name should have a single asterisk on either side of it followed by a period.
in the *Name of the guide*.