LoginSignup
1
2

More than 3 years have passed since last update.

AWS Cloud9 (ubuntu) のAWS CLIをversion 2 にアップデートする

Posted at

AWS Cloud9 にAWS CLI (version2)をインストールした際のメモ
OSはubuntu

現行バージョンを確認

Cloud9ではすでにAWS CLIがインストールされている

$ aws --version
aws-cli/1.18.45 Python/3.6.9 Linux/4.15.0-1065-aws botocore/1.15.45

Version 2 インストール

v2をダウンロード

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

現行バージョンをアンインストール

$ sudo pip3 uninstall awscli -y

インストール

$ sudo ./aws/install
You can now run: /usr/local/bin/aws --version
$ aws --version
aws-cli/2.0.15 Python/3.7.3 Linux/4.15.0-1065-aws botocore/2.0.0dev19

その他の設定

AWS Cloud9 はログインユーザが持つ権限の一時的な認証情報が利用できるため、AWS CLIのアカウント設定をしなくてもすぐ利用できるが、許可されるアクションが制限される。
IAM系ユーザやグループの作成などは今のままでは下記のようにエラーとなる。

$ aws iam create-group --group-name testgroup
An error occurred (InvalidClientTokenId) when calling the CreateGroup operation: The security token included in the request is invalid

回避方法として、一時的な認証(AWS managed temporary credentials)をOFFにし、代わりにロールをアタッチする。

設定方法

  1. AWS Cloud9 の Prefarences -> AWS Settings -> Credentials でAWS managed temporary credentials をOFFにする
  2. IAM のロールで ロールの作成をクリックし、ユースケースでEC2を選択
  3. アタッチするアクセス権限ポリシーを選択(例:AdministratorAccess)
  4. 作成したロールをCloud9をホストしているEC2にアタッチする
$ aws iam create-group --group-name testgroup
{
    "Group": {
        "Path": "/",
        "GroupName": "testgroup",
        "GroupId": "********************",
        "Arn": "arn:aws:iam::************:group/testgroup",
        "CreateDate": "2020-05-22T12:21:14+00:00"
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2