private static void UnmarshallResult(XmlUnmarshallerContext context, CreateStackResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("StackId", targetDepth))
                    {
                        response.StackId = StringUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }



            return;
        }
        /// <summary>
        /// <para> Creates a stack as specified in the template. After the call completes successfully, the stack creation starts. You can check the
        /// status of the stack via the DescribeStacks API. </para> <para><b>NOTE:</b> Currently, the limit for stacks is 20 stacks per account per
        /// region. </para>
        /// </summary>
        ///
        /// <param name="createStackRequest">Container for the necessary parameters to execute the CreateStack service method on
        ///           AmazonCloudFormation.</param>
        ///
        /// <returns>The response from the CreateStack service method, as returned by AmazonCloudFormation.</returns>
        ///
        /// <exception cref="AlreadyExistsException"/>
        /// <exception cref="LimitExceededException"/>
        public CreateStackResponse CreateStack(CreateStackRequest createStackRequest)
        {
            IRequest <CreateStackRequest> request  = new CreateStackRequestMarshaller().Marshall(createStackRequest);
            CreateStackResponse           response = Invoke <CreateStackRequest, CreateStackResponse> (request, this.signer, CreateStackResponseUnmarshaller.GetInstance());

            return(response);
        }
Beispiel #3
0
        static string CreateStack(StackBase stack)
        {
            Console.WriteLine(
                "Creating {0} stack for build {1}",
                stack.StackType,
                stack.Version
                );

            //string template = CreateBuildTemplate(stackName, commit);
            //string outFile = String.Format("debug-{0}-{1}-template.json", stack.StackType, stack.Environment);
            //File.WriteAllText(outFile, template);
            Console.WriteLine("    Creating stack {0}", stack.Name);

            CreateStackResponse response = cloudFormationClient.CreateStackAsync(
                new CreateStackRequest
            {
                OnFailure        = OnFailure.DELETE,
                StackName        = stack.Name,
                Parameters       = stack.Parameters,
                TemplateBody     = stack.GetTemplate(),
                TimeoutInMinutes = 20,
                Tags             = stack.Tags,
            }
                ).Result;

            string stackId = response.StackId;

            Console.WriteLine("Created {0}", stackId);
            return(stackId);
        }
Beispiel #4
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateStackResponse response = new CreateStackResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("CreateStackResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateStackResponse response = new CreateStackResponse();

            context.Read();

            UnmarshallResult(context, response);
            return(response);
        }
Beispiel #6
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);
        }
        public static CreateStackResponse Unmarshall(UnmarshallerContext _ctx)
        {
            CreateStackResponse createStackResponse = new CreateStackResponse();

            createStackResponse.HttpResponse = _ctx.HttpResponse;
            createStackResponse.RequestId    = _ctx.StringValue("CreateStack.RequestId");
            createStackResponse.StackId      = _ctx.StringValue("CreateStack.StackId");

            return(createStackResponse);
        }
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateStackResponse response = new CreateStackResponse();

            context.Read();

            response.CreateStackResult = CreateStackResultUnmarshaller.GetInstance().Unmarshall(context);

            return(response);
        }
Beispiel #9
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateStackResponse response = new CreateStackResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("StackId", targetDepth))
                {
                    response.StackId = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        private static void UnmarshallResult(JsonUnmarshallerContext context, CreateStackResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("StackId", targetDepth))
                {
                    context.Read();
                    response.StackId = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }
Beispiel #11
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateStackResponse response = new CreateStackResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("CreateStackResult", 2))
                    {
                        response.CreateStackResult = CreateStackResultUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }


            return(response);
        }
Beispiel #12
0
        public void TestCreateStackResponse()
        {
            string json = @"{
  ""metadata"": {
    ""guid"": ""b53cfbc1-88ef-4bf5-8279-f85b999f60d8"",
    ""url"": ""/v2/stacks/e29a62e8-55ac-4af6-bfcf-9d8b174f7ceb"",
    ""created_at"": ""2016-09-02T11:52:26Z"",
    ""updated_at"": null
  },
  ""entity"": {
    ""name"": ""example_stack"",
    ""description"": ""Description for the example stack""
  }
}";

            CreateStackResponse obj = Utilities.DeserializeJson <CreateStackResponse>(json);

            Assert.AreEqual("b53cfbc1-88ef-4bf5-8279-f85b999f60d8", TestUtil.ToTestableString(obj.EntityMetadata.Guid), true);
            Assert.AreEqual("/v2/stacks/e29a62e8-55ac-4af6-bfcf-9d8b174f7ceb", TestUtil.ToTestableString(obj.EntityMetadata.Url), true);
            Assert.AreEqual("2016-09-02T11:52:26Z", TestUtil.ToTestableString(obj.EntityMetadata.CreatedAt), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.EntityMetadata.UpdatedAt), true);
            Assert.AreEqual("example_stack", TestUtil.ToTestableString(obj.Name), true);
            Assert.AreEqual("Description for the example stack", TestUtil.ToTestableString(obj.Description), true);
        }
Beispiel #13
0
        static void TestCfStack(EncryptionMaterials encryptionMaterials)
        {
            string bucket_Name  = QSS3BucketName;
            string templateName = QSS3KeyPrefix + TdwUtils.cfClassPathBastion.Replace("tdw_cf_template\\", "");
            string stack_name   = templateName.Replace("-", "");

            stack_name = stack_name.Replace(".template", "");
            //AmazonS3EncryptionClient s3Client = new AmazonS3EncryptionClient(encryptionMaterials);
            AmazonS3Client s3Client = new AmazonS3Client();

            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();
            ValidateTemplateResponse templateResponse = cfClient.ValidateTemplate(new ValidateTemplateRequest()
            {
                TemplateBody = data
            });

            List <string>            capabilities       = templateResponse.Capabilities;
            string                   capabilitiesReason = templateResponse.CapabilitiesReason;
            string                   description        = templateResponse.Description;
            List <TemplateParameter> parameters         = templateResponse.Parameters;

            if (parameters.Any())
            {
                Console.WriteLine("  Parameters:");

                foreach (var p in parameters)
                {
                    Console.WriteLine("    {0} = {1}",
                                      p.ParameterKey, p.Description);
                }
            }

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

            DescribeStacksResponse testForStackDescResp = new DescribeStacksResponse();

            try
            {
                testForStackDescResp = cfClient.DescribeStacks(new DescribeStacksRequest()
                {
                    StackName = stack_name
                });
            }
            catch (Exception ex)
            {
                testForStackDescResp = null;
            }

            if (testForStackDescResp == null)
            {
                List <string> CfCapabilities = new List <string>();
                CfCapabilities.Add("CAPABILITY_IAM");
                CreateStackRequest stackRequest = new CreateStackRequest()
                {
                    StackName = stack_name, TemplateBody = data, Capabilities = CfCapabilities
                };

                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "pDBPassword", ParameterValue = "LiverpoolFC" } );
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "pNotifyEmail", ParameterValue = "*****@*****.**" });
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "pEC2KeyPairBastion", ParameterValue = "BastionSshKvp" });
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "pEC2KeyPair", ParameterValue = "Ec2SshKvp" });
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "pSupportsConfig", ParameterValue = "Yes" });
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "pAvailabilityZoneA", ParameterValue = "eu-west-1a" });
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "pAvailabilityZoneB", ParameterValue = "eu-west-1b" });
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "pVPCTenancy", ParameterValue = "default" });
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "QSS3BucketName", ParameterValue = QSS3BucketName });
                //stackRequest.Parameters.Add(new Parameter() { ParameterKey = "QSS3KeyPrefix", ParameterValue = QSS3KeyPrefix });

                templateResponse = cfClient.ValidateTemplate(new ValidateTemplateRequest()
                {
                    TemplateBody = data
                });
                CreateStackResponse stackResponse = cfClient.CreateStack(stackRequest);
            }

            testForStackDescResp = cfClient.DescribeStacks(new DescribeStacksRequest());

            foreach (var stack in testForStackDescResp.Stacks)
            {
                Console.WriteLine("stack: {0}", stack.StackName);
                Console.WriteLine("  status: {0}", stack.StackStatus);
                Console.WriteLine("  created: {0}", stack.CreationTime);

                var ps = stack.Parameters;

                if (ps.Any())
                {
                    Console.WriteLine("  parameters:");

                    foreach (var p in ps)
                    {
                        Console.WriteLine("    {0} = {1}",
                                          p.ParameterKey, p.ParameterValue);
                    }
                }
            }
        }