Example #1
0
        public static ListHostedZonesResponse GetListHostedZones(string date, string authValue)
        {
            String         url     = "https://route53.amazonaws.com/2013-04-01/hostedzone";
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.Method = "GET";
            WebHeaderCollection headers = (request as HttpWebRequest).Headers;

            ListHostedZonesResponse listHostedZonesResponse = new ListHostedZonesResponse();

            // the canonical String is the date String
            //String httpDate = GetRoute53Date();

            headers.Add("x-amz-date", date);

            // Both the following methods work!
            //String authenticationSig = GetAWSR53_SHA1AuthorizationValue(awsId, secretId, httpDate);
            headers.Add("X-Amzn-Authorization", authValue);

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                using (Stream stream = response.GetResponseStream() as Stream)
                {
                    listHostedZonesResponse = Utility.Deserialize <ListHostedZonesResponse>(stream);
                }

            return(listHostedZonesResponse);
        }
Example #2
0
        static void Main(string[] args)
        {
            string accessKeyId     = "AKIAIJFROTM7CQWW46UQ";
            string secretAccessKey = "GOTvAMVLEFXi29k4M5LTnNaHuisIrkviQEzxKEMD";

            string date      = Utility.GetRoute53Date();
            string authValue = Utility.GetAWSR53_SHA1AuthorizationValue(accessKeyId, secretAccessKey, date);

            string externalIp = Utility.GetExternalIp();

            ListHostedZonesResponse listHostedZonesResponse = API.GetListHostedZones(date, authValue);

            var hostedZone = listHostedZonesResponse.HostedZones.Where(x => x.Name == "pierrethelusma.com.").SingleOrDefault();

            ListResourceRecordSetsResponse listResourceRecordSetsResponse = API.GetListResourceRecordSets(date, authValue, hostedZone.Id);

            var resourceRecordSet = listResourceRecordSetsResponse.ResourceRecordSets.Where(x => x.Name == "home.pierrethelusma.com." && x.Type == "A").SingleOrDefault();

            ChangeResourceRecordSetsResponse changeResourceRecordSetsResponse = new ChangeResourceRecordSetsResponse();

            if (resourceRecordSet == null)
            {
                changeResourceRecordSetsResponse = API.PostChangeResourceRecordSets(date, authValue, externalIp, hostedZone.Id, "home.pierrethelusma.com.", "A", "600", "CREATE");
            }
            else
            {
                if (!resourceRecordSet.ResourceRecords.Any(x => x.Value == externalIp))
                {
                    changeResourceRecordSetsResponse = API.PostChangeResourceRecordSets(date, authValue, externalIp, hostedZone.Id, "home.pierrethelusma.com.", "A", "600", "UPSERT");
                }
            }
        }