Skip to content

Instantly share code, notes, and snippets.

View pictolearn's full-sized avatar

Pictolearn pictolearn

  • Coimbatore, IN
View GitHub Profile
@pictolearn
pictolearn / Install_NGINX_on_EC2_instance.txt
Last active May 16, 2024 08:10
Install NGINX on EC2 instance
#!/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
@pictolearn
pictolearn / Connect_2_EC2
Last active May 13, 2019 18:41
Connecting to an EC2 instance
#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
@pictolearn
pictolearn / Unix_helper_commands
Created May 16, 2019 15:29
UNIX_HELPER_COMMANDS
# 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
@pictolearn
pictolearn / Unix_helper_commands
Created May 16, 2019 15:29
UNIX_HELPER_COMMANDS
# 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
@pictolearn
pictolearn / NGINX_Commands
Created May 17, 2019 06:54
Nginx Commands
# 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.
@pictolearn
pictolearn / CHANGE_EC2_USER_DATA
Created May 17, 2019 08:15
Change_EC2_USER_DATA
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
@pictolearn
pictolearn / CHANGE_EC2_USER_DATA
Created May 17, 2019 08:15
Change_EC2_USER_DATA
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
@pictolearn
pictolearn / Launch,list and terminate_EC2_instances_using_amzon_command_line_interface.txt
Last active June 21, 2019 08:06
Launch,list and terminate_EC2_instances_using_amzon_command_line_interface
# 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
@pictolearn
pictolearn / start_stop_ec2.py
Created May 31, 2019 14:25
python code to launch,list and terminate EC2 instances
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
{
"Version": "2012-10-17",
"Id": "Policy1559630929660",
"Statement": [
{
"Sid": "Stmt1559630927924",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"