AWS CLI v2 has become GA (General Availability), so I tried using it immediately.

Everyone loves AWS CLI v2 became GA (General Availability) on February 11, 2020 in the early morning of Japan time! Hooray. https://aws.amazon.com/jp/blogs/developer/aws-cli-v2-is-now-generally-available/

I like the AWS CLI as much as I write a thin book on the AWS CLI. That's why I tried using it immediately.

Installation

The official guide has installation instructions for Linux, macOS, and Windows. This time, I tried it on AmazonLinux2, so I followed the Linux procedure.

Official Guide: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

install

The official guide has the following description. https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html#cliv2-linux-install

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

When I actually try it, it looks like this.

ec2-user@test ~]$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 30.6M  100 30.6M    0     0  64.1M      0 --:--:-- --:--:-- --:--:-- 64.0M
[ec2-user@test ~]$ ls
awscliv2.zip
[ec2-user@test ~]$
[ec2-user@test ~]$ unzip awscliv2.zip
Archive:  awscliv2.zip
   creating: aws/
   creating: aws/dist/
(Omission)
  inflating: aws/dist/zlib/cpython-37m-x86_64-linux-gnu/soib.cpython-37m-x86_64-linux-gnu.so
[ec2-user@test ~]$
[ec2-user@test ~]$ sudo ./aws/install
You can now run: /usr/local/bin/aws --version
[ec2-user@test ~]$
[ec2-user@test ~]$ /usr/local/bin/aws --version
aws-cli/2.0.0 Python/3.7.3 Linux/4.14.154-128.181.amzn2.x86_64 botocore/2.0.0dev4
[ec2-user@test ~]$

Try immediately.

The new features at the time of this writing are:

--Installer --This has been tried above. The difference so far is that you no longer need to pre-install a version of Python that is provided in the pre-built package and meets the prerequisites.

In this article, we'll try auto-completion of resource names and auto-prompts, wizards, and yaml output. Update SSO after trial if possible.

Resource name auto-completion

At the moment, it seems that not all services are supported. For example, it seems that Amazon EC2 and Amazon S3 bucket names, RDS, etc. are not supported in the trial. It is expected that this area will be expanded in the future.

So, it seems that the services (Amazon DynamoDB, AWS IAM, AWS Lambda) that support the wizard described later are supported, so I tried it.

[ec2-user@test ~]$ aws dynamodb describe-table --table-name <Press the TAB key>
12234            table-us-east-1
[ec2-user@test ~]$
[ec2-user@test ~]$ aws iam get-user --user-name <Press the TAB key>
cli         codecommit  hirosys
[ec2-user@test ~]$
[ec2-user@test ~]$ aws lambda get-function --function-name <Press the TAB key>
AWS-DeepRacer-Test-Reward-Function              aws-deepracer-reward-fn-********-****-****-****-************

Automatic prompt

I tried to create an Amazon VPC using the automatic prompt function.

[ec2-user@test ~]$ aws ec2 create-vpc --cli-auto-prompt
--cidr-block: 10.20.0.0/16

After specifying the required parameter --cidr-block, a list of optional parameters was displayed. image.png

By selecting ** [DONE] Parameter input finished ** at the bottom and pressing the Enter key without specifying anything, the VPC was created.

{
    "Vpc": {
        "CidrBlock": "10.20.0.0/16",
        "DhcpOptionsId": "dopt-********",
        "State": "pending",
        "VpcId": "vpc-*****************",
        "OwnerId": "************",
        "InstanceTenancy": "default",
        "Ipv6CidrBlockAssociationSet": [],
        "CidrBlockAssociationSet": [
            {
                "AssociationId": "vpc-cidr-assoc-*****************",
                "CidrBlock": "10.20.0.0/16",
                "CidrBlockState": {
                    "State": "associated"
                }
            }
        ],
        "IsDefault": false,
        "Tags": []
    }
}

I was able to create it safely.

Points of concern ...

When I ran aws ec2 describe-instances in auto-prompt mode, I couldn't run it with the following message even if I specified the instance ID in --instance-ids.

An error occurred (InvalidInstanceID.Malformed) when calling the DescribeInstances operation: Invalid id: "-"

However, it is strange that the CLI output by ** Print CLI command. ** works as intended. .. ..

Wizard

[ec2-user@test ~]$ aws lambda wizard new-function

First, specify the name of the Lambda function you want to create. Then select the runtime type and version you want to use from the list. image.png

In addition, select which role to use in the list. image.png

Then specify the zip file that contains the handler and the Lambda function, In the end, it looks like the following and executes it.

[ec2-user@test ~]$ aws lambda wizard new-function
Enter the function name: cliv2
Select the Lambda runtime
Select the role to use
Enter the handler for your function: lambda_function.lambda_handler
Enter the new location of your code zip file: cliv2_test.zip
[ec2-user@test ~]$

If you can execute it without any error, you have successfully created the Lambda function. The following is the result confirmed on the management console. image.png

It would be nice to see the runtime or role selected from the list.

Output in yaml

There may be some taste issues, but I personally find yaml easy to read, so this update is nice.

[ec2-user@test ~]$ aws ec2 describe-instances --output yaml
Reservations:
- Groups: []
  Instances:
  - AmiLaunchIndex: 0
    Architecture: x86_64
    BlockDeviceMappings:
    - DeviceName: /dev/xvda
      Ebs:
        AttachTime: '2020-02-11T14:25:47+00:00'
        DeleteOnTermination: true
        Status: attached
        VolumeId: vol-*****************
    CapacityReservationSpecification:
      CapacityReservationPreference: open
    ClientToken: ''
    CpuOptions:
      CoreCount: 1
      ThreadsPerCore: 1
    EbsOptimized: false
    EnaSupport: true
    HibernationOptions:
      Configured: false
    Hypervisor: xen
    IamInstanceProfile:
      Arn: arn:aws:iam::************:instance-profile/role-tsuyoi
      Id: *********************
    ImageId: ami-*****************
    InstanceId: i-*****************
    InstanceType: t2.micro
    KeyName: ***********
    LaunchTime: '2020-02-11T14:25:46+00:00'
    MetadataOptions:
      HttpEndpoint: enabled
      HttpPutResponseHopLimit: 1
      HttpTokens: optional
      State: applied
    Monitoring:
      State: disabled
    NetworkInterfaces:
    - Association:
        IpOwnerId: amazon
        PublicDnsName: ec2-***-***-***-***.ap-northeast-1.compute.amazonaws.com
        PublicIp: ***.***.***.***
      Attachment:

Summary

I used to like the AWS CLI, but with this v2, it's transformed into a feature that makes it even more itchy, and I feel that it's become an even more favorite feature. Why don't you take this opportunity to get in touch with the AWS CLI?

Postscript

AWS has posted an image of AWS CLI v2 on Docker Hub! It's perfect for a quick try!

https://aws.amazon.com/jp/blogs/developer/aws-cli-v2-docker-image/

Those who tried using it immediately have summarized it in Qiita! https://qiita.com/kai_kou/items/cfb7c1d6a449e0da68d1

Recommended Posts

AWS CLI v2 has become GA (General Availability), so I tried using it immediately.
AWS Lambda now supports Python so I tried it
I tried using AWS Chalice
[Python] I tried using YOLO v3
I tried using YOUTUBE Data API V3
I tried using pipenv, so a memo
I tried using AWS Rekognition's Detect Labels API
[Rails] v1.0 came out on google-cloud-vision of gem, so I tried to support it
I wanted to operate google spread sheet with AWS lambda, so I tried it [Part 2]
[Python] I immediately tried using Pylance's VS Code extension.
I tried Amazon Comprehend sentiment analysis with AWS CLI.
I tried to get an AMI using AWS Lambda
I tried to become an Ann Man using OpenCV