AwsSnapshotScheduler.Ec2Helper.CreateClient C# (CSharp) Метод

CreateClient() публичный статический Метод

Return the EC2 client
public static CreateClient ( ) : AmazonEC2Client
Результат Amazon.EC2.AmazonEC2Client
        public static AmazonEC2Client CreateClient()
        {
            AmazonEC2Config config = new AmazonEC2Config();
            config.ServiceURL = "https://ec2." + Program.options.Region + ".amazonaws.com";
            //config.RegionEndpoint = RegionEndpoint.USEast1;

            AmazonEC2Client ec2 = new Amazon.EC2.AmazonEC2Client(Program.options.AccessKey, Program.options.SecretKey, config);
            //AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(Program.options.AccessKey, Program.options.SecretKey, config);

            return ec2;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Check for any snapshots set to expire -- that have a tag key of "expires" with a value that is in the past.
        /// </summary>
        public static void CheckForExpiredSnapshots()
        {
            Console.WriteLine("Checking for expired snapshots...");

            AmazonEC2 ec2 = Ec2Helper.CreateClient();

            DescribeSnapshotsRequest rq = new DescribeSnapshotsRequest();

            rq.WithOwner("self");
            rq.WithFilter(new Filter()
            {
                Name = "tag-key", Value = new List <string>()
                {
                    "expires"
                }
            });

            DescribeSnapshotsResponse rs = ec2.DescribeSnapshots(rq);

            foreach (Snapshot s in rs.DescribeSnapshotsResult.Snapshot)
            {
                string expireText = Ec2Helper.GetTagValue(s.Tag, "expires");

                DateTime expires;

                if (DateTime.TryParse(expireText, out expires))
                {
                    if (expires < DateTime.UtcNow)
                    {
                        Console.WriteLine("Deleting " + s.SnapshotId + " for " + s.VolumeId + "...");
                        Ec2Helper.DeleteSnapsot(s.SnapshotId);
                    }
                }
            }
        }
All Usage Examples Of AwsSnapshotScheduler.Ec2Helper::CreateClient