Пример #1
0
        public static ChangeResourceRecordSetsResponse PostChangeResourceRecordSets(string date, string authValue, string externalIp, string hostedZoneId, string name, string type, string TTL, string action)
        {
            String         url     = "https://route53.amazonaws.com/2013-04-01" + hostedZoneId + "/rrset";
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

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

            headers.Add("x-amz-date", date);
            headers.Add("X-Amzn-Authorization", authValue);

            request.ContentType = "application/xml";

            string xmlRequest = Utility.Serialize <ChangeResourceRecordSetsRequest>(CreateChangeResourceRecordSetsRequest(name, type, TTL, externalIp, action));

            byte[] bytes = Encoding.UTF8.GetBytes(xmlRequest);

            request.ContentLength = bytes.Length;

            using (Stream putStream = request.GetRequestStream())
            {
                putStream.Write(bytes, 0, bytes.Length);
            }

            ChangeResourceRecordSetsResponse changeResourceRecordSetsResponse = new ChangeResourceRecordSetsResponse();

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

            return(changeResourceRecordSetsResponse);
        }
Пример #2
0
        static void Main(string[] args)
        {
            string accessKeyId     = "AKIAIJFROTM7CQWW46UQ";
            string secretAccessKey = "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";

            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");
                }
            }
        }