Browsing the blog archives for August, 2009.

MongoDB Wildcard Query

Examples

icon

MongoDB uses regex in certain parts of their query syntax. The following is an example of how to perform a wildcard query:

db.collectionName.find( { fieldName : /.*cnn.*/ } );

This example searches the collection for all documents with a field that contains, “%cnn%”. Of course in your query you need to replace “collectionName” with the name of your collection and “fieldName” with the field you are interested in.

1 Comment

Create Amazon EC2 AMI

Examples

aws

Creating an Amazon EC2 AMI from an existing image seems like a challenging process however, it is actually fairly simple. Before looking at the steps to create the image, first have the following AWS information/files handy:

  • Access key
  • Secret Key
  • Account Number
  • Private key (e.g., pk-37BKCPZ2AVHVSYBK2WZXUQ9D4GQZEB4Q.pem)
  • Certificate (e.g., cert-38BKCPZ1BOHVSYBK4WZXUQ4D4GQZEB2Q.pem)

Next, login to your instance and make sure you have the Amazon AMI and EC2 API tools installed and available in your PATH. Also, upload your private key and certificate to the server.

Now you are ready to create your image file. First create a directory to store this image in.

E.g.

mkdir /mnt/ami

The actual AMI bundle is created by running:

ec2-bundle-vol -d /mnt/ami -k YOUR_PRIVATE_KEY -c YOUR_CERTIFICATE -u YOUR_ACCOUNT_NUMBER

note: The account number should not contain any dashes (‘-’).

Creating the bundle takes a few minutes. After the bundle has been created, it is time to upload it to S3. This is done by running:

ec2-upload-bundle -b YOUR_BUNDLE_NAME -m /mnt/ami/image.manifest.xml -a YOUR_ACCESS_KEY -s YOUR_SECRET_KEY

This walks through the files generated by the bundle command and inserts them into S3.

After your files have been uploaded, it is time to register the AMI using the following command:

ec2-register YOUR_BUNDLE_NAME/image.manifest.xml

The result of running this command is your AMI id.

E.g.

ami-323FEA

Finally, your AMI has been created, uploaded and registered and you are able to launch a new instance of your AMI.

If you need more help, there is a good video available from an Amazon employee. Additionally, take a look at the Amazon docs on the subject.

No Comments

Git Ignore Untracked Files

Config

git-logo

If you do not want to see Git messages about build directories or miscellaneous scratch files then add them to your .gitignore file. To do so, create the file, add the directories/files and then add the file to git.

E.g.

touch .gitignore

Edit the file to suit your needs and then add/commit.

git add .gitignore
git commit .gitignore
2 Comments