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.