AWS Classroom notes 21/Nov/2023

AWS CLI Contd

Make the script reusable

  • We have create the following script
#!/bin/bash

REGION="us-east-1"
AZ="${REGION}a"

# This script will not 
# create vpc, rather uses existing one
VPC_ID="vpc-cd32bcb0"
# create subnet rather uses exiting one
SUBNET_ID="subnet-15ede058"
# create security groups rather uses existing
SECURITY_GROUP_IDS="sg-0bdd39a6be616d961 sg-0f67708d44b7f6cb1"
# create key pairs rather uses existing keys
KEY_NAME="id_rsa"

# will create ec2 instance of AMI of your choice
AMI_ID="ami-0fc5d935ebf8bc3bc"
INSTANCE_TYPE="t2.micro"


# Create an ec2 instance
aws ec2 run-instances \
    --instance-type ${INSTANCE_TYPE} \
    --key-name ${KEY_NAME} \
    --security-group-ids ${SECURITY_GROUP_IDS} \
    --subnet-id ${SUBNET_ID} \
    --image-id ${AMI_ID}

  • Refer Here for the changeset
  • Problems:
    • executing this script multiple times is creating multiple instances
    • Unable to pass values from external

Ability to pass values while running the script

Adding guards

  • Ensure number of arguments are 7 Refer Here for changes

Validate values passed

  • Check if the region is valid
  • To be continued in next session

References

Exercise:

  • Watch this tutorial for json Refer Here
  • how to check substrings in linux
is hello present in helloworld => linux expression => true
is hello1 present in helloworld => linux expresioon => false

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Network Integration by Acurax Social Media Branding Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube