Skip to content

Commit 18ef37f

Browse files
committedNov 9, 2016
Initial checkin
1 parent 0ec1ac6 commit 18ef37f

5 files changed

+240
-1
lines changed
 

‎README.md

+62-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,62 @@
1-
# awscli_helper
1+
# awscli_helper
2+
3+
This directory contains some scripts I created to bridge the gap that the aws-cli left behind.
4+
5+
## General
6+
### ec2-describe-instance-attributes-all.sh
7+
I don't understand why the aws-cli doesn't display all the instance attributes by default and have to list one at a time as desribed at https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instance-attribute.html so I came up with this script to display all the attributes listed below on an instance_id. The full list of attributes is listed below
8+
9+
* instanceType
10+
* kernel
11+
* ramdisk
12+
* userData
13+
* disableApiTermination
14+
* instanceInitiatedShutdownBehavior
15+
* rootDeviceName
16+
* blockDeviceMapping
17+
* productCodes
18+
* sourceDestCheck
19+
* groupSet
20+
* ebsOptimized
21+
* sriovNetSupport
22+
* enaSupport
23+
24+
example: ec2-describe-instance-attributes-all.sh instance-id region
25+
26+
## Long Resource ID testing and migration
27+
28+
The scripts in this section help with the testing and migration to the long resource id format as described here
29+
https://aws.amazon.com/blogs/aws/theyre-here-longer-ec2-resource-ids-now-available/
30+
31+
### check_role_id_format.sh
32+
This script let you check to see if the IAM role is opted in or opted out of the long resource id.
33+
34+
example: check_role_id_format.sh role regions-separated-by-comma
35+
36+
### check_user_id_format.sh
37+
This script let you check to see if the IAM user is opted in or opted out of the long resource id.
38+
39+
example: check_user_id_format.sh user regions-separated-by-comma
40+
41+
### switch_user_id_format.sh
42+
This script let you switch to the long or the short resource id of an IAM user including root user
43+
44+
Syntax: switch_user_id_format.sh regions-separated-by-comma [long|short]
45+
46+
Example:
47+
To switch an IAM user to use long id format in the us-west-1 region
48+
switch_user_id_format.sh <iam-user> us-west-1 long
49+
50+
To switch an IAM user to use short id format in the us-west-1 (avaiable until Dec 2016)
51+
switch_user_id_format.sh <iam-user> us-west-1 short
52+
53+
To switch an IAM user to use long id format in the us-west-1 and us-west-2
54+
switch_user_id_format.sh <iam-user> us-west-1,us-west-2 long
55+
56+
To switch the root user(for ASG) to use long id format in the us-west-1
57+
58+
switch_user_id_format.sh root us-west-1 long
59+
60+
After you have finished your testing and you would like to check or optIn/optOut all the users/roles etc in one shot use the migratelongerids.py script at
61+
62+
https://github.com/awslabs/ec2-migrate-longer-id

‎check_role_id_format.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -e
4+
usage() {
5+
echo "Syntax: $0 role regions-separated-by-comma"
6+
echo "For example, $0 root us-east-1,us-west-1"
7+
}
8+
9+
AWS_ACCOUNT_NUMBER=$(aws sts get-caller-identity --output text --query 'Account')
10+
11+
if [ "$1" == "" ]; then
12+
echo "Missing role id."
13+
usage
14+
exit 1
15+
elif [ "$1" != "root" ]; then
16+
ROLE="role/$1"
17+
fi
18+
19+
DEFAULT_REGIONS="eu-west-1 ap-southeast-2 us-east-1 us-west-1"
20+
if [ "$2" == "" ]; then
21+
echo "Missing AWS region. Using the following default regions $DEFAULT_REGIONS"
22+
REGIONS=$DEFAULT_REGIONS
23+
else
24+
REGIONS=$(echo $2 | sed s'/,/ /g')
25+
fi
26+
27+
echo "Checking the id format for root "
28+
echo "----------------------------------------------------"
29+
echo "AWS_ACCOUNT_NUMBER=$AWS_ACCOUNT_NUMBER"
30+
echo "REGIONS=$REGIONS"
31+
echo "ROLE=$ROLE"
32+
echo "----------------------------------------------------"
33+
for REGION in ${REGIONS}; do
34+
echo "REGION=$REGION"
35+
aws --region $REGION ec2 describe-identity-id-format --principal-arn arn:aws:iam::${AWS_ACCOUNT_NUMBER}:${ROLE} --output table
36+
done

‎check_user_id_format.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -e
4+
usage() {
5+
echo "Syntax: $0 user regions-separated-by-comma"
6+
echo "For example, $0 root us-east-1,us-west-1"
7+
}
8+
9+
AWS_ACCOUNT_NUMBER=$(aws sts get-caller-identity --output text --query 'Account')
10+
11+
if [ "$1" == "" ]; then
12+
echo "Missing user id."
13+
usage
14+
exit 1
15+
elif [ "$1" == "root" ]; then
16+
USER="root"
17+
elif [ "$1" != "root" ]; then
18+
USER="user/$1"
19+
fi
20+
21+
DEFAULT_REGIONS="eu-west-1 ap-southeast-2 us-east-1 us-west-1"
22+
if [ "$2" == "" ]; then
23+
echo "Missing AWS region. Using the following default regions $DEFAULT_REGIONS"
24+
REGIONS=$DEFAULT_REGIONS
25+
else
26+
REGIONS=$(echo $2 | sed s'/,/ /g')
27+
fi
28+
29+
echo "Checking the id format for root "
30+
echo "----------------------------------------------------"
31+
echo "AWS_ACCOUNT_NUMBER=$AWS_ACCOUNT_NUMBER"
32+
echo "REGIONS=$REGIONS"
33+
echo "USER=$USER"
34+
echo "----------------------------------------------------"
35+
for REGION in ${REGIONS}; do
36+
echo "REGION=$REGION"
37+
aws --region $REGION ec2 describe-identity-id-format --principal-arn arn:aws:iam::${AWS_ACCOUNT_NUMBER}:${USER} --output table
38+
done
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
ATTRIBUTES="
4+
instanceType
5+
kernel
6+
ramdisk
7+
userData
8+
disableApiTermination
9+
instanceInitiatedShutdownBehavior
10+
rootDeviceName
11+
blockDeviceMapping
12+
productCodes
13+
sourceDestCheck
14+
groupSet
15+
ebsOptimized
16+
sriovNetSupport
17+
enaSupport
18+
"
19+
20+
if [ "$1" == "" ]; then
21+
echo "Please provide an instance id"
22+
exit 1
23+
else
24+
INSTANCE_ID=$1
25+
fi
26+
27+
if [ "$2" == "" ]; then
28+
echo "Please provide a REGION such as us-west-1 "
29+
exit 1
30+
else
31+
REGION=$2
32+
fi
33+
34+
echo "Instance ID=$1" > $INSTANCE_ID.log
35+
for a in $ATTRIBUTES; do
36+
echo ATTRIBUTE=$a>> $INSTANCE_ID.log
37+
aws --region $REGION ec2 describe-instance-attribute --instance-id $INSTANCE_ID --attribute $a --output text >> $INSTANCE_ID.log 2>&1
38+
echo "------------------------------" >> $INSTANCE_ID.log
39+
done
40+
41+
cat $INSTANCE_ID.log | grep -v $INSTANCE_ID

‎switch_user_id_format.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
usage() {
6+
echo "Syntax: $0 user regions-separated-by-comma ID_FORMAT"
7+
echo "For example, to switch the root user in us-west-1 to long format"
8+
echo " $0 root us-west-1 long"
9+
echo "For example, to switch the root user in us-west-1 to short format"
10+
echo " $0 root us-west-1 short"
11+
}
12+
13+
AWS_ACCOUNT_NUMBER=$(aws sts get-caller-identity --output text --query 'Account')
14+
15+
if [ "$1" == "" ]; then
16+
echo "Missing user id."
17+
usage
18+
exit 1
19+
elif [ "$1" == "root" ]; then
20+
USER="root"
21+
elif [ "$1" != "root" ]; then
22+
USER="user/$1"
23+
fi
24+
25+
DEFAULT_REGIONS="eu-west-1 ap-southeast-2 us-east-1 us-west-1"
26+
if [ "$2" == "" ]; then
27+
echo "Missing AWS region."
28+
usage
29+
exit 1
30+
else
31+
REGIONS=$(echo $2 | sed s'/,/ /g')
32+
fi
33+
34+
if [ "$3" == "long" ]; then
35+
ID_FORMAT="--use-long-ids"
36+
elif [ "$3" == "short" ]; then
37+
ID_FORMAT="--no-use-long-ids"
38+
else
39+
echo "Invalid id format"
40+
usage
41+
exit 1
42+
fi
43+
44+
echo "Switch to the $ID_FORMAT id format for $USER"
45+
echo "----------------------------------------------------"
46+
echo "AWS_ACCOUNT_NUMBER=$AWS_ACCOUNT_NUMBER"
47+
echo "REGIONS=$REGIONS"
48+
echo "USER=$USER"
49+
echo "ID_FORMAT=$ID_FORMAT"
50+
echo "----------------------------------------------------"
51+
52+
RESOURCES="instance reservation snapshot volume"
53+
ARN="arn:aws:iam::$AWS_ACCOUNT_NUMBER:$USER"
54+
55+
for REGION in ${REGIONS}; do
56+
echo "REGION=$REGION"
57+
for r in ${RESOURCES}; do
58+
echo "Changing the id format for resource=$r"
59+
aws ec2 modify-identity-id-format --principal-arn $ARN --region $REGION --resource $r $ID_FORMAT
60+
done
61+
done
62+
63+
./check_user_id_format.sh $1 $2

0 commit comments

Comments
 (0)
Please sign in to comment.