-
Notifications
You must be signed in to change notification settings - Fork 36
/
00-setup.sh
executable file
·55 lines (45 loc) · 3.34 KB
/
00-setup.sh
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
#!/bin/bash
# Install jq
sudo yum -y -q install jq
# Install awscli v2
curl -O "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
unzip -o awscli-exe-linux-x86_64.zip
sudo ./aws/install
rm awscli-exe-linux-x86_64.zip
# Install bash-completion
sudo yum -y install jq gettext bash-completion
# Configure AWS CLI
export ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account)
export TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
export AWS_REGION=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.region')
export AZS=($(aws ec2 describe-availability-zones --query 'AvailabilityZones[].ZoneName' --output text --region $AWS_REGION))
echo "export ACCOUNT_ID=${ACCOUNT_ID}" | tee -a ~/.bash_profile
echo "export AWS_REGION=${AWS_REGION}" | tee -a ~/.bash_profile
echo "export AZS=(${AZS[@]})" | tee -a ~/.bash_profile
aws configure set default.region ${AWS_REGION}
aws configure get default.region
# Configure network variables (VPC, Priv/Pub-subnets)
export MyVPC=$(aws ec2 describe-vpcs --query 'Vpcs[*].[VpcId]' --filters "Name=tag-key,Values=IsUsedForDeploy" --output text)
export PrivateSubnet1=$(aws ec2 describe-subnets --query 'Subnets[*].[SubnetId]' --filters "Name=tag-value,Values=VPC-Observability Private Subnet (AZ1)" --output text)
export PrivateSubnet2=$(aws ec2 describe-subnets --query 'Subnets[*].[SubnetId]' --filters "Name=tag-value,Values=VPC-Observability Private Subnet (AZ2)" --output text)
export PrivateSubnet3=$(aws ec2 describe-subnets --query 'Subnets[*].[SubnetId]' --filters "Name=tag-value,Values=VPC-Observability Private Subnet (AZ3)" --output text)
export PublicSubnet1=$(aws ec2 describe-subnets --query 'Subnets[*].[SubnetId]' --filters "Name=tag-value,Values=VPC-Observability Public Subnet (AZ1)" --output text)
export PublicSubnet2=$(aws ec2 describe-subnets --query 'Subnets[*].[SubnetId]' --filters "Name=tag-value,Values=VPC-Observability Public Subnet (AZ2)" --output text)
export PublicSubnet3=$(aws ec2 describe-subnets --query 'Subnets[*].[SubnetId]' --filters "Name=tag-value,Values=VPC-Observability Public Subnet (AZ3)" --output text)
echo "export MyVPC=${MyVPC}" | tee -a ~/.bash_profile
echo "export PrivateSubnet1=${PrivateSubnet1}" | tee -a ~/.bash_profile
echo "export PrivateSubnet2=${PrivateSubnet2}" | tee -a ~/.bash_profile
echo "export PrivateSubnet3=${PrivateSubnet3}" | tee -a ~/.bash_profile
echo "export PublicSubnet1=${PublicSubnet1}" | tee -a ~/.bash_profile
echo "export PublicSubnet2=${PublicSubnet2}" | tee -a ~/.bash_profile
echo "export PublicSubnet3=${PublicSubnet3}" | tee -a ~/.bash_profile
# Configure EKS Cluster kubeconfig
aws eks list-clusters --output text |
awk '{print $2}' |
while read line;
do aws eks --region $AWS_REGION update-kubeconfig --name $line;
done
# Reload bash_profile
source ~/.bash_profile
# Download lab repository
git clone https://github.com/aws-samples/observability-with-amazon-opensearch