forked from awslabs/awscli-aliases
-
Notifications
You must be signed in to change notification settings - Fork 1
/
alias
111 lines (87 loc) · 4.48 KB
/
alias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
[toplevel]
whoami = sts get-caller-identity
create-assume-role =
!f() {
aws iam create-role --role-name "${1}" \
--assume-role-policy-document \
"{\"Statement\":[{\
\"Action\":\"sts:AssumeRole\",\
\"Effect\":\"Allow\",\
\"Principal\":{\"Service\":\""${2}".amazonaws.com\"},\
\"Sid\":\"\"\
}],\
\"Version\":\"2012-10-17\"\
}";
}; f
running-instances = ec2 describe-instances \
--filter Name=instance-state-name,Values=running \
--output table \
--query 'Reservations[].Instances[].{ID: InstanceId,PrivateIpAddress: PrivateIpAddress,Name: Tags[?Key==`Name`].Value | [0],Type: InstanceType, Platform: Platform || `Linux`}'
ebs-volumes= ec2 describe-volumes \
--query 'Volumes[].{VolumeId: VolumeId,State: State,Size: Size,Name: Tags[0].Value,AZ: AvailabilityZone}' \
--output table
amazon-linux-amis = ec2 describe-images \
--filter \
Name=owner-alias,Values=amazon \
Name=name,Values="amzn2-ami-hvm-*" \
Name=architecture,Values=x86_64 \
Name=virtualization-type,Values=hvm \
Name=root-device-type,Values=ebs \
Name=block-device-mapping.volume-type,Values=gp2 \
--query "reverse(sort_by(Images, &CreationDate))[*].[ImageId,Name,Description]" \
--output text
list-sgs = ec2 describe-security-groups --query "SecurityGroups[].[VpcId, GroupId, GroupName]" --output text
list-igw = ec2 describe-internet-gateways \
--query "InternetGateways[].{IGW:InternetGatewayId,VpcId: Attachments[].VpcId|[0], Name: Tags[?Key=='Name'].Value |[0] }" \
--output table
list-ngw = ec2 describe-nat-gateways \
--query "NatGateways[].{VpcId:VpcId, NatGatewayId: NatGatewayId, SubnetId: SubnetId, PublicIp: NatGatewayAddresses[].PublicIp | [0], PrivateIp: NatGatewayAddresses[].PrivateIp | [0] }" \
--output table
list-vgw = ec2 describe-vpn-gateways \
--query "VpnGateways[].{VpnGatewayId: VpnGatewayId, AmazonSideAsn: AmazonSideAsn, VpcId: VpcAttachments.VpcId,Name: Tags[?Key=='Name'].Value| [0] }" \
--output table
list-vpn-connection = ec2 describe-vpn-connections \
--query "VpnConnections[].{ VpnConnectionId: VpnConnectionId, CustomerGatewayId:CustomerGatewayId,VpnGatewayId:VpnGatewayId, Name: Tags[?Key=='Name'].Value| [0] }" \
--output table
list-instance-status = ec2 describe-instance-status \
--query "InstanceStatuses[].{InstanceId: InstanceId, State: InstanceState.Name, AZ: AvailabilityZone, SystemStatus: SystemStatus.Status, InstanceStatus: InstanceStatus.Status}" \
--output table
list-vpcs = ec2 describe-vpcs \
--query \
"Vpcs[].{VpcId: VpcId, CidrBlock: CidrBlock, Name: Tags[?Key=='Name'].Value| [0], IsDefault: IsDefault}" \
--output table
list-subnets = ec2 describe-subnets \
--query "Subnets[].{AZ:AvailabilityZone,VpcId:VpcId,SubnetId:SubnetId,CidrBlock:CidrBlock, Name: Tags[?Key=='Name'].Value| [0]}" \
--output table
sg-rules = !f() { aws ec2 describe-security-groups \
--query "SecurityGroups[].IpPermissions[].[FromPort,ToPort,IpProtocol,join(',',IpRanges[].CidrIp)]" \
--group-id "$1" --output text; }; f
# List or set your region
region = !f() { [[ $# -eq 1 ]] && aws configure set region "$1" || aws configure get region; }; f
list-asg-settings = autoscaling describe-auto-scaling-groups \
--query "AutoScalingGroups[].{MDesired:DesiredCapacity, ASGName:AutoScalingGroupName, Min:MinSize, Max:MaxSize, lbname:LoadBalancerNames, LCName:LaunchConfigurationName, HealthCheckType:HealthCheckType}" \
--output table
list-asg-instances = autoscaling describe-auto-scaling-groups \
--query "AutoScalingGroups[].Instances[].{id:InstanceId, AZ:AvailabilityZone, HealthStatus:HealthStatus,LifecycleState:LifecycleState }" \
--output table
list-lc = autoscaling describe-launch-configurations \
--query "LaunchConfigurations[].{LCName:LaunchConfigurationName, ImageId:ImageId,InstanceType:InstanceType,SG:SecurityGroups[],KeyName:KeyName }" \
--output table
list-routes = ec2 describe-route-tables \
--query "RouteTables[].{RouteTableId:RouteTableId, VpcId:VpcId, Name: Tags[?Key=='Name'].Value| [0], GatewayId: Routes[].{GatewayId:GatewayId,DestinationCidrBlock: DestinationCidrBlock} } " \
--output table
# aws s3head s3://randhunt-code/template.yaml 10
s3cat =
!f() {
tmpfile=$(mktemp)
aws s3 cp $1 $tmpfile
cat "$tmpfile"
rm "$tmpfile"
}; f
s3head =
!f() {
tmpfile=$(mktemp)
aws s3 cp $1 $tmpfile
head -n $2 "$tmpfile"
rm "$tmpfile"
}; f