[PYTHON] I am making my own aws cli

I am making my own aws cli. I'm thinking of hitting the API to understand the contents of AWS. I'm using boto3 from Python. It's also a Python practice. I don't know if it's because of that, but it's much easier to touch AWS than before.

The self-made tool specializes in browsing AWS resources and aims to be able to use it without looking at the help one by one.

What you feel with aws cli

You can see how to use aws cli by looking at help, but you have to look at help for each subcommand. There are also subcommands with a large number of parameters, so it is difficult to type commands while looking at the help. It's hard to type such a long command.

#Very long unrememberable command example
$ aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Duration \
  --dimensions 'Name=FunctionName,Value=xxxx' --start-time ... ... ...

Will I be able to do it once I get used to it? It corresponds directly to the API, so it would be nice if you knew the API.

This is the way to get to this long command.

#Find the cloudwatch API
$ aws cloudwatch help

#I found something like that. get-metric-statistics

$ aws cloudwatch get-metric-statistics help

#It's hard to have a lot of parameters ...
#What format is the date and time?
#How do you write period
#Googling a lot

$ aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Duration --start-time xxxx --end-time xxxx --period xxxx
At least one of the parameters Statistics and ExtendedStatistics must be specified.

#Eh, aren't there any required parameters?
#See help again on how to specify Statistics
$ aws cloudwatch get-metric-statistics help

$ aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Duration --start-time xxxx --end-time xxxx --period xxxx --statistics xxxx
#I finally finished it
#But I really want to specify the dimension as well. How to write

What you are aiming for with your own tools

This is the case with my own tools.

#I want to see the metrics of lambda, so first type lambda
# (Follow from cloudwatch)
$ boto3 lambda
functions
layers

#If it looks like this, select what you want to see, add it to the parameters and re-execute.
#The metrics you want to see are tied to functions, so select functions this time.

$ boto3 lambda functions
xxxx
yyyy

#A list of functions will appear, so select the function you want to see.

$ boto3 lambda functions xxxx
code
configuration
metrics

#Choose what you want to see from this

$ boto3 lambda functions xxxx metrics
duration
errors
invocations
throttles

#Choose what you want to see from this

$ boto3 lambda functions xxxx metrics duration
# see-also: aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Duration --dimensions Name=FunctionName,Value=xxxx --start-time 2019-10-10T13:03:00 --end-time 2019-10-11T13:03:00 --period 60 --statistics Average --output text
2019-10-10T13:03:00+00:00 1713.59 Milliseconds
2019-10-10T13:04:00+00:00 1736.76 Milliseconds
...

#I saw what I wanted to see.

If you want to tweak the detailed parameters and see the details, you can hit the original aws cli displayed by # see-also: above. All the necessary parameters of the original aws cli are available, so it's easy to just play with them.

that's all.

Recommended Posts

I am making my own aws cli
I made my own language. (1)
I made my own language (2)
I made my own AML
I made my own Python library
[I tried using Pythonista3] Importing my own module
I made my own primitive static site generator
I made my own parallel link robot (software version)
I made my own parallel link robot (mechanical edition)
AWS CLI installation procedure
I tried AWS CDK!
I tried AWS Iot
I touched AWS Chalice
I made my goimports
I published my own Python baseball library to Packaging & PyPI
I made my own OSS because I wanted to contribute to it