-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.aws
More file actions
134 lines (105 loc) · 5.64 KB
/
Copy pathMakefile.aws
File metadata and controls
134 lines (105 loc) · 5.64 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#backend-vpc
AWS_SG ?= sg-002271feae348b68c
#
AWS_SUBNET_ID ?= subnet-067387b658830caa3
AMI_ID ?= ami-0c1bc246476a5572b
INSTANCE_TYPE ?= t3.medium
ROLE_NAME ?= security-scanner-ec2
KEY_PAIR ?= david-key
INSTANCE_NAME ?= david_security_scanner
TMUX_SESSION_NAME ?= $(INSTANCE_NAME)
TERRAFORM_BUCKET_NAME ?= david-terraform-remote-state-${AWS_DEFAULT_REGION}
TERRAFORM_LOCK_TABLE_NAME ?= terraform-locks
INSTANCE_ID ?= $(shell aws ec2 describe-instances --filters 'Name=tag:Name,Values=$(INSTANCE_NAME)' 'Name=instance-state-name,Values=running,stopped' --query 'Reservations[*].Instances[*].[InstanceId]' --output text)
aws-vault:
aws-vault exec default
aws-ec2-describe-instances:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[?Key==`Name`]|[0].Value,Subnet:SubnetId,InstanceType:InstanceType,State: State.Name, Ip: PrivateIpAddress }'\
--filters 'Name=instance-state-name,Values=running,stopped,stopping' --output table
aws-ec2-launch:
aws ec2 run-instances --image-id $(AMI_ID) --count 1 --instance-type $(INSTANCE_TYPE) --key-name $(KEY_PAIR) \
--security-group-ids $(AWS_SG) --subnet-id $(AWS_SUBNET_ID) --iam-instance-profile Name="$(ROLE_NAME)" \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=$(INSTANCE_NAME)}]' \
--hibernation-options Configured=true \
--block-device-mapping "[ { \"DeviceName\": \"/dev/xvda\", \"Ebs\": {\"VolumeSize\": 60 , \"Encrypted\": true} } ]"
aws-ec2-get-ids:
@echo $(INSTANCE_ID)
aws-ec2-tag:
aws ec2 create-tags --resources $(INSTANCE_ID) --tags Key=Testing,Value=true Key=Owner,Value=david;
aws-ec2-terminate:
aws ec2 terminate-instances --instance-ids $(INSTANCE_ID)
aws-ec2-stop:
aws ec2 stop-instances --instance-ids $(INSTANCE_ID)
aws-ec2-hibernate:
aws ec2 stop-instances --instance-ids $(INSTANCE_ID) --hibernate
aws-ec2-start:
aws ec2 start-instances --instance-ids $(INSTANCE_ID)
aws-ssm-connect:
aws ssm start-session --target $(INSTANCE_ID)
aws-ssh-connect:
ssh ec2-user@$(INSTANCE_ID) -i ~/.ssh/$(KEY_PAIR).pem
aws-ssh-connect-tmux:
ssh ec2-user@$(INSTANCE_ID) -i ~/.ssh/$(KEY_PAIR).pem -t "tmux new-session -s $(TMUX_SESSION_NAME) || tmux attach-session -t $(TMUX_SESSION_NAME)"
#IAM
aws-iam-role-create:
aws iam create-role --role-name $(ROLE_NAME) --assume-role-policy-document file://aws/assume-role-policy.json
${MAKE} aws-iam-role-attach-policy-ssm
${MAKE} aws-iam-role-show-attached-policy
aws iam create-instance-profile --instance-profile-name $(ROLE_NAME)
aws iam add-role-to-instance-profile --instance-profile-name $(ROLE_NAME) --role-name $(ROLE_NAME)
#aws-iam-role-create-ec2-start-stop:
# aws iam create-role --role-name ec2-start-stop --assume-role-policy-document file://aws/ec2-start-stop-policy.json
aws-iam-associate-instance-profile:
aws ec2 associate-iam-instance-profile --iam-instance-profile Name=$(ROLE_NAME) --instance-id $(INSTANCE_ID)
aws-iam-role-remove:
-aws iam delete-instance-profile --instance-profile-name $(ROLE_NAME)
-aws iam detach-role-policy --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore --role-name $(ROLE_NAME)
aws iam delete-role --role-name $(ROLE_NAME)
aws-iam-role-attach-policy-ssm:
aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore --role-name $(ROLE_NAME)
aws-iam-role-show-attached-policy:
aws iam list-attached-role-policies --role-name $(ROLE_NAME)
aws-iam-ec2-attach-role:
aws ec2 associate-iam-instance-profile --instance-id $(INSTANCE_ID) --iam-instance-profile Name=
#---------EKS-----
EKS_CLUSTER_NAME ?= kay-test
EKS_CLUSTER_NODE_GROUP_NAME ?= node-group-arm64
EKS_CLUSTER_SUBNETS ?= subnet-067387b658830caa3
EKS_CLUSTER_NODE_ROLE ?= arn:aws:iam::155136788633:role/kay-test-k8s-NodeInstanceRole-1BCTZ79K7XS16
EKS_CLUSTER_INSTANCE_TYPE ?= m7g.large
EKS_CLUSTER_AMI_TYPE ?= AL2_ARM_64
EKS_CLUSTER_ARCH ?= arm64
EKS_CLUSTER_LABELS ?= ARCH=$(EKS_CLUSTER_ARCH)
EKS_CLUSTER_TAGS ?= Name=$(EKS_CLUSTER_NAME),Arch=$(EKS_CLUSTER_ARCH)
EKS_CLUSTER_MIN_SIZE ?= 0
EKS_CLUSTER_MAX_SIZE ?= 4
EKS_CLUSTER_DESIRED_SIZE ?= 1
EKS_CLUSTER_TAINTS ?= key=ARCH,value=ARM64,effect=NO_SCHEDULE
EKS_CLUSTER_LAUNCH_TEMPLATE ?= kay-test-cluster-managednodegroup-arm64
EKS_CLUSTER_LAUNCH_TEMPLATE_VERSION ?= 1
aws-eks-node-group-create:
aws eks create-nodegroup --cluster-name $(EKS_CLUSTER_NAME) \
--nodegroup-name $(EKS_CLUSTER_NODE_GROUP_NAME) \
--subnets $(EKS_CLUSTER_SUBNETS) \
--node-role $(EKS_CLUSTER_NODE_ROLE) \
--launch-template name=$(EKS_CLUSTER_LAUNCH_TEMPLATE),version=$(EKS_CLUSTER_LAUNCH_TEMPLATE_VERSION) \
--ami-type $(EKS_CLUSTER_AMI_TYPE) \
--labels $(EKS_CLUSTER_LABELS) \
--tags $(EKS_CLUSTER_TAGS) \
--taints $(EKS_CLUSTER_TAINTS) \
--scaling-config minSize=$(EKS_CLUSTER_MIN_SIZE),maxSize=$(EKS_CLUSTER_MAX_SIZE),desiredSize=$(EKS_CLUSTER_DESIRED_SIZE)
aws-eks-node-group-delete:
aws eks delete-nodegroup --cluster-name $(EKS_CLUSTER_NAME) \
--nodegroup-name $(EKS_CLUSTER_NODE_GROUP_NAME)
aws-eks-launch-template-create:
aws ec2 create-launch-template \
--launch-template-name $(EKS_CLUSTER_LAUNCH_TEMPLATE) \
--version-description "launch templated for creating and managing managed node groups for ARM64" \
--launch-template-data '{"InstanceType": "$(EKS_CLUSTER_INSTANCE_TYPE)",\
"TagSpecifications":[{"ResourceType":"instance","Tags":[{"Key":"purpose","Value":"eks-nodes"},\
{"Key":"Name","Value":"kay-test-$(EKS_CLUSTER_NODE_GROUP_NAME)"}]}] }'
aws-eks-launch-template-delete:
aws ec2 delete-launch-template \
--launch-template-name $(EKS_CLUSTER_LAUNCH_TEMPLATE)
aws-eks-launch-template-describe:
aws ec2 describe-launch-templates --filters 'Name=launch-template-name,Values=$(EKS_CLUSTER_LAUNCH_TEMPLATE)'