This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##Note the below commands may need to be run as a sudo depending on the OS you are using. | |
# Updates the OPERATING SYSTEM | |
yum update -y | |
# Install EPEL, required for NGINX, note you would typically do a yum install -y epel-release but in case of | |
# AWS Linux you will need to do the following | |
amazon-linux-extras install epel -y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The following steps to be performed after you download the PEM file | |
# For windows user "Load" the key, save as private key w/o a password. Save the private key as a .ppk extension | |
# For mac and linux users you can just use the pem file | |
chmod 400 <key-file> | |
#How to ssh into the EC2 instance | |
ssh -i <key-name> ec2-user@IP-ADDRESS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find out what is running on what port in linux | |
# Lists all ports | |
netstat -l | |
# Specify a port and find out which process is using it | |
netstat -ltnp | grep -w ':80' | |
# Look for what process is running on the unix box | |
ps -ef | grep <app-name> | |
Ex: ps -eg | grep nginx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find out what is running on what port in linux | |
# Lists all ports | |
netstat -l | |
# Specify a port and find out which process is using it | |
netstat -ltnp | grep -w ':80' | |
# Look for what process is running on the unix box | |
ps -ef | grep <app-name> | |
Ex: ps -eg | grep nginx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# STOP NGINX | |
sudo systemctl stop nginx | |
#START NGINX | |
sudo systemctl start nginx | |
#To stop and then start the service again, type: | |
sudo systemctl restart nginx | |
# If you are simply making configuration changes, Nginx can often reload without dropping connections. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Content-Type: multipart/mixed; boundary="//" | |
MIME-Version: 1.0 | |
--// | |
Content-Type: text/cloud-config; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="cloud-config.txt" | |
#cloud-config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Content-Type: multipart/mixed; boundary="//" | |
MIME-Version: 1.0 | |
--// | |
Content-Type: text/cloud-config; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="cloud-config.txt" | |
#cloud-config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Launches an instance | |
# aws ec2 run-instances \ | |
# --image-id <ami-xxxxx> \ | |
# --count 1 \ | |
# --instance-type t2.micro \ | |
# --key-name <your KeyPair> \ | |
# --security-group-ids <group_id> \ | |
# --subnet-id <your subnet id> | |
aws ec2 run-instances --image-id ami-0cc96feef8c6bbff3 --count 1 --instance-type t2.micro --key-name pictolearn-ec2 --security-group-ids sg-0bc5999645783c843 --subnet-id subnet-76f2c879 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 # a development kit package in AWS | |
import os # package which runs shell commands | |
import time # package which handles date and time | |
def get_ec2_con_for_give_region(my_region): # function definition to get region | |
ec2_con_re=boto3.resource('ec2',region_name=my_region) | |
return ec2_con_re | |
def list_instances_on_my_region(ec2_con_re): # function definition to get instance in that respective region | |
for each in ec2_con_re.instances.all(): | |
print(each.id) | |
def get_instant_state(ec2_con_re,in_id): # function definition to get the state of instances in that respective region |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Id": "Policy1559630929660", | |
"Statement": [ | |
{ | |
"Sid": "Stmt1559630927924", | |
"Effect": "Allow", | |
"Principal": "*", | |
"Action": [ | |
"s3:GetObject" |
OlderNewer