Skip to content

Instantly share code, notes, and snippets.

@jeeshofone
Created October 25, 2022 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeeshofone/546f27bb894940bf90afddec25b67aa3 to your computer and use it in GitHub Desktop.
Save jeeshofone/546f27bb894940bf90afddec25b67aa3 to your computer and use it in GitHub Desktop.
Setup Cloud9 with less copy paste
#!/bin/sh
# do all the steps on this page in one script https://catalog.workshops.aws/observability/en-US/installation/using-ee/setup-cloud9
# Step 11
rm -vf ${HOME}/.aws/credentials
# Step 12
curl -sSL https://raw.githubusercontent.com/aws-samples/one-observability-demo/main/PetAdoptions/envsetup_ee.sh | bash -s stable
# Step 13
export ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account)
export AWS_REGION=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.region')
echo "export ACCOUNT_ID=${ACCOUNT_ID}" | tee -a ~/.bash_profile
echo "export AWS_REGION=${AWS_REGION}" | tee -a ~/.bash_profile
aws configure set default.region ${AWS_REGION}
aws configure get default.region
# Step 15
test -n "$AWS_REGION" && echo AWS_REGION is "$AWS_REGION" || echo AWS_REGION is not set
aws sts get-caller-identity --query Arn | grep observabilityworkshop-admin -q && echo "You're good. IAM role IS valid." || echo "IAM role NOT valid. DO NOT PROCEED."
# Step 16
cd workshopfiles/one-observability-demo/PetAdoptions/cdk/pet_stack
# Step 17
npm install
# Step 18
aws eks update-kubeconfig --name PetSite --region $AWS_REGION
kubectl get nodes
# Step 14
pip3 install --user --upgrade boto3
export instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
python -c "import boto3
import os
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2')
volume_info = ec2.describe_volumes(
Filters=[
{
'Name': 'attachment.instance-id',
'Values': [
os.getenv('instance_id')
]
}
]
)
volume_id = volume_info['Volumes'][0]['VolumeId']
try:
resize = ec2.modify_volume(
VolumeId=volume_id,
Size=30
)
print(resize)
except ClientError as e:
if e.response['Error']['Code'] == 'InvalidParameterValue':
print('ERROR MESSAGE: {}'.format(e))"
if [ $? -eq 0 ]; then
sudo reboot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment