Exemple #1
0
        public static string GetEC2InstancesOutput(RegionEndpoint rEndpoint)
        {
            StringBuilder sb = new StringBuilder(1024);

            using (StringWriter sr = new StringWriter(sb))
            {
                IAmazonEC2 ec2 = new AmazonEC2Client();
                DescribeInstancesRequest      ec2Request  = new DescribeInstancesRequest();
                Amazon.Runtime.AWSCredentials credentials = new Amazon.Runtime.StoredProfileAWSCredentials("3rdPlayground");
                ec2 = new AmazonEC2Client(credentials, rEndpoint);

                try
                {
                    DescribeInstancesResponse ec2Response = ec2.DescribeInstances(ec2Request);
                    int numInstances = 0;
                    numInstances = ec2Response.Reservations.Count;
                    sr.WriteLine(string.Format("You have {0} Amazon EC2 instance(s) running in the {1} region.",
                                               numInstances, rEndpoint.ToString()));

                    DescribeInstancesResponse      ec2IdResponse         = ec2.DescribeInstances(ec2Request);
                    Amazon.EC2.Model.Reservation[] instanceForGettingIds = ec2IdResponse.Reservations.ToArray();
                    string[] ec2IDs = ec2Request.InstanceIds.ToArray();

                    foreach (Reservation comp in instanceForGettingIds)
                    {
                        sr.WriteLine();
                        sr.WriteLine("--- " + comp.Instances[0].InstanceId);
                    }
                }
                catch (AmazonEC2Exception ex)
                {
                    if (ex.ErrorCode != null && ex.ErrorCode.Equals("AuthFailure"))
                    {
                        sr.WriteLine("The account you are using is not signed up for Amazon EC2.");
                        sr.WriteLine("You can sign up for Amazon EC2 at http://aws.amazon.com/ec2");
                    }
                    else
                    {
                        sr.WriteLine("Caught Exception: " + ex.Message);
                        sr.WriteLine("Response Status Code: " + ex.StatusCode);
                        sr.WriteLine("Error Code: " + ex.ErrorCode);
                        sr.WriteLine("Error Type: " + ex.ErrorType);
                        sr.WriteLine("Request ID: " + ex.RequestId);
                    }
                }

                sr.WriteLine();
            }
            return(sb.ToString());
        }
Exemple #2
0
        public static string GetSimpleDBDomainsOutput(RegionEndpoint rEndpoint)
        {
            StringBuilder sb = new StringBuilder(1024);

            using (StringWriter sr = new StringWriter(sb))
            {
                IAmazonSimpleDB simpleDBClient = new AmazonSimpleDBClient();

                try
                {
                    ListDomainsResponse response = simpleDBClient.ListDomains();
                    int numDomains = 0;
                    if (response.DomainNames != null &&
                        response.DomainNames.Count > 0)
                    {
                        numDomains = response.DomainNames.Count;
                    }
                    sr.WriteLine(string.Format("You have {0} Amazon SimpleDB domain(s) in the {1} region.",
                                               numDomains, rEndpoint.ToString()));
                    sr.WriteLine();
                    sr.WriteLine();
                    //S3Bucket[] domains = response.DomainNames.ToArray();
                    //foreach ( bucket in buckets)
                    //{
                    //    sr.WriteLine("--- " + bucket.BucketName.PadRight(63) + " --- " + bucket.CreationDate);
                    //}
                }
                catch (AmazonS3Exception ex)
                {
                    if (ex.ErrorCode != null && (ex.ErrorCode.Equals("InvalidAccessKeyId") ||
                                                 ex.ErrorCode.Equals("InvalidSecurity")))
                    {
                        sr.WriteLine("Please check the provided AWS Credentials.");
                        sr.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
                    }
                    else
                    {
                        sr.WriteLine("Caught Exception: " + ex.Message);
                        sr.WriteLine("Response Status Code: " + ex.StatusCode);
                        sr.WriteLine("Error Code: " + ex.ErrorCode);
                        sr.WriteLine("Request ID: " + ex.RequestId);
                    }
                }
            }

            return(sb.ToString());
        }
Exemple #3
0
 static void Menu()
 {
     Console.WriteLine("-- Available Commands --");
     Console.WriteLine("   ?                   Help, this menu");
     Console.WriteLine("   q                   Quit the program");
     Console.WriteLine("   cls                 Clear the screen");
     Console.WriteLine("   endpoint            Set endpoint (currently " + _Endpoint + ")");
     Console.WriteLine("   access              Set access key (currently " + _AccessKey + ")");
     Console.WriteLine("   secret              Set secret key (currently " + _SecretKey + ")");
     Console.WriteLine("   region              Set AWS region (currently " + _S3Region.ToString() + ")");
     Console.WriteLine("   bucket              Set S3 bucket (currently " + _Bucket + ")");
     Console.WriteLine("   init                Initialize client (needed after changing keys or region)");
     Console.WriteLine("");
     Console.WriteLine("-- Bucket Commands --");
     Console.WriteLine("   list buckets        List buckets");
     Console.WriteLine("   list bucket         List the contents of a bucket");
     Console.WriteLine("   write bucket        Create a bucket");
     Console.WriteLine("   write bucket acl    Write a bucket's ACL");
     Console.WriteLine("   write bucket tags   Write tags to a bucket");
     Console.WriteLine("   read bucket acl     Read a bucket's ACL");
     Console.WriteLine("   read bucket tags    Read tags from a bucket");
     Console.WriteLine("   write bucket ver    Write bucket versioning");
     Console.WriteLine("   read bucket ver     Read bucket versioning");
     Console.WriteLine("   read bucket vers    Read bucket versions");
     Console.WriteLine("   delete bucket       Delete a bucket");
     Console.WriteLine("   delete bucket tags  Delete a bucket's tags");
     Console.WriteLine("   bucket exists       Check if bucket exists");
     Console.WriteLine("");
     Console.WriteLine("-- Object Commands --");
     Console.WriteLine("   write               Write an object");
     Console.WriteLine("   write acl           Write an object's ACL");
     Console.WriteLine("   write tags          Write object tags");
     Console.WriteLine("   write retention     Write object retention");
     Console.WriteLine("   read                Read an object");
     Console.WriteLine("   read acl            Read an object's ACL");
     Console.WriteLine("   read range          Read a range of bytes from an object");
     Console.WriteLine("   read tags           Read an object's tags");
     Console.WriteLine("   read retention      Read an object's retention");
     Console.WriteLine("   delete              Delete an object");
     Console.WriteLine("   delete multiple     Delete multiple objects");
     Console.WriteLine("   delete tags         Delete tags from an object");
     Console.WriteLine("   exists              Check if object exists");
     Console.WriteLine("");
 }
        public async Task <string> GetSecretAsync()
        {
            try
            {
                var request = new GetSecretValueRequest {
                    SecretId = secretId
                };
                var response = await client.GetSecretValueAsync(request);

                // Decrypts secret using the associated KMS CMK.
                // Depending on whether the secret is a string or binary, one of these fields will be populated.
                if (!string.IsNullOrEmpty(response.SecretString))
                {
                    return(response.SecretString);
                }

                using var reader = new StreamReader(response.SecretBinary);
                return(Encoding.UTF8.GetString(Convert.FromBase64String(reader.ReadToEnd())));
            }
            catch (Exception e)
            {
                throw new SecretException(secretId, region.ToString(), e);
            }
        }