Configuration for accessing Amazon EC2 service
コード例 #1
0
        public static Ec2Response StartServer(DeveloperOptions developerOptions)
        {
            try
            {
                var ec2Config = new AmazonEC2Config { AuthenticationRegion = developerOptions.RegionEndpont };

                var ec2Client = new AmazonEC2Client(
                    new BasicAWSCredentials(developerOptions.AccessKey, developerOptions.SecretAccessKey), ec2Config);

                var launchRequest = new RunInstancesRequest
                {
                    ImageId = developerOptions.AmiId,
                    InstanceType = developerOptions.InstanceType,
                    MinCount = 1,
                    MaxCount = 1,
                    KeyName = developerOptions.Ec2KeyPair,
                    SecurityGroupIds = new List<string> { developerOptions.SecurityGroupId }
                };
                var launchResponse = ec2Client.RunInstances(launchRequest);
                if (launchResponse.HttpStatusCode.Equals(HttpStatusCode.OK))
                {
                    while (true)
                    {
                        var instances = ec2Client.DescribeInstances();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            // TODO
            return null;
        }
コード例 #2
0
ファイル: ClientUtils.cs プロジェクト: awithy/aws
 private static AmazonEC2Client _GetClient()
 {
     var awsAccessKeyId = "ACCESS_KEY";
     var secretAccessKey = "SECRET_ACCESS_KEY".ToCharArray();
     var awsSecretAccessKey = new SecureString();
     foreach (var secretAccessKeyChar in secretAccessKey)
         awsSecretAccessKey.AppendChar(secretAccessKeyChar);
     awsSecretAccessKey.MakeReadOnly();
     var config = new AmazonEC2Config();
     return new AmazonEC2Client(awsAccessKeyId, awsSecretAccessKey, config);
 }
コード例 #3
0
        /// <summary>
        /// Return the EC2 client
        /// </summary>
        /// <returns></returns>
        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;
        }
コード例 #4
0
ファイル: ProxyTests.cs プロジェクト: aws/aws-sdk-net
        public void TestProxySetupHostAndPortOnly()
        {
            var dummyConfig = new AmazonEC2Config();

            dummyConfig.ProxyHost = Host;
            dummyConfig.ProxyPort = Port;

            WebProxy proxy = dummyConfig.GetWebProxy();
            var address = proxy.Address;
            Assert.AreEqual(address.Host, Host);
            Assert.AreEqual(address.Port, Port);
            Assert.AreEqual(0, proxy.BypassList.Length);
            Assert.IsFalse(proxy.BypassProxyOnLocal);
        }
コード例 #5
0
ファイル: ProxyTests.cs プロジェクト: aws/aws-sdk-net
        public void TestProxySetupWithSchemedHost()
        {
            // verifies bug fix that the http:// scheme is not doubled 
            // up in the proxy address if the user specifies it when setting
            // proxy host (the bug yielded an address like http://http/host)

            var dummyConfig = new AmazonEC2Config();

            var host = string.Concat("http://", Host);
            dummyConfig.ProxyHost = host;
            dummyConfig.ProxyPort = Port;

            WebProxy proxy = dummyConfig.GetWebProxy();
            Assert.IsTrue(proxy.Address.ToString().StartsWith(host, StringComparison.OrdinalIgnoreCase));
        }
コード例 #6
0
ファイル: ProxyTests.cs プロジェクト: aws/aws-sdk-net
        public void TestProxySetupWithBypass()
        {
            var dummyConfig = new AmazonEC2Config();

            dummyConfig.ProxyHost = Host;
            dummyConfig.ProxyPort = Port;

            dummyConfig.ProxyBypassList = new List<string>(BypassList);
            dummyConfig.ProxyBypassOnLocal = true;

            WebProxy proxy = dummyConfig.GetWebProxy();
            Assert.AreEqual(BypassList.Count, proxy.BypassList.Length);
            // making assumption here that order is retained on assignment 
            // inside WebProxy - seems to be the case
            for (int i = 0; i < BypassList.Count; i++)
            {
                Assert.AreEqual(BypassList[i], proxy.BypassList[i]);
            }

            Assert.IsTrue(proxy.BypassProxyOnLocal);
        }
コード例 #7
0
 /// <summary>
 /// Create a client for the Amazon EC2 Service with the specified configuration
 /// </summary>
 /// <param name="awsAccessKey">The AWS Access Key associated with the account</param>
 /// <param name="awsSecretAccessKey">The AWS Secret Access Key associated with the account</param>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc
 /// </param>
 /// <returns>An Amazon EC2 client</returns>
 /// <remarks>
 /// </remarks>
 public static IAmazonEC2 CreateAmazonEC2Client(
     string awsAccessKey,
     string awsSecretAccessKey, AmazonEC2Config config
     )
 {
     return new AmazonEC2Client(awsAccessKey, awsSecretAccessKey, config);
 }
コード例 #8
0
 /// <summary>
 /// Create a client for the Amazon EC2 Service with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSAccessKey" value="********************"/&gt;
 ///         &lt;add key="AWSSecretKey" value="****************************************"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 /// </summary>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc</param>
 /// <returns>An Amazon EC2 client</returns>
 public static AmazonEC2 CreateAmazonEC2Client(AmazonEC2Config config)
 {
     return new AmazonEC2Client(config);
 }
コード例 #9
0
        private AmazonEC2 CreateAmazonEc2Client(Ec2Key ec2Key)
        {
            var er2Config = new AmazonEC2Config();
            AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2Key.AwsAccessKey, ec2Key.AwsSecretKey, er2Config);

            return ec2;
        }
コード例 #10
0
 /// <summary>
 /// Constructs AmazonEC2Client with AWS Access Key ID, AWS Secret Key and an
 /// AmazonEC2Client Configuration object. 
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="awsSessionToken">AWS Session Token</param>
 /// <param name="clientConfig">The AmazonEC2Client Configuration Object</param>
 public AmazonEC2Client(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonEC2Config clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }
コード例 #11
0
 /// <summary>
 /// Constructs AmazonEC2Client with AWS Credentials and an
 /// AmazonEC2Client Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonEC2Client Configuration Object</param>
 public AmazonEC2Client(AWSCredentials credentials, AmazonEC2Config clientConfig)
     : base(credentials, clientConfig)
 {
 }
コード例 #12
0
ファイル: AWSEC2Helper.cs プロジェクト: trista-lg/AWSHelpers
        private void Initialize(RegionEndpoint regionEndpoint, string AWSAcessKey, string AWSSecretKey)
        {
            // Set configuration info
            AmazonEC2Config config = new AmazonEC2Config ();
            config.Timeout = new TimeSpan (1, 0, 0);
            config.ReadWriteTimeout = new TimeSpan (1, 0, 0);
            config.RegionEndpoint = regionEndpoint;

            // Create EC2 client
            EC2client = AWSClientFactory.CreateAmazonEC2Client (
                            AWSAcessKey,
                            AWSSecretKey,
                            config);
        }
コード例 #13
0
        /// <summary>
        /// Creates AWS EC2 client
        /// </summary>
        /// <returns>AmazonEC2Client</returns>
        private AmazonEC2Client GetEc2Client()
        {
            if (vm.Region == null)
            {
                throw new InvalidRegionException("No region defined when creating EC2 client");
            }

            AmazonEC2Config config = new AmazonEC2Config();
            config.ServiceURL = vm.Region.Ec2Url;

            AmazonEC2Client client = new AmazonEC2Client(config);

            return client;
        }
コード例 #14
0
 /// <summary>
 /// Create a client for the Amazon EC2 Service with AWSCredentials and an AmazonEC2 Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc</param>
 /// <returns>An Amazon EC2 client</returns>
 /// <remarks>
 /// </remarks>
 public static IAmazonEC2 CreateAmazonEC2Client(AWSCredentials credentials, AmazonEC2Config config)
 {
     return new AmazonEC2Client(credentials, config);
 }
コード例 #15
0
 /// <summary>
 /// Constructs AmazonEC2Client with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSAccessKey" value="********************"/&gt;
 ///         &lt;add key="AWSSecretKey" value="****************************************"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonEC2 Configuration Object</param>
 public AmazonEC2Client(AmazonEC2Config config)
     : base(FallbackCredentialsFactory.GetCredentials(), config, AuthenticationTypes.User | AuthenticationTypes.Session) { }
コード例 #16
0
 /// <summary>
 /// Constructs AmazonEC2Client with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSProfileName" value="AWS Default"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonEC2Client Configuration Object</param>
 public AmazonEC2Client(AmazonEC2Config config)
     : base(FallbackCredentialsFactory.GetCredentials(), config) { }
コード例 #17
0
 /// <summary>
 /// Constructs AmazonEC2Client with AWS Credentials and an
 /// AmazonEC2Client Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonEC2Client Configuration Object</param>
 public AmazonEC2Client(AWSCredentials credentials, AmazonEC2Config clientConfig)
     : base(credentials, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }
コード例 #18
0
 /// <summary>
 /// Constructs AmazonEC2Client with AWS Access Key ID, AWS Secret Key and an
 /// AmazonEC2Client Configuration object. 
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="awsSessionToken">AWS Session Token</param>
 /// <param name="clientConfig">The AmazonEC2Client Configuration Object</param>
 public AmazonEC2Client(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonEC2Config clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig)
 {
 }
コード例 #19
0
 public EC2Helper(AwsClientDetails clientDetails, String regionURL)
 {
     AmazonEC2Config region = new AmazonEC2Config();
     region.ServiceURL = regionURL;
     Client = AWSClientFactory.CreateAmazonEC2Client(clientDetails.AwsAccessKeyId, clientDetails.AwsSecretAccessKey, region);
 }