Open14
aws cli チートシート

QuickSight
Reference
データセット取得(更新日降順で一覧取得)
aws quicksight list-data-sets --aws-account-id [Accound_id] --query 'reverse(sort_by(DataSetSummaries, &LastUpdatedTime))'
分析一覧取得
aws quicksight list-analyses --aws-account-id [Accound_id]
※[Account_id]
はiamユーザのARNのiam::
の後の数値文字列
更新日降順で一覧取得
aws quicksight list-analyses --aws-account-id [Accound_id] \
--query 'reverse(sort_by(AnalysisSummaryList, &LastUpdatedTime))'
QuickSightユーザ取得
aws quicksight list-users --aws-account-id [Accound_id] --namespace default
Adminユーザ取得
aws quicksight list-users --aws-account-id [Accound_id] \
--namespace default --query 'UserList[?Role == `AUTHOR`]'

フォルダ一覧取得
aws quicksight list-folders --aws-account-id {id}--query 'FolderSummaryList[].Name'
テーブル形式で取得
aws quicksight list-folders --aws-account-id 909287433301 --query 'FolderSummaryList[].{FolderName
:Name}' --output table

IAM
自分の情報確認
aws iam get-user
ユーザ一覧
aws iam list-users --query 'Users[].UserName'
特定ユーザの所属グループ確認
aws iam list-groups-for-user --user-name iam_user_name
グループポリシー確認
aws iam list-attached-group-policies --group-name GroupName --query 'AttachedPolicies[].PolicyArn'

IAMユーザ名、作成日、最終ログイン日をテーブル形式で表示
aws iam list-users --query 'Users[*].{Name:UserName, CreateDate:CreateDate ,LastUsed:PasswordLastU
sed}' --output table
作成日でソートして出力
※LastUsed
のようなnullが含まれている項目はソート指定不可
aws iam list-users --query 'sort_by(Users[*].{Name:UserName, CreateDate:CreateDate ,LastUsed:PasswordLastUsed}, &CreateDate)' --output table

EC2
SG一覧
aws ec2 describe-security-groups | jq '.SecurityGroups[] | [.GroupId, .GroupName, .Description]' --compact-output

sg詳細設定確認
aws ec2 describe-security-groups --group-ids sg-<sg-id>

S3
バケット一覧
aws s3 ls
バケット作成
aws s3 mb s3://new-bucket-name
バケットのデフォルト暗号化有効化
aws s3api put-bucket-encryption --bucket new-bucket-name --server-side-encryption-configuration '{
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
}'
バケット暗号化設定取得
aws s3api get-bucket-encryption --bucket new-bucket-name
{
"ServerSideEncryptionConfiguration": {
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
},
"BucketKeyEnabled": false
}
]
}
}

_SUCCEESS
を除いてローカルにcp
特定のprefixからaws s3 cp s3://bucket/prefix/ ./ --recursive --exclude '_SUCCESS' --dryrun
# dryrun
aws s3 cp s3://bucket/prefix/ ./ --recursive --exclude '_SUCCESS'

ファイル数とファイルサイズを合計して出力
aws s3 ls s3://bucket/prefix/object --recursive --human --sum
参考:

ファイルを落とさずに中身を確認
実は -
で標準出力にcpできる
aws s3 cp s3://bucket/prefix/object - | cat
jsonなら
aws s3 cp s3://bucket/prefix/object - | jq

降順にして最上位のパスを取得
grep -v
を用いて取得したいプリフィックスやオブジェクトを制御
aws s3 ls s3://bucket/base_prefix/ | grep -v '.csv' | sort -nr | head -n 1 | awk '{print $NF}'

CodeCommit
レポジトリ作成
aws codecommit create-repository \
--repository-name demo-repository \
--repository-description "this is demo repository"
CodeCommitリモートレポジトリ作成→ローカルレポジトリ作成→登録→デフォルトブランチ変更
# `レポ名変更`コメント部分は作成レポジトリ名に沿って変更すべきコマンドが存在する部分
# test-repositoryを作成したいレポジトリ名に一括置換すれば動くはず
# レポ名変更
aws --profile yasumura codecommit create-repository \
--repository-name test-repository \
--repository-description "test-repository description"
# return
# {
# "repositoryMetadata": {
# "accountId": "xxx",
# "repositoryId": "xxx",
# "repositoryName": "test-repository ",
# "repositoryDescription": "test-repository description",
# "lastModifiedDate": "2021-10-26T14:55:50.701000+00:00",
# "creationDate": "2021-10-26T14:55:50.701000+00:00",
# "cloneUrlHttp": "https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/test-repository ",
# "cloneUrlSsh": "ssh://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/test-repository ",
# "Arn": "arn:aws:codecommit:ap-northeast-1:xxxxx:test-repository "
# }
# }
echo ".ipynb_checkpoints/" >> ./.gitignore
# レポ名変更
echo "# test-repository " >> ./README.md
git init
git add .
git cm 'FirstCommit'
git branch -m master main
git cob develop
# レポ名変更
git remote add origin https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/test-repository
git push
# レポ名変更
aws codecommit update-default-branch \
--repository-name test-repository\
--default-branch-name develop

デフォルトブランチ変更
aws codecommit update-default-branch \
--repository-name demo-repository \
--default-branch-name develop

レポジトリ一覧
aws codecommit list-repositories --query 'repositories[].repositoryName'