예제 #1
0
        public static void DeleteStack(RegionEndpoint awsEndpoint, string stackName)
        {
            var codeDeployClient = new AmazonCodeDeployClient(awsEndpoint);
            var apps             = codeDeployClient.ListApplications().Applications.Where(name => name.StartsWith("HelloWorld"));

            foreach (var app in apps)
            {
                codeDeployClient.DeleteApplication(new DeleteApplicationRequest {
                    ApplicationName = app
                });
            }

            var cloudFormationClient = new AmazonCloudFormationClient(awsEndpoint);

            try
            {
                cloudFormationClient.DeleteStack(new DeleteStackRequest {
                    StackName = stackName
                });
                var testStackStatus = StackStatus.DELETE_IN_PROGRESS;
                while (testStackStatus == StackStatus.DELETE_IN_PROGRESS)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(10));
                    var stacksStatus =
                        cloudFormationClient.DescribeStacks(new DescribeStacksRequest {
                        StackName = stackName
                    });
                    testStackStatus = stacksStatus.Stacks.First(s => s.StackName == stackName).StackStatus;
                }
            }
            catch (AmazonCloudFormationException)
            {
            }
        }
예제 #2
0
        static void TestParentChildTemplates()
        {
            string bucket_Name  = QSS3BucketName;
            string templateName = QSS3KeyPrefix + TdwUtils.cfClassPathParentSubnet.Replace("tdw_cf_template\\", "");
            string stack_name   = templateName.Replace("-", "");

            stack_name = stack_name.Replace(".template", "");
            string dataPath = null;

            byte[]            dataBytes = null;
            PutObjectRequest  request   = null;
            PutObjectResponse response  = null;
            AmazonS3Client    s3Client  = new AmazonS3Client();

            bucket_Name = TdwUtils.CreateBucket(s3Client, QSS3BucketName);

            GetObjectRequest getObjectRequest = new GetObjectRequest
            {
                BucketName = bucket_Name,
                Key        = templateName,
            };

            string data = null;

            using (GetObjectResponse getObjectResponse = s3Client.GetObject(getObjectRequest))
            {
                using (var stream = getObjectResponse.ResponseStream)
                    using (var reader = new StreamReader(stream))
                    {
                        data = reader.ReadToEnd();
                    }
            }

            Amazon.CloudFormation.AmazonCloudFormationClient cfClient = new AmazonCloudFormationClient();

            try
            {
                DeleteStackRequest deleteRequest = new DeleteStackRequest()
                {
                    StackName = stack_name
                };
                cfClient.DeleteStack(deleteRequest);
            }
            catch (Exception ex)
            {
                ex = null;
            }

            List <string> CfCapabilities = new List <string>();

            CfCapabilities.Add("CAPABILITY_IAM");
            CreateStackRequest stackRequest = new CreateStackRequest()
            {
                StackName = stack_name, TemplateBody = data, Capabilities = CfCapabilities
            };
            CreateStackResponse stackResponse = cfClient.CreateStack(stackRequest);
        }