Skip to content

Instantly share code, notes, and snippets.

View eMahtab's full-sized avatar
💭
مهتاب

Mahtab Alam eMahtab

💭
مهتاب
View GitHub Profile
@eMahtab
eMahtab / gist:f97194641f6b49f2ca7053066fec9051
Created August 26, 2018 17:27 — forked from mikepfeiffer/gist:7c949e2d04c9e51ef204fb9a7f3d2978
Userdata script to setup a basic web page with instance id and tag instance
#!/bin/bash
yum install httpd -y
/sbin/chkconfig --levels 235 httpd on
service httpd start
instanceId=$(curl http://169.254.169.254/latest/meta-data/instance-id)
region=$(curl http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
echo "<h1>$instanceId</h1>" > /var/www/html/index.html
aws ec2 create-tags --resources "$instanceId" --tags Key=Name,Value="PROD-$instanceId" --region "$region"
@eMahtab
eMahtab / gist:84dbd724c7a92619bfd3d6556e224380
Created August 26, 2018 17:26 — forked from mikepfeiffer/gist:4aea8cba143ff31fa90a33ff4818b809
How to create and complete a lifecycle hook
aws autoscaling put-lifecycle-hook \
--lifecycle-hook-name scale-out-hook \
--auto-scaling-group-name MyASG \
--lifecycle-transition autoscaling:EC2_INSTANCE_LAUNCHING
aws autoscaling complete-lifecycle-action \
--lifecycle-action-result CONTINUE \
--instance-id i-0680775fb68bc97a5 \
--lifecycle-hook-name scale-out-hook \
--auto-scaling-group-name MyASG
@eMahtab
eMahtab / Installing AWS Code Deploy Agent on EC2
Last active August 14, 2018 11:54
Installing AWS Code Deploy Agent on EC2
#!/bin/bash
sudo yum update -y
sudo yum install ruby
cd /home/ec2-user
aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' . --region us-east-1
sudo yum -y install codedeploy-agent.noarch.rpm
@eMahtab
eMahtab / gist:a4ea2ef704788ac487d17a718ccfb944
Created August 14, 2018 11:18 — forked from mikepfeiffer/gist:4d9386afdcceaf29493a
EC2 UserData script to install CodeDeploy agent
#!/bin/bash
yum install -y aws-cli
cd /home/ec2-user/
aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' . --region us-east-1
yum -y install codedeploy-agent.noarch.rpm
@eMahtab
eMahtab / ReadingWebPageContent.java
Created June 30, 2018 04:55
Reading a web page content
package net.mahtabalam;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
@eMahtab
eMahtab / Docker-Network.txt
Last active February 21, 2018 18:23
Docker-Network
docker network create -d bridge --subnet 10.0.0.1/24 mahtab-bridge
docker network inspect mahtab-bridge
docker build -t node-app1:1.0 .
docker run -d --rm -p 3000:5000 --name node-app1 --network mahtab-bridge node-app1:1.0
docker build -t node-app2:1.0 .
@eMahtab
eMahtab / Docker-Tomcat.txt
Created February 13, 2018 15:07
Running Tomcat in Docker
docker run -it --rm -p 8888:8080 tomcat:8.0
docker exec -it container_name-OR-container_id /bin/sh
@eMahtab
eMahtab / assume-role-with-API-call.py
Created December 30, 2017 07:51
assume-role-with-API-call
import boto3
# The calls to AWS STS AssumeRole must be signed with the access key ID
# and secret access key of an existing IAM user or by using existing temporary
# credentials such as those from antoher role. (You cannot call AssumeRole
# with the access key for the root account.) The credentials can be in
# environment variables or in a configuration file and will be discovered
# automatically by the boto3.client() function. For more information, see the
# Python SDK documentation:
# http://boto3.readthedocs.io/en/latest/reference/services/sts.html#client
@eMahtab
eMahtab / EC2-UserData.sh
Last active December 18, 2017 16:15
EC2 UserData
#!/bin/bash
yum install httpd -y
chkconfig httpd on
service httpd start
echo "<html><h1>Hello there</h1></html>" > /var/www/html/index.html
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template VPC_with_PublicIPs_And_DNS: Sample template that creates a VPC with DNS and public IPs enabled. Note that you are billed for the AWS resources that you use when you create a stack from this template.",
"Parameters": {
"KeyPair": {
"Description": "Name of the keypair to use for SSH access",
"Type": "String"
},
"BucketName" : {
"Description" : "Name of bucket containing application war",