SimpleDB Domains


Before you can access data in SimpleDB, you have to have a domain. Domain creation is fairly expensive in terms of time-up to 1/2 a second. Listing domains is really cheap-especially since you will normally have a maximum of 100 domains. When the application starts up, we want to check if the domains we need exist-if not, create them. Otherwise, mark an all clear so that the check doesn’t happen again. To handle all this work, we have a module named PhotoWebInit. The module instantiates a client capable of communicating with SimpleDB by reading the key and secret from configuration. Using that client, the code then checks to see if the domain we want, friseton_com, exists. OK-this code really looks to see if we have 0 domains or more. friseton_com is the first domain we need because if a user needs to be able to log in before any other domains need to exist for my application. If no domains are found, the friseton_com domain is created.

#light

 

namespace PhotoWeb_AWS

open System

open System.Web.Security

open Amazon.SimpleDB

open System.Configuration

open System.Diagnostics

 

module PhotoWebInit =

    let domainName = "friseton_com"

 

    let SimpleDBClient =

        new AmazonSimpleDBClient(ConfigurationManager.AppSettings.["AWSKey"],

            ConfigurationManager.AppSettings.["AWSSecret"])

 

    let InitializeAWS =

        let listDomains = new Model.ListDomainsRequest()

        let domainList = SimpleDBClient.ListDomains(listDomains)

        let isInitialized = match domainList.ListDomainsResult.DomainName.Count with

                                | 0  -> 

                                            let createParam = new Model.CreateDomainRequest()

                                            createParam.DomainName <- domainName

                                            let response = SimpleDBClient.CreateDomain(createParam)

                                            ()

                                | n -> (Debug.WriteLine("domain exists"))

        ()

The corresponding configuration reads as follows:

    <appSettings>

        <add key="AWSKey" value="Your AWS Key goes here"/>

        <add key="AWSSecret" value="Your AWS Secret goes here"/>

    </appSettings>

Hey, I wasn’t going to share MY keys. This thing costs money! Next time, we will look at saving and retrieving data from the domain.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: