AWS Developer Tools Blog
AWS re:Invent 2014 Recap
This year at re:Invent we had a great time meeting customers and discussing their usage of the AWS CLI. We hope everyone had a blast!
I had the opportunity to present a talk titled “Advanced Usage of the AWS CLI.” In this talk, I discussed some advanced features of the AWS CLI, and how you can leverage these features to make you more proficient at using the CLI. Some of these features were brand new.
In the talk, I presented six topics:
-
aws configure
subcommands - Using JMESPath via the
--query
command line argument - Waiters
- Input JSON templates
- The new
AssumeRole
credential provider, with and without MFA - Amazon S3 stdout/stdin streaming
Both the slides as well as the video of the talk are online, and you can check them out if you weren’t able to attend.
In the next few posts, we’ll explore some of these six topics in more depth, and in this post, we’ll explore waiters.
Waiters
One of the examples I showed in the talk was how to use the new waiters feature of the CLI to block until an AWS resource reaches a specific state. I gave an example of how you can use the aws ec2 wait
command to block until an Amazon EC2 instance reaches a running
state. I’d like to explore this topic and give you an additional example of how you can leverage waiters in the CLI when creating an Amazon DynamoDB table.
When you first create a DynamoDB table the table will enter the CREATING
state. You can use theaws dynamodb wait table-exists
command to block until the table is available.
The first thing we need to do is create a table:
$ aws dynamodb create-table --table-name waiter-demo --attribute-definitions AttributeName=foo,AttributeType=S --key-schema AttributeName=foo,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
Now if we immediately try to put an item into this DynamoDB table, we will get a ResourceNotFoundException
error:
$ aws dynamodb put-item --table-name waiter-demo --item '{"foo": {"S": "bar"}}' A client error (ResourceNotFoundException) occurred when calling the PutItem operation: Requested resource not found
In order to avoid this issue, we can use the aws dynamodb wait table-exists
command, which will not exit until the table is in the ACTIVE
state:
$ aws dynamodb wait table-exists --table-name waiter-demo
Once this command finishes, we can put an item into the DynamoDB table and then verify that this item is now available:
$ aws dynamodb put-item --table-name waiter-demo --item '{"foo": {"S": "bar"}}' $ aws dynamodb scan --table-name waiter-demo { "Count": 1, "Items": [ { "foo": { "S": "bar" } } ], "ScannedCount": 1, "ConsumedCapacity": null }
If you’re following along, you can cleanup the resource we’ve created by running:
$ aws dynamodb delete-table --table-name waiter-demo
If an AWS service provides wait commands, you’ll see them in the output of aws help
. You can also view the docs online. For DynamoDB, you can see all the available waiters, as well as the documentation for theaws dynamodb wait table-exists
command.
re:Invent 2015
We hope everyone enjoyed re:Invent 2014, and we look forward to seeing everyone again next year!