blog.area23.at - a simple url encoder/decoder

 a simple url encoder/decoder
 http://blog.area23.at

Labels

Wirtschaft (124) Österreich (96) Pressefreiheit (71) IT (52) Staatsschulden (32) code (29) EZB (23) Pensionssystem (13) music (2) France (1)

2016-04-22

AWSSDK Demo Sample in C# .NET

This article just shows, how to use some basic functions of the Amazon WebServices SDK under C# .NET with Visual Studio 2013

Pre-requesties: 



/*******************************************************************************
* Copyright 2009-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*******************************************************************************/

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;

using Amazon;
using Amazon.EC2;
using Amazon.EC2.Model;
using Amazon.EC2.Util;

using Amazon.IdentityManagement;
using Amazon.IdentityManagement.Model;

using Amazon.Auth.AccessControlPolicy;
using Amazon.Auth.AccessControlPolicy.ActionIdentifiers;

using Amazon.S3;
using Amazon.S3.Model;
using Amazon.S3.Util;

namespace AwsEC2Sample1
{
    /// <summary>
    /// This sample shows how to launch an Amazon EC2 instance with a PowerShell script that is executed when the
    /// instance becomes available and access Amazon S3.
    /// </summary>
    class Program
    {      

        static readonly string RESOURCDE_POSTFIX = DateTime.Now.Ticks.ToString();
        static readonly string SAMPLE_PREFIX = AWSConfigSettings.AWSSamplePrefix;
        static readonly string SAMPLE_NAME = SAMPLE_PREFIX +
            DateTime.Now.ToShortDateString() + "_" + DateTime.Now.ToShortTimeString().Replace(":", ".");
        static readonly string SAMPLE_LONG_UNIQUE_NAME = SAMPLE_PREFIX + RESOURCDE_POSTFIX;
        const bool CREATE_AND_SAVE_KEY_PAIR = true;


        public static void Main(string[] args)
        {

            string awsProfileName = AWSConfigSettings.AWSProfileName;

            AmazonEC2Config config = new AmazonEC2Config();
            config.ServiceURL = AWSConfigSettings.AWSServiceUrl;
            Amazon.Runtime.AWSCredentials credentials = new Amazon.Runtime.StoredProfileAWSCredentials(awsProfileName);
            // AmazonEC2Client ec2Client = new AmazonEC2Client(credentials, config);
            AmazonEC2Client ec2Client = new AmazonEC2Client();

            var bucketName = SAMPLE_LONG_UNIQUE_NAME;           

            // Get latest 2012 Base AMI
            var imageId = ImageUtilities.FindImage(ec2Client, ImageUtilities.WINDOWS_2012_BASE).ImageId;
            Console.WriteLine("Using Image ID: {0}", imageId);

            // Create an IAM role
            var instanceProfileArn = CreateInstanceProfile();
            Console.WriteLine("Created Instance Profile: {0}", instanceProfileArn);

            Thread.Sleep(15000);

            // Check existing keypairs
            string keyPairName = SAMPLE_LONG_UNIQUE_NAME;

            var dkpRequest = new DescribeKeyPairsRequest();
            var dkpResponse = ec2Client.DescribeKeyPairs(dkpRequest);
            List<KeyPairInfo> myKeyPairs = dkpResponse.KeyPairs;
            foreach (KeyPairInfo item in myKeyPairs)
            {
                Console.WriteLine("Existing key pair: " + item.KeyName);
            }

            // Create new KeyPair
            KeyPair newKeyPair = null;
            CreateKeyPairRequest newKeyRequest = new CreateKeyPairRequest() { KeyName = keyPairName };
            CreateKeyPairResponse ckpResponse = ec2Client.CreateKeyPair(newKeyRequest);
            // store the received new Key  
            newKeyPair = ckpResponse.KeyPair;
            Console.WriteLine();
            Console.WriteLine("New key: " + keyPairName);
            Console.WriteLine("fingerprint: " + newKeyPair.KeyFingerprint);
            Console.WriteLine();
            // Save the private key in a .pem file
            using (FileStream s = new FileStream(keyPairName + ".pem", FileMode.Create))
            {
                using (StreamWriter writer = new StreamWriter(s))
                {
                    writer.WriteLine(newKeyPair.KeyMaterial);
                    Console.WriteLine(newKeyPair.KeyMaterial);
                }
            }

            string secGroupId = string.Empty;
            // Create new security Group
            try
            {
                HttpStatusCode createSecGrCode = CreateSecurityGroup(ec2Client, ref secGroupId);
            }
            catch (AmazonEC2Exception ae)
            {
                if (string.Equals(ae.ErrorCode, "InvalidGroup.Duplicate", StringComparison.InvariantCulture))
                    Console.WriteLine(ae.Message);
                else throw;
            }

            // add ip ranges
            String ipSource = "0.0.0.0/0";
            List<String> ipRanges = new List<String>();
            ipRanges.Add(ipSource);

            List<IpPermission> ipPermissions = new List<IpPermission>();
            IpPermission tcpSSH = new IpPermission() { IpProtocol = "tcp", FromPort = 22, ToPort = 22, IpRanges = ipRanges };
            ipPermissions.Add(tcpSSH);
            IpPermission tcpHTTP = new IpPermission() { IpProtocol = "tcp", FromPort = 80, ToPort = 80, IpRanges = ipRanges };
            ipPermissions.Add(tcpHTTP);
            IpPermission tcpHTTPS = new IpPermission() { IpProtocol = "tcp", FromPort = 443, ToPort = 443, IpRanges = ipRanges };
            ipPermissions.Add(tcpHTTPS);
            IpPermission tcpMYSQL = new IpPermission() { IpProtocol = "tcp", FromPort = 3306, ToPort = 3306, IpRanges = ipRanges };
            ipPermissions.Add(tcpMYSQL);
            IpPermission tcpRDP = new IpPermission() { IpProtocol = "tcp", FromPort = 3389, ToPort = 3389, IpRanges = ipRanges };
            ipPermissions.Add(tcpRDP);

            try
            {
                // Authorize the ports to be used.

                AuthorizeSecurityGroupIngressRequest ipPermissionsRequest = new AuthorizeSecurityGroupIngressRequest();
                ipPermissionsRequest.IpPermissions = ipPermissions;
                ipPermissionsRequest.GroupName = SAMPLE_NAME;
                if (!string.IsNullOrEmpty(secGroupId)) {
                    ipPermissionsRequest.GroupId = secGroupId;
                }
                AuthorizeSecurityGroupIngressResponse authResp = ec2Client.AuthorizeSecurityGroupIngress(ipPermissionsRequest);
                
                Console.WriteLine("Auth SecurityGroup Request HttpStatusCode " + authResp.HttpStatusCode + " ");
                Console.WriteLine(authResp.ResponseMetadata);
            }
            catch (AmazonEC2Exception ae)
            {
                if (String.Equals(ae.ErrorCode, "InvalidPermission.Duplicate", StringComparison.InvariantCulture))
                    Console.WriteLine(ae.Message);
                else
                    throw;
            }

            // run ec2 instance request with existing or new generated keypair
            var runRequest = new RunInstancesRequest
            {
                ImageId = imageId,
                MinCount = 1,
                MaxCount = 1,
                KeyName = newKeyPair.KeyName, //keyPair.KeyName,
                IamInstanceProfile = new IamInstanceProfileSpecification { Arn = instanceProfileArn },                           
                   
                // Add the region for the S3 bucket and the name of the bucket to create
                UserData = EncodeToBase64(
                    string.Format(
                        AWSConfigSettings.POWERSHELL_S3_BUCKET_SCRIPT,
                        AWSConfigSettings.AWSRegionEndpoint.SystemName,
                        bucketName)
                    )
            };

            // add secGroupId
            if (!string.IsNullOrEmpty(secGroupId)) {
                runRequest.SecurityGroupIds.Add(secGroupId);
            }
           
            var instanceId = ec2Client.RunInstances(runRequest).Reservation.Instances[0].InstanceId;
            Console.WriteLine("Launch Instance {0}", instanceId);


            // Create the name tag
            ec2Client.CreateTags(new CreateTagsRequest
            {
                Resources = new List<string> { instanceId },
                Tags = new List<Amazon.EC2.Model.Tag> { new Amazon.EC2.Model.Tag { Key = "Name", Value = "Processor" } }
            });
            Console.WriteLine("Adding Name Tag to instance");

            // create ElastiCache Cluster
            try
            {
                Amazon.ElastiCache.AmazonElastiCacheConfig eCacheConfig = new Amazon.ElastiCache.AmazonElastiCacheConfig();
                eCacheConfig.ServiceURL = AWSConfigSettings.AWSServiceUrl;
                Amazon.ElastiCache.AmazonElastiCacheClient eCacheClient = new Amazon.ElastiCache.AmazonElastiCacheClient();
                // List<string> x = new List<string>();
                // x.Add(secGroupId);
                // Amazon.ElastiCache.Model.CreateCacheClusterRequest eCacheReq = new Amazon.ElastiCache.Model.CreateCacheClusterRequest(
                //    "cache-cluster" + SAMPLE_NAME, 2, "cache.t2.medium", "memcached", x);
                Amazon.ElastiCache.Model.CreateCacheClusterRequest eCacheReq = new Amazon.ElastiCache.Model.CreateCacheClusterRequest(
                                    "Christian", 2, "cache.t2.medium", "memcached", new List<string>());
               
                Amazon.ElastiCache.Model.CreateCacheClusterResponse eCacheResp = eCacheClient.CreateCacheCluster(eCacheReq);
                Console.WriteLine("Cache Cluster Created" + eCacheResp.HttpStatusCode.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
            }

            // rds client
            Amazon.RDS.AmazonRDSConfig rdsConf = new Amazon.RDS.AmazonRDSConfig();
            rdsConf.ServiceURL = AWSConfigSettings.AWSServiceUrl;
            Amazon.RDS.AmazonRDSClient rdsClient = new Amazon.RDS.AmazonRDSClient();
           
            // create Database Cluster with aurora DB
            string dbClusterIdentifier = string.Empty;
            try
            {
                Amazon.RDS.Model.DBCluster createdCluster =
                    CreateDBClusterRDS(rdsClient, SAMPLE_NAME, "aurora", "root", SAMPLE_LONG_UNIQUE_NAME, secGroupId, ref dbClusterIdentifier);
                Console.WriteLine("Created DBCluster with Id " + createdCluster.DBClusterIdentifier);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
            }

            Console.WriteLine("Waiting for EC2 Instance to stop");
            // The script put in the user data will shutdown the instance when it is complete.  Wait
            // till the instance has stopped which signals the script is done so the instance can be terminated.
            Instance = null;
            var instanceDescribeRequest = new DescribeInstancesRequest { InstanceIds = new List<string> { instanceId } };
            do
            {
                Thread.Sleep(10000);
                instance = ec2Client.DescribeInstances(instanceDescribeRequest).Reservations[0].Instances[0];

                if (instance.State.Name == "stopped")
                {
                    // Demonstrate how to get the Administrator password using the keypair.
                    var passwordResponse = ec2Client.GetPasswordData(new GetPasswordDataRequest
                    {
                        InstanceId = instanceId
                    });

                    // Make sure we actually got a password
                    if (passwordResponse.PasswordData != null)
                    {
                        var password = passwordResponse.GetDecryptedPassword(newKeyPair.KeyMaterial);
                        Console.WriteLine("The Windows Administrator password is: {0}", password);
                    }
                }
            } while (instance.State.Name == "pending" || instance.State.Name == "running");


            // Terminate instance
            Console.WriteLine("Terminate Instances " + instanceId.ToString());
            ec2Client.TerminateInstances(new TerminateInstancesRequest
            {
                InstanceIds = new List<string>() { instanceId }
            });

            // Delete key pair created for sample.
            Console.WriteLine("Delete KeyPair " + newKeyPair.KeyName);
            ec2Client.DeleteKeyPair(new DeleteKeyPairRequest { KeyName = newKeyPair.KeyName });
           
            try
            {
                var s3Client = new AmazonS3Client();
                var listResponse = s3Client.ListObjects(new ListObjectsRequest
                {
                    BucketName = bucketName
                });
                if (listResponse.S3Objects.Count > 0)
                {
                    Console.WriteLine("Found results file {0} in S3 bucket {1}", listResponse.S3Objects[0].Key, bucketName);
                }

                // Delete bucket created for sample.
                AmazonS3Util.DeleteS3BucketWithObjects(s3Client, bucketName);
                Console.WriteLine("Deleted S3 bucket created for sample.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
            }

            // delete DB Cluster
            try
            {
                HttpStatusCode delClusterStatus = DeleteDBClusterRDS(rdsClient, dbClusterIdentifier);
                Console.WriteLine("Delete Cluster Request with Id " + dbClusterIdentifier + " returned " + delClusterStatus.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
            }


            Thread.Sleep(1000);

            Console.WriteLine("Delete Instance Profile created for sample.");
            DeleteInstanceProfile();

            // delete Security Group

            try
            {
                HttpStatusCode delSecGroupStatus = DeleteSecurityGroup(ec2Client, secGroupId);
                Console.WriteLine("Delete SecurityGroup " + secGroupId + " returned " + delSecGroupStatus.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
            }


            Console.WriteLine("Instance terminated, push enter to exit the program");
            Console.Read();

        }


        /// <summary>
        /// CreateSecurityGroup
        /// </summary>
        /// <param name="ref ec2Client"></param>
        /// <param name="secGroupId"></param>
        /// <returns>HttpStatusCode</returns>
        static HttpStatusCode CreateSecurityGroup(AmazonEC2Client ec2Client, ref string secGroupId)
        {
            CreateSecurityGroupRequest securityGroupRequest = new CreateSecurityGroupRequest();
            securityGroupRequest.GroupName = SAMPLE_NAME;
            securityGroupRequest.Description = SAMPLE_LONG_UNIQUE_NAME;
            CreateSecurityGroupResponse secRes = ec2Client.CreateSecurityGroup(securityGroupRequest);
            Console.WriteLine("Created security Group with GroupId " + secRes.GroupId);

            secGroupId = secRes.GroupId;
            Console.WriteLine(secRes.ResponseMetadata);
            return secRes.HttpStatusCode;
        }

        /// <summary>
        /// CreateDBClusterRDS
        /// </summary>
        /// <param name="rdsClient"></param>
        /// <param name="databaseName"></param>
        /// <param name="databaseEngine"></param>
        /// <param name="MasterUsername"></param>
        /// <param name="MasterUserPassword"></param>
        /// <param name="secGroupId"></param>
        /// <param name="ref dbClusterIdentifier"></param>
        /// <returns></returns>
        static Amazon.RDS.Model.DBCluster CreateDBClusterRDS(Amazon.RDS.AmazonRDSClient rdsClient,
            string databaseName,
            string databaseEngine,
            string MasterUsername,
            string MasterUserPassword,
            string secGroupId, ref string dbClusterIdentifier)
        {
            Amazon.RDS.Model.CreateDBClusterRequest createClusterReq = new Amazon.RDS.Model.CreateDBClusterRequest();
            createClusterReq.DatabaseName = databaseName;
            createClusterReq.DBClusterIdentifier = dbClusterIdentifier;
            createClusterReq.Engine = databaseEngine;
            if (!string.IsNullOrEmpty(secGroupId))
            {
                createClusterReq.VpcSecurityGroupIds.Add(secGroupId);
            }
            createClusterReq.MasterUserPassword = MasterUserPassword;
            createClusterReq.MasterUsername = MasterUsername;

            Amazon.RDS.Model.CreateDBClusterResponse createClusterResp = rdsClient.CreateDBCluster(createClusterReq);
            Amazon.RDS.Model.DBCluster createdCluster = createClusterResp.DBCluster;
            dbClusterIdentifier = createdCluster.DBClusterIdentifier;
            return createdCluster;
        }

        /// <summary>
        /// DeleteDBClusterRDS
        /// </summary>
        /// <param name="rdsClient">Amazon.RDS.AmazonRDSClient</param>
        /// <param name="dbClusterIdentifier">Identifier of RDS DatabaseCluster 2 delete</param>
        /// <returns>HttpStatusCode</returns>
        static HttpStatusCode DeleteDBClusterRDS(Amazon.RDS.AmazonRDSClient rdsClient, string dbClusterIdentifier)
        {
            if (!string.IsNullOrEmpty(dbClusterIdentifier))
            {
                throw new ArgumentException("Null or Empty DBClusterIdentifier which is needed for Amazon.RDS.Model.DeleteDBClusterRequest", "string dbClusterIdentifier");
            }
            Console.WriteLine("Deleting DeleteDBClusterRDS with identifier " + dbClusterIdentifier);
            Amazon.RDS.Model.DeleteDBClusterRequest delClusterReq = new Amazon.RDS.Model.DeleteDBClusterRequest();
            delClusterReq.DBClusterIdentifier = dbClusterIdentifier;
            Amazon.RDS.Model.DeleteDBClusterResponse delClusterResp = rdsClient.DeleteDBCluster(delClusterReq);
            return delClusterResp.HttpStatusCode;
        }

        /// <summary>
        /// DeleteSecurityGroup
        /// </summary>
        /// <param name="ec2Client">EC2Client</param>
        /// <param name="securityGroupId">Identifier of SecurityGroup 2 delete</param>
        /// <returns>HttpStatusCode</returns>
        static HttpStatusCode DeleteSecurityGroup(AmazonEC2Client ec2Client, string securityGroupId)
        {
            if (!string.IsNullOrEmpty(securityGroupId))
            {
                throw new ArgumentException("Null or Empty securityGroupId which is needed for Amazon.EC2.Model.DeleteSecurityGroupRequest", "string securityGroupId");
            }
            Console.WriteLine("Deleting SecurityGroup " + securityGroupId);
            DeleteSecurityGroupRequest delSecGroupReq = new DeleteSecurityGroupRequest();
            delSecGroupReq.GroupId = securityGroupId;
            DeleteSecurityGroupResponse delSecGroupResp = ec2Client.DeleteSecurityGroup(delSecGroupReq);
            return delSecGroupResp.HttpStatusCode;
        }

        /// <summary>
        /// Create instance profile & grant EC2 instance requesting S3 bucket
        /// </summary>
        /// <returns></returns>
        static string CreateInstanceProfile()
        {
            var roleName = SAMPLE_NAME;
            var client = new AmazonIdentityManagementServiceClient();
            client.CreateRole(new CreateRoleRequest
            {
                RoleName = roleName,
                AssumeRolePolicyDocument = @"{""Statement"":[{""Principal"":{""Service"":[""ec2.amazonaws.com""]},""Effect"":""Allow"",""Action"":[""sts:AssumeRole""]}]}"
            });

            var statement = new Amazon.Auth.AccessControlPolicy.Statement(
                Amazon.Auth.AccessControlPolicy.Statement.StatementEffect.Allow);
            statement.Actions.Add(S3ActionIdentifiers.AllS3Actions);
            statement.Resources.Add(new Resource("*"));

            var policy = new Policy();
            policy.Statements.Add(statement);

            client.PutRolePolicy(new PutRolePolicyRequest
            {
                RoleName = roleName,
                PolicyName = "S3Access",
                PolicyDocument = policy.ToJson()
            });

            var response = client.CreateInstanceProfile(new CreateInstanceProfileRequest
            {
                InstanceProfileName = roleName
            });

            client.AddRoleToInstanceProfile(new AddRoleToInstanceProfileRequest
            {
                InstanceProfileName = roleName,
                RoleName = roleName
            });

            return response.InstanceProfile.Arn;
        }

        /// <summary>
        /// Delete the instance profile created for the sample.
        /// </summary>
        static void DeleteInstanceProfile()
        {
            var roleName = SAMPLE_NAME;
            var client = new AmazonIdentityManagementServiceClient();

            client.DeleteRolePolicy(new DeleteRolePolicyRequest
            {
                RoleName = roleName,
                PolicyName = "S3Access"
            });

            client.RemoveRoleFromInstanceProfile(new RemoveRoleFromInstanceProfileRequest
            {
                InstanceProfileName = roleName,
                RoleName = roleName
            });

            client.DeleteRole(new DeleteRoleRequest
            {
                RoleName = roleName
            });

            client.DeleteInstanceProfile(new DeleteInstanceProfileRequest
            {
                InstanceProfileName = roleName
            });
        }

        static string EncodeToBase64(string str)
        {
            byte[] toEncodeAsBytes = System.Text.Encoding.UTF8.GetBytes(str);
            string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
            return returnValue;
        }
    }

    /// <summary>
    /// AWSConfigSettings Helper Facade
    /// </summary>
    internal static class AWSConfigSettings
    {      
        const string PROTO = "https://";
        const string DOMAIN = "amazonaws.com"; //amazonaws.com
        const char DOT = '.';

        /// <summary>
        /// PowerShell script for creating S3 bucket and allowing write access to it
        /// </summary>
        internal const string POWERSHELL_S3_BUCKET_SCRIPT =
             "<powershell>\n" +
                "Import-Module \"C:\\Program Files (x86)\\AWS Tools\\PowerShell\\AWSPowerShell\\AWSPowerShell.psd1\"\n" +
                "Set-DefaultAWSRegion {0}\n" +
                "New-Item C:\\Windows\\Temp -type directory\n" +
                "Add-Content -path C:\\Windows\\Temp\\s3-bucket-results.txt -value \"Results from lots of data processing\"\n" +
                "New-S3Bucket -BucketName {1}\n" +
                "Write-S3Object -BucketName {1} -File C:\\Windows\\Temp\\s3-bucket-results.txt -Key results.txt\n" +
                "shutdown.exe /s\n" +
            "</powershell>";
      
        /// <summary>
        /// Gets AWSAppSettings from Configuration
        /// </summary>
        internal static NameValueCollection AWSAppSettings
        {
            get {
                return System.Configuration.ConfigurationManager.AppSettings;
            }
        }

        /// <summary>
        /// Gets value stored at AWSAppSettings[key]
        /// </summary>
        /// <param name="key">key string from KeyValuePair of Configuration AppSettings</param>
        /// <returns>value string</returns>
        internal static string AWSConfigGetKey(string key)
        {
            string awsValue = null;
            foreach (var nextKey in AWSConfigSettings.AWSAppSettings.Keys)
            {
                if (nextKey.ToString() == key)
                {
                    awsValue = AWSConfigSettings.AWSAppSettings.Get(key);
                    if (!string.IsNullOrEmpty(awsValue))
                    {
                        return awsValue;
                    }
                    throw new ConfigurationErrorsException(
                        String.Format("AWSConfigSettings.AWSAppSettings[\"{0}\"] returns null or void Value", key),
                        new NullReferenceException(String.Format("AWSConfigSettings.AWSAppSettings[\"{0}\"] is \'\\0\' || \"\"", key))
                    );
                }
            }

            throw new ConfigurationErrorsException(
                String.Format("AWSConfigSettings.AWSAppSettings[\"{0}\"] contains no key {1} not found inside <configuration>[...]<appSettings>[...]", key, key),
                new NullReferenceException(String.Format("AWSConfigSettings.AWSAppSettings[\"{0}\"] is \'\\0\' (null)", key))
                );
        }

        /// <summary>
        /// Gets AWSProfileName from ConfigSettings
        /// </summary>
        public static string AWSProfileName
        {
            get {
                return AWSConfigSettings.AWSConfigGetKey("AWSProfileName");
            }
        }

        /// <summary>
        /// Gets AWSRegion from ConfigSettings
        /// </summary>
        public static string AWSRegion
        {
            get
            {
                string region = "eu-central-1";
                try
                {
                    region = AWSConfigSettings.AWSConfigGetKey("AWSRegion");
                }
                catch (Exception)
                {
                    region = "ap-southeast-2";
                }
                return region;
            }
        }

        /// <summary>
        /// Gets Amazon.RegionEndpoint from ConfigSettings
        /// </summary>
        public static Amazon.RegionEndpoint AWSRegionEndpoint
        {
            get {
                string compareRegion = AWSConfigSettings.AWSRegion.Replace("_", string.Empty).ToLower();
                foreach (Amazon.RegionEndpoint endpoint in Amazon.RegionEndpoint.EnumerableAllRegions)
                {
                    if ((endpoint.DisplayName.ToLower() == AWSConfigSettings.AWSRegion.Replace("_", string.Empty).ToLower()) ||
                        (endpoint.SystemName.ToLower() == AWSConfigSettings.AWSRegion.Replace("_", string.Empty).ToLower()) ||
                        (endpoint.ToString().ToLower() == AWSConfigSettings.AWSRegion.Replace("_", string.Empty).ToLower()))
                    {
                        return endpoint;
                    }
                }
                return Amazon.RegionEndpoint.EUWest1;
            }
        }

        /// <summary>
        /// Gets AWSServiceUrl from ConfigSettings
        /// </summary>
        public static String AWSServiceUrl
        {
            get {
                string serviceUrl = String.Concat(
                    PROTO.ToString(),
                    AWSConfigSettings.AWSRegion,
                    ((DOMAIN[0] != DOT) ? DOT.ToString() : string.Empty),
                    DOMAIN.ToString()
                    );
                return serviceUrl;
            }
        }

        /// <summary>
        /// Gets AWSServiceUri from ConfigSettings
        /// </summary>
        public static Uri AWSServiceUri
        {
            get {
                return (new Uri(AWSConfigSettings.AWSServiceUrl, UriKind.Absolute));
            }
        }

        /// <summary>
        /// Gets AWSSamplePrefix from Configuration
        /// </summary>
        public static string AWSSamplePrefix
        {
            get
            {
                return AWSConfigSettings.AWSConfigGetKey("AWSSamplePrefix");
            }

        }

        /// <summary>
        /// Gets AWSAccessKey from Configuration
        /// </summary>
        public static string AWSAccessKey
        {
            get {
                return AWSConfigSettings.AWSConfigGetKey("AWSAccessKey");
            }
        }

        /// <summary>
        /// Gets AWSSecretKey from Configuration
        /// </summary>
        public static string AWSSecretKey
        {
            get
            {
                return AWSConfigSettings.AWSConfigGetKey("AWSSecretKey");
            }
        }

    }

}



Ҁ and ү.

2016-04-04

Refugees welcome - the other / dark side of the medal


To welcome refugees is often good for welcomers country, cause refugees mostley wanted to be in a safe place and took every work, so that they could stay there.

But there's a dark side of this "refugee welcome" story too.
Many refugees will keep staying here, even when war will be over in there home countries.
After war in ex-Yugoslavia was over many refugees kept staying here. Only some returned. Economy remained there very weak, cause of missing labor force; Economy never runs again there, as it did in the past bevore war. Population was shrinking:
tradingeconomics.com/kosovo/population

bosnia-and-herzegovina/population
We saw here population shrunk in Serbia, Bosnia and the Kosovo. In Kosova a seperate currency was never introduced, Kosova region got Euro as currency, but without having a central bank, that's official and by law part of €-Zone and with ultra hard €, they had even more economical problems as Serbia with flexible Dinar: https://en.wikipedia.org/wiki/Kosovo_and_the_euro

With EU Program now, we might can recover economy in balkan region.


But in other post war states like Somalia neither economy nor state recovered and Somalia became a "failed state" and a source of terrorism, that continuesley keep destabilizing and weakning his neighbors.

2016-03-30

aws CodeDeploy CodePipeline - 2 Amazon's deployment services


CodeDeploy

Warning: If you use Amazon's CodeDeploy Service outside of the US, e.g. in Ireland, you can't combine that CodeDeployment AWS Service Instance with AWS CodePipeline later, cause Amazon's Code Pipeline is only availible inside the US for now:
https://console.aws.amazon.com/codepipeline/home?region=eu-west-1#

The following sample shows you, how to use CodeDeploy in Ireland. Be free to change the region to Oregon or Virginia, if you want combine it with CodePipeline later.

https://eu-west-1.console.aws.amazon.com/codedeploy/home?region=eu-west-1#/first-run/


Create new Key-Pair in Ireland:
https://eu-west-1.console.aws.amazon.com/ec2/v2/home?region=eu-west-1#KeyPairs:sort=keyName


I choosed a sample Linux Apache Web Application Deployment

This will take a while. don't panic!


For insiders: This wizards runs really only a CloudFormation
https://eu-west-1.console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks?filter=active


We choose here the pre default Sample from S3 please, you will see later, how we change to GitHub





We see here Deployment Configuration


OK, yet we finished the default wizard and are under Deployments
https://eu-west-1.console.aws.amazon.com/codedeploy/home?region=eu-west-1#/deployments

We create now a new Deployment for GitHub repository (instead default S3)
https://eu-west-1.console.aws.amazon.com/codedeploy/home?region=eu-west-1#/deployments/new

OK. I have used my GitHub PlayGround here
https://github.com/heinrichelsigan/AWSCodeDeploy
Feel free to create your own and play!

OK, we create now the new Deployment from GitHub

After creating the new Deployment, we are back at Deployments page in Ireland:
https://eu-west-1.console.aws.amazon.com/codedeploy/home?region=eu-west-1#/deployments




We can look now at e2c instances menu, to see our fresh deployed instances:
https://eu-west-1.console.aws.amazon.com/ec2/v2/home?region=eu-west-1#Instances:sort=instanceId


CodePipeline

As I mentioned at the beginning Amazon's CodePipeline service is at the moment only availible inside the US at two locations:


We create here our Virginia CodePipeLine Demo Sample 
 CodePipeLine Demo Wizard let you choose directly different pre defined source repositories:

I took my GitHub PlayGround


You can choose some pre defined build servers here, if you like to fetch uncompiled code from your repository and build it with a cloud build service.
Attention: Cloud Build is only very beta compared to a full professionell lan build server.
Warning: Take care, that you deliver your source code (maybe with TOP secret database or config keys or some very snakeoiled intelectual property claims on source maybe without clearly license agreement) for build through the net to a blackbox and got a magical yet another black box compiler compiled snakeoils linked build (you will never find out, what secret different snakeoils and serpentoils they mixed to in to build your code, maybe compiled to use highest CPU Power, so that your cloud provider could make business :) out of this blackbox!





Now your Pipeline appears in dashboard (don't type daeshboard, cause then police stands before your flat in the night :)
https://console.aws.amazon.com/codepipeline/home?region=us-east-1#/dashboard



Great Gas Game

This article should help you to understand the great gas game / gambit

Behind this Israel - Grece pipeline stands Israel.
http://www.thetoc.gr/eng/news/article/greece-cyprus--egypt-present-pipeline-plan-to-eu
This pipeline will be canceled, I guess, cause Israel high court canceled the project:
http://www.timesofisrael.com/high-court-torpedoes-massive-gas-deal-in-historic-ruling/





Behind this Qatar - Europe pipeline stands Muslimbrotherhood in Qatar: https://en.wikipedia.org/wiki/Qatar-Turkey_pipeline
Behind this Iranian  - Europe pipeline stands Iranian governement and IRGCs:
https://en.wikipedia.org/wiki/Persian_Pipeline



There is actually no dispute between Iran and Qatar, concerning gas field in the Persian Gulf, On both Iranian and Qatar cards the division of great gas field is equal drawn!
https://en.wikipedia.org/wiki/South_Pars_/_North_Dome_Gas-Condensate_field


I would build all  4 3 pipelines, then everyone has a piece of pie!

Would thou agree?

OK



Who is sitting on the largest gas reserves?




More maps & pictures, that helps you to understand turkish iranian gas gambit