A complex type that contains the information for each change in a change batch request.

Esempio n. 1
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();
    }
        public ChangeResourceRecordSetsResponse updateRRSet(
            string hostedZoneId, ResourceRecordSet oldRRset, ResourceRecordSet newRRset)
        {
            logger.Info("Calling ChangeResourceRecordSets");
            Change delete = new Change()
            {
                Action = Action.DELETE.ToString(),
                ResourceRecordSet = oldRRset
            };
            Change create = new Change() {
                Action = Action.CREATE.ToString(),
                ResourceRecordSet = newRRset
            };
            List<Change> changes = new List<Change>() { delete, create };

            ChangeBatch batch = new ChangeBatch() { Changes = changes };

            return client.ChangeResourceRecordSets(new ChangeResourceRecordSetsRequest(){
                HostedZoneId = hostedZoneId,
                ChangeBatch = batch
            });
        }
        private ChangeResourceRecordSetsRequest GetChangeResourceRecordSetsRequest(string hostname, string ipAddress, string action, List<HostedZone> zones)
        {
            string domain = DomainName.Parse(hostname).Domain;
            string hostedZoneId = zones.Single(z => z.Name.StartsWith(domain)).Id;

            var record = new ResourceRecord() { Value = ipAddress };

            var recordSet = new ResourceRecordSet()
                                {
                                    Name = hostname,
                                    TTL = 300, //5 min.
                                    Type = DnsRecordType.A,
                                    ResourceRecords = new List<ResourceRecord> {record}
                                };

            var change = new Change() {Action = action, ResourceRecordSet = recordSet};

            var request = new ChangeResourceRecordSetsRequest()
                          	{
                          		ChangeBatch = new ChangeBatch()
                          		              	{
                          		              		Changes = new List<Change> {change},
                          		              		Comment = string.Format("Automatically updated by {0}", this.ToString())
                          		              	},
                          		HostedZoneId = hostedZoneId
                          	};
            return request;
        }