Whitelist an IP in Amazon AWS security group from command line

To white list an IP in Amazon AWS security group using aws command line tool, run

Example

Amazon S3 CORS

To enable CORS for Amazon S3 bucket, add

aws-attach-volume

Resize Amazon EC2 Boot Disk

Once you resize disk in Amazon AWS console, it get auto resized on reboot. Some times this won’t happen, you have to manually resize the disk.

To resize disk, do the following.

1) Take a snapshot of the disk
2) Create a new server in same availability zone as current server. Lets call it tmpServer.
3) Shutdown tmpServer.
4) Shutdown the server that need disk resized. Lets call it mainServer. Make sure you have Elastic IP, if not shutting down changes IP of the server.
5) Detach the disk.
6) Attack the disk in tmpServer as /dev/xvdf
7) Start tmpServer.

Login to tempServer and do the following.

Resize Partition

Firt find the devices

In this cause /dev/xvdf is the disk that need to be resized. Current Size is approx 107 GB.

To see free disk space on this disk, run

There is 21.5GB free space on the disk.

To grow partition 1 to use up remaining disk space, run command

Verify free disk space after. Now you see there is not much free disk space left after partition 1.

Resize FileSystem

Resize file system depends on the type of file system you are using. For ext4, do the folllowing.

Check disk using e2fsck

If any errors found, you will be asked to press “y” to fix the errors. After e2fsck run, you can reszie filesystem with command

You have completed resizeing the disk. All you need to do now is

8) Shutdown tmpServer
9) Detact the disk from tmpServer (/dev/xvdf)
10) Attach the disk on original server mainServer as /dev/sda1.

11) start the mainServer.

Enable Gzip in Amazon Linux

To verify Apache module is loaded, run

Create file

Add following content

Restart Apache with

To verify gzip is working, run

You will see something like

NOTE: gzip compression only works if you have a reasonably large file. If your file is very small, then gzip won’t do anything.

See gzip

Configure Postfix to use Amazon SES

Install postfix with

Update postfix config with

Edit

Add to end of the file

In the above, replace SMTP_SERVER_NAME with your Amazon SES mail server, for example “email-smtp.us-east-1.amazonaws.com”, you can see it in your Amazon SES console.

Run

Replace SMTP_SERVER_NAME, SMTP_USERNAME and SMTP_PASSWORD with your actual credentials.

Now run

Restart postfix

You can test mail working with

For sending from Apache, you may need to set myorigin in postfix confgiration with your veirfied domain. This can be done by editing

You can verify myorgin with

Sending Mail from Amazon EC2

When sending email from Amazon EC2, it rejected with

Problem is solved by editing

Find

Replace with

Amazon SES

Amazon EFS burst credit

Create Dummy Data in Amazon EFS

Disk read/write speed in Amazon EFS depends on how much data you have on the file system.

Amazon EFS have something called BurstCreditBalance, that shows much much data balance you have available. Initially all file system have some 2 TB Burst credit, this is is for you to copy data. If you don’t copy dummy data or real data, your file system performance will degrade after your Burst credit used up.

Amazon EFS burst credit

To create dummy data, run

See Amazon EFS

Install Amazon AWS awscli

awscli is a command line tool for Amazon AWS. To install, run

You can find more details at

https://docs.aws.amazon.com/cli/latest/reference/

Once installed, you need to configure it

To sync content of a folder to Amazon S3 bucket, run

Whitelist IP in AWS security group using awscli
Amazon AWS create key pair using awscli
AWS Cloud​Formation

See aws

Cpanel Server Behind NAT – Amazon EC2

When your cpanel server is behind nat, for example Amazon EC2 where you have an internal IP and External IP.

Go to

Home > Server Configuration> Basic WebHost Manager® Setup

Enter your servers internal IP where it ask for “The IPv4 address (only one address) to use to set up shared IPv4 virtual hosts.”.

Now login to Server using SSH and run

For an Amazon EC2 server with internal IP 172.31.26.120, i added the IP in WHM > Basic WebHost Manager® Setup

Run command /scripts/build_cpnat

That associate the IP with external IP address.

This allow DNS and Apache to resolve external IP properly. With out running this command DNS server will just reply with servers internal IP address.