Ejemplo n.º 1
0
        public AwsClient(AWSCredentials credentials, IStackItConfiguration configuration)
        {
            _credentials = credentials;

            _cloudFormationClient = new Lazy <IAmazonCloudFormation>(() => AWSClientFactory.CreateAmazonCloudFormationClient(_credentials));
            _ec2Client            = new Lazy <IAmazonEC2>(() => AWSClientFactory.CreateAmazonEC2Client(_credentials));
            _route53Client        = new Lazy <IAmazonRoute53>(() => AWSClientFactory.CreateAmazonRoute53Client(_credentials));
            _s3Client             = new Lazy <IAmazonS3>(() => AWSClientFactory.CreateAmazonS3Client(_credentials));
            _iamClient            = new Lazy <IAmazonIdentityManagementService>(() => AWSClientFactory.CreateAmazonIdentityManagementServiceClient(_credentials));

            _configuration = configuration;
        }
Ejemplo n.º 2
0
        public static string GetServiceOutput(string hostedZoneId)
        {
            StringBuilder sb = new StringBuilder(1024);

            using (StringWriter sr = new StringWriter(sb))
            {
                AmazonRoute53 r53      = AWSClientFactory.CreateAmazonRoute53Client();
                var           response = r53.ListResourceRecordSets(new Amazon.Route53.Model.ListResourceRecordSetsRequest
                {
                    HostedZoneId = hostedZoneId
                });

                var result = response.ListResourceRecordSetsResult;
                foreach (var record in result.ResourceRecordSets)
                {
                    if (record.Type == "NS")
                    {
                        // dns name 의 최대 길이를 구한다.
                        int maxLen = 0;
                        foreach (var rr in record.ResourceRecords)
                        {
                            maxLen = rr.Value.Length > maxLen ? rr.Value.Length : maxLen;
                        }

                        int nsWidth = maxLen + 5;
                        foreach (var rr in record.ResourceRecords)
                        {
                            // 너비를 동일하게 출력. 왼쪽 정렬
                            string format = string.Format("{{0,-{0}}}", nsWidth);
                            sr.Write(string.Format(format, rr.Value));

                            var host = Dns.GetHostEntry(rr.Value);
                            foreach (var ip in host.AddressList)
                            {
                                // ip는 왼쪽 정렬, 너비를 동일하게 출력.
                                string strIp = string.Format("{0,-18}", ip.ToString());
                                sr.Write(strIp);
                                sr.Write(", ");

                                // ping 출력
                                var ping  = new Ping();
                                var reply = ping.Send(ip);
                                sr.Write("ping: {0} msec", reply.RoundtripTime);
                            }
                            sr.WriteLine();
                        }
                    }
                }
            }
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public void Connect()
        {
            if (ec2 != null)
            {
                throw new ZAwsEWrongState("Controller is already open");
            }

            Debug.Assert(route53 == null);
            Debug.Assert(s3 == null);

            Debug.Assert(!RunMonitoring);
            Debug.Assert(MonitoringThread == null);

            ec2 = AWSClientFactory.CreateAmazonEC2Client(awsAccessKey, awsSecretKey,
                                                         new AmazonEC2Config().WithServiceURL(awsEc2ZoneUrl));

            route53 = AWSClientFactory.CreateAmazonRoute53Client(awsAccessKey, awsSecretKey,
                                                                 new AmazonRoute53Config()
            {
                ServiceURL = awsRoute53ZoneUrl
            });

            s3 = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretKey,
                                                       new AmazonS3Config().WithServiceURL(awsS3ZoneUrl));

            CloudWatch = AWSClientFactory.CreateAmazonCloudWatchClient(awsAccessKey, awsSecretKey,
                                                                       new AmazonCloudWatchConfig()
            {
                ServiceURL = awsCloudWatchZoneUrl
            });

            //Start the thread
            MonitoringThread = new Thread(new ThreadStart(MonitorFunction));
            RunMonitoring    = true;
            MonitoringThread.Start();
        }
Ejemplo n.º 4
0
 public IAmazonRoute53 CreateClient()
 {
     return(AWSClientFactory.CreateAmazonRoute53Client(AccessKey, SecretAccessKey));
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            const string awsId  = "AKIAJBEJGQLMJAGQV6YQ";
            const string awsKey = "lzM+9nJXLTNauQgz15SIyQD1QzWe/4+UcPzOEEPw";

            const string domainName = "www.example.org";

            //[1] Create an Amazon Route 53 client object
            var route53Client = AWSClientFactory.CreateAmazonRoute53Client(awsId, awsKey);

            //[2] Create a hosted zone
            var zoneRequest = new CreateHostedZoneRequest {
                Name            = domainName,
                CallerReference = "my_change_request"
            };

            var zoneResponse = route53Client.CreateHostedZone(zoneRequest);

            //[3] Create a resource record set change batch
            var recordSet = new ResourceRecordSet {
                Name            = domainName,
                TTL             = 60,
                Type            = RRType.A,
                ResourceRecords = new List <ResourceRecord> {
                    new ResourceRecord {
                        Value = "192.0.2.235"
                    }
                }
            };

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

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

            //[4] Update the zone's resource record sets
            var recordsetRequest = new ChangeResourceRecordSetsRequest {
                HostedZoneId = zoneResponse.HostedZone.Id,
                ChangeBatch  = changeBatch
            };

            var recordsetResponse = route53Client.ChangeResourceRecordSets(recordsetRequest);

            //[5] Monitor the change status
            var changeRequest = new GetChangeRequest {
                Id = recordsetResponse.ChangeInfo.Id
            };

            while (route53Client.GetChange(changeRequest).ChangeInfo.Status == ChangeStatus.PENDING)
            {
                Console.WriteLine("Change is pending.");
                Thread.Sleep(15000);
            }

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