Uncategorized

Category: Uncategorized

Setting up SSL on Amazon Linux Instance under EC2

Hopefully if you do it right, you too will see a positive Qualys report after you follow these steps.

Previously, the easiest way to add an SSL certificate to an EC2 instance (and still the Amazon recommended way it appears) has been to create a certificate (free) from Amazon through the certificate manager and then adding that cert to a CloudFront or ELB instance (both of which cost money).

I’ve been successful in using LetsEncrypt to provide SSL for websites running under Windows Server in EC2 using the fantastic Windows ACME Simple (WACS) (previously known as letsencrypt-win-simple (LEWS)). If this is your need, you can always grab the lastest instance on GitHub.

I never seemed to find the correct set of steps to do this on the Amazon Linux instances. However, due to the work of Lawrence McDaniel, I discovered this blog post. He walks you through step by step on how to install mod24_ssl, CertBot (from EFF) and then how to run CertBot to create and install a LetsEncrypt SSL cert on one or more sites on your Apache-served Amazon Linux instance. He also shows you how to use crontab to set up a recurring job to renew the certificates on a regular basis (a necessity since LetsEncrypt certificates expire after 90 days.

Well done Lawrence!

BTW – crontab defaults to vi as the editor. If you aren’t used to using this beast (I know, some people love it) what you really need to know is that you press the letter i on your keyboard to enter INSERT mode so you can edit the file, hit ESC to exit the INSERT mode and then enter “:wq” (without the quotes of course) to write and quite (save and exit) or just “:q” to quit without saving your changes.

Method Chaining of Objects in C#

I’m sure that many of you c# programmers know this already but I’m posting this here more as a way to reinforce this in my own brain as I seem to forget this…
When you have an object that you want to apply a number of methods to, the order of processing will always be from the inside out.
For example:
String.Format("[{0}]", name.Trim().Replace("\"", string.Empty)); will return [Deborah ] while
String.Format("[{0}]", name.Replace("\"", string.Empty).Trim()); will return is [Deborah].

So there you have it!

Native SQL Backup/Restore in AWS RDS

Native SQL Backup And Restores on AWS RDS

Amazon recently announced the availability of native backups to and from RDS for MS SQL. This is fantastic news for those of us used to working in the SQL world. More importantly, it provides a MUCH easier way to move your SQL data into and out of your RDS instance(s).

While getting things set up to do this may take a bit of time, once you do, I think you’ll find you’ll be much happier. You only need the following things:

  1. An RDS instance of MS Sql server to backup (skip if you are just importing a .bak file into an empty instance)
  2. An RDS instance of MS Sql server to restore to (skip if you are just taking a .bak you want to store off of AWS)
  3. An S3 storage bucket to contain your .bak files
  4. An option group defined (and applied to your RDS instances) that includes the SQLSERVER_BACKUP_RESTORE option added to it (which includes configuring it for a IAM role and the S3 storage bucket)

Please note, these instructions are for accomplishing these steps using the AWS Console web site rather than the CLI or APIs. Perhaps we’ll modify this for these in the future. We also won’t cover things like creating RDS instances as we assume that if you are interested in this, you’ll already know how to do it.

First thing we want to do is to create our Options group and apply it to the db(s) in question. The easiest way is to go into the RDS Dashboard and in the left pane, click on Option Groups. You will most likely have one (or more) called default:sqlserver-xxxxx-xx-xx and it will be described as “Default option group for sqlserver-type version“. Take note that the license type (like web in my case) and the version 12.00 match the  Engine listed on your RDS instance.

Click on Create button, give it a Name, Description, and select the appropriate Engine and Major Engine Version.  Once created, select your group and click Add Option. The only Option available to you should be SQLSERVER_BACKUP_RESTORE and it will ask you to select an IAM role (or create a new one). Select one you have or create a new one. Mark Apply Immediately and then hit Add Option button to add it.

Now go to your RDS instances, select the instance you want and under Instance Actions, select Modify. Note that many of the operations we are going to do cannot be accomplished while a db is being backed up just so you know.

After you’ve got everything in place, you can now jump into MS SQL Server Management Studio (or other Query tool) and do the following:

Backup Jobs:
Note that you must be logged into the db you wish to backup:

USE dbName;
exec msdb.dbo.rds_backup_database 
@source_db_name='dbName', 
@s3_arn_to_backup_to='arn:aws:s3:::bucketname/backupname.bak',
@overwrite_S3_backup_file=1

Restore Jobs:

EXEC msdb.dbo.rds_restore_database
	@restore_db_name='dbName',
	@s3_arn_to_restore_from='arn:aws:s3:::bucketname/backupname.bak';

 

View Your Jobs:
The following will show all the tasks run on the named db, most recent first.

exec msdb.dbo.rds_task_status
	@db_name = 'dbname'
exec msdb.dbo.rds_task_status
	@task_id = X

where X is the task ID given by SQL when you started the job

Cancel a Job:

exec msdb.dbo.rds_cancel_task @task_id=X;

where X is the task ID you want to cancel. Note that this can take upwards of 5 minutes or more to complete so use wisely.

General Notes:

  • You cannot restore a backup to an RDS instance that contains the db to be restored.
  • You can’t rename the db in the target that you want to restore to either.
  • You CAN, however, delete the db and then you can restore to the same instance.
  • These aren’t super fast (backup of a 100gb db took about an hour and 15 minutes and the restore took about 40 minutes. However in most instances, I’ve found it quicker than doing a snapshot and restoring the snapshot to a new instance.

Thoughts

This particular technique saved my bacon when an RDS instance was running out of space and I couldn’t shrink it enough to make a difference. Since you can’t change the storage allocation on a MS SQL instance in RDS, you need to create a whole new instance. I used this technique to copy the db over to the new instance with the larger storage allocation much quicker than I could have otherwise.

 

 

Add a program to Send To context in Windows 8

With the move to Windows 7 and Windows 8, there are a number of new locations for folders that were very helpful and well known to support techs and SysAdmins. The Send To folder (where you could control what shows up in Explorer when you right clicked on an item and selected Send To) was one of these.

Unfortunately, for many, the location of this file is a mystery… Until now.

HowToGeek.com shows how to do this in two different ways.

One way is to run the following in a command window or Run box (WinKey + R):
shell:sendto

Simple and elegant, this should find the correct folder for the currently logged in user.

Alternatively, in a command window or Run box (WinKey + R) you can enter the following:
%UserProfile%\AppData\Roaming\Microsoft\Windows\SendTo

Just in case you needed to know…

Search Gmail by Date Range

For those of us who live in our Gmail inbox (inside of Google Apps of course) and who have done so for years know that it can be difficult to find a specific email that occurred within a specific time period; especially if it is a commonly occurring word.

My frustration at having to page through page after page of results lead me to search a little bit on the web for the answer and discovered the before: and after: search modifiers.
Read more

More Fun with php.ini: Allow WordPress Plugin to Access Data On Remote Server

Have you ever found that a WordPress plugin that works fine on one web host isn’t working as you would have expected when you move it to a new webhost? We recently experienced this with a plugin that reaches out to a remote server to collect XML data to be displayed by the plugin. The problem manifested itself as a blank page where the plugin’s shortcode SHOULD have displayed formatted version of the remote data. 

The quickest way to diagnose issues like this is to modify the wp-config.php so that the line “define(‘WP_DEBUG’, false);” reads as “define(‘WP_DEBUG’, true);” temporarily so you can view the errors that WordPress by default will hide from you.

Doing so in this case returned the following error:

Read more