Пример #1
0
        private void WaitChangesPropagation(ChangeInfo changeInfo)
        {
            if (changeInfo.Status == ChangeStatus.INSYNC)
            {
                return;
            }

            _log.Information("Waiting for DNS changes propagation");

            var changeRequest = new GetChangeRequest(changeInfo.Id);

            while (_route53Client.GetChange(changeRequest).ChangeInfo.Status == ChangeStatus.PENDING)
            {
                Thread.Sleep(TimeSpan.FromSeconds(5d));
            }
        }
Пример #2
0
        //https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/route53-apis-intro.html
        public static void UpdateRecord()
        {
            //TODO: Better exception handling overall in the method
            SimpleLogging.WriteToLog("Time to check for update to public IP", true);
            SimpleLogging.WriteToLog("Last public IP was " + lastIP, true);
            string publicIP = GetPublicIP(ServiceConfig.GetPublicIPTries);

            SimpleLogging.WriteToLog("Current public IP is " + publicIP, true);

            if (publicIP == "")
            {
                SimpleLogging.WriteToLog("Failed to check for new public IP");
                return;
            }

            if (publicIP == lastIP)
            {
                if (ServiceConfig.WriteLogsOnlyIfIPChanged)
                {
                    SimpleLogging.WipePendingLogData();
                }
                else
                {
                    SimpleLogging.WriteToLog("Public IP address has not changed" + Environment.NewLine);
                }
                return;
            }
            SimpleLogging.WriteToLog("Contacting AWS to update public IP");
            lastIP = publicIP;

            //TODO: Better exception handling when these values aren't working
            //TODO: Confirm all users can use the APSoutheast2 endpoint
            var route53Client = new AmazonRoute53Client(ServiceConfig.AwsAccessKeyId, ServiceConfig.AwsSecretAccessKey, RegionEndpoint.APSoutheast2);

            SimpleLogging.WriteToLog("Successfully authenticated to AWS");

            var recordSet = new ResourceRecordSet()
            {
                Name            = ServiceConfig.DomainName,
                TTL             = 60,
                Type            = RRType.A, //TODO: Update so can do IPv6 records also where required
                ResourceRecords = new List <ResourceRecord>
                {
                    new ResourceRecord {
                        Value = publicIP
                    }
                }
            };

            var changeBatch = new ChangeBatch()
            {
                Changes = new List <Change>
                {
                    new Change()
                    {
                        ResourceRecordSet = recordSet,
                        Action            = ChangeAction.UPSERT
                    }
                }
            };

            var recordsetRequest = new ChangeResourceRecordSetsRequest()
            {
                HostedZoneId = ServiceConfig.HostedZoneId,
                ChangeBatch  = changeBatch
            };

            var recordsetResponse = route53Client.ChangeResourceRecordSets(recordsetRequest);

            SimpleLogging.WriteToLog("Succesfully submitted update request to AWS");

            var changeRequest = new GetChangeRequest()
            {
                Id = recordsetResponse.ChangeInfo.Id
            };

            while (ChangeStatus.PENDING == route53Client.GetChange(changeRequest).ChangeInfo.Status)
            {
                SimpleLogging.WriteToLog("Waiting for change to be INSYNC");
                Thread.Sleep(ServiceConfig.AWSGetChangeSleepTime);
            }

            SimpleLogging.WriteToLog("Succesfully updated IP address to " + publicIP + Environment.NewLine);
        }
Пример #3
0
        public static void Route53CreateAdd(string[] args)
        {
            #region Route53CreateAdd
            string domainName = "www.example.org";

            IAmazonRoute53 route53Client = new AmazonRoute53Client();

            CreateHostedZoneRequest zoneRequest = new CreateHostedZoneRequest
            {
                Name            = domainName,
                CallerReference = "my_change_request"
            };

            CreateHostedZoneResponse zoneResponse = route53Client.CreateHostedZone(zoneRequest);

            ResourceRecordSet recordSet = new ResourceRecordSet
            {
                Name            = domainName,
                TTL             = 60,
                Type            = RRType.A,
                ResourceRecords = new List <ResourceRecord> {
                    new ResourceRecord {
                        Value = "192.0.2.235"
                    }
                }
            };

            Change change1 = new Change
            {
                ResourceRecordSet = recordSet,
                Action            = ChangeAction.CREATE
            };

            ChangeBatch changeBatch = new ChangeBatch
            {
                Changes = new List <Change> {
                    change1
                }
            };

            ChangeResourceRecordSetsRequest recordsetRequest = new ChangeResourceRecordSetsRequest
            {
                HostedZoneId = zoneResponse.HostedZone.Id,
                ChangeBatch  = changeBatch
            };

            ChangeResourceRecordSetsResponse recordsetResponse = route53Client.ChangeResourceRecordSets(recordsetRequest);

            GetChangeRequest changeRequest = new GetChangeRequest
            {
                Id = recordsetResponse.ChangeInfo.Id
            };

            while (route53Client.GetChange(changeRequest).ChangeInfo.Status == ChangeStatus.PENDING)
            {
                Console.WriteLine("Change is pending.");
                Thread.Sleep(TimeSpan.FromSeconds(15));
            }
            #endregion

            Console.WriteLine("Change is complete.");
            Console.ReadKey();
        }