{"id":1215,"date":"2018-02-25T20:30:22","date_gmt":"2018-02-25T20:30:22","guid":{"rendered":"http:\/\/wiki.thomasandsofia.com\/?p=1215"},"modified":"2018-03-08T02:43:50","modified_gmt":"2018-03-08T02:43:50","slug":"cloudformation-advanced-topics","status":"publish","type":"post","link":"https:\/\/wiki.thomasandsofia.com\/?p=1215","title":{"rendered":"CloudFormation Advanced Topics"},"content":{"rendered":"<p><a href=\"http:\/\/wiki.thomasandsofia.com\/2018\/02\/18\/cloud-formation-main-menu\/\" rel=\"noopener\">Course Main Menu<\/a><\/p>\n<h2>Section 10 Main Menu<\/h2>\n<ul>\n<li><a href=\"#KnowledgeReview\">Knowledge Review<\/a><\/li>\n<li><a href=\"#UsingtheAWSCLI\">Using the AWS CLI<\/a><\/li>\n<li><a href=\"#TropospherePythontoGenerateCFTemplates\">Troposphere (Python) to Generate CF Templates<\/a><\/li>\n<li><a href=\"#DeletionPolicy\">DeletionPolicy<\/a><\/li>\n<li><a href=\"#CustomResourceswithAWSLambda\">Custom Resources with AWS Lambda<\/a><\/li>\n<li><a href=\"#BestPracticesforCloudFormation\">Best Practices for CloudFormation<\/a><\/li>\n<li><a href=\"#CostEstimateforYourTemplates\">Cost Estimate for Your Templates<\/a><\/li>\n<li><a href=\"#NextSteps\">Next Steps<\/a><\/li>\n<\/ul>\n<p><a name=\"KnowledgeReview\"><\/a><\/p>\n<h2>Knowledge Review<\/h2>\n<p><a href=\"https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8149166?start=0\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8149166?start=0<\/a><\/p>\n<h3>Ready to Use CloudFormation templates from AWS<\/h3>\n<ul>\n<li><a href=\"https:\/\/github.com\/awslabs\/aws-cloudformation-templates\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/awslabs\/aws-cloudformation-templates<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/awslabs\/aws-cloudformation-templates\/blob\/master\/aws\/solutions\/WordPress_Single_Instance.yaml\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/awslabs\/aws-cloudformation-templates\/blob\/master\/aws\/solutions\/WordPress_Single_Instance.yaml<\/a><\/li>\n<li>Easier to download it from here: <a href=\"http:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2018\/02\/WordPress_Single_Instance.yaml_.txt\">WordPress_Single_Instance.yaml<\/a><\/li>\n<\/ul>\n<p><a name=\"UsingtheAWSCLI\"><\/a><\/p>\n<h2>Using the AWS CLI<\/h2>\n<p><a href=\"https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8149190?start=0\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8149190?start=0<\/a><br \/>\n<a href=\"http:\/\/wiki.thomasandsofia.com\/2017\/09\/20\/iam-cli-users-and-roles\/\">More information from AWS Solutions Architect training<\/a><\/p>\n<ul>\n<li>We can use the AWS CLI to create, update or delete CloudFormation templates.<\/li>\n<li>It is convenient when you start automating your deployments<\/li>\n<li>It is also useful for managing parameters in a file.<\/li>\n<\/ul>\n<h3>Installing the AWS Command Line Interface<\/h3>\n<p><a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<h4>Install AWS CLI (Easy way)<\/h4>\n<p><b>Ubuntu<\/b><\/p>\n<pre>sudo apt install -y awscli<\/pre>\n<h4>Install AWS CLI via Python (Hard way)<\/h4>\n<p><b>Ubuntu:<\/b><\/p>\n<pre>sudo apt -y install python3\r\ncurl -O https:\/\/bootstrap.pypa.io\/get-pip.py\r\npython3 get-pip.py --user<\/pre>\n<p>Add the executable path to your PATH variable:<br \/>\nInstall the AWS CLI<\/p>\n<pre>pip install awscli --upgrade --user<\/pre>\n<h4>Create a Profile<\/h4>\n<ul>\n<li>Console &gt; Username &gt; My Security Credentials &gt; [Continue to Security Credentials]<\/li>\n<li>Under &#8220;Your Security Credentials&#8221; &gt; Access keys (access key ID and secret access key) &gt; [Create New Access Key]<\/li>\n<li>[Download Key File] (rootkey.csv)<\/li>\n<li>Configure your profile<\/li>\n<\/ul>\n<pre>aws configure --profile <span style=\"color: #008080;\">profilename<\/span><\/pre>\n<ul>\n<li>Enter the Access Key, Secret Access Key Id and default region as prompted<\/li>\n<\/ul>\n<h4>Create your Parameters.json file<\/h4>\n<p>This file will allow you to pre-populate any parameters required<\/p>\n<pre>[\r\n {\r\n  \"ParameterKey\": \"InstanceType\",\r\n  \"ParameterValue\": \"t2.micro\"\r\n },\r\n {\r\n  \"ParameterKey\": \"KeyName\",\r\n  \"ParameterValue\": \"mykey\"\r\n },\r\n {\r\n  \"ParameterKey\": \"DBPassword\",\r\n  \"ParameterValue\": \"!4U2n0\"\r\n }\r\n]<\/pre>\n<h4>Run your template<\/h4>\n<pre>aws cloudformation create-stack <span style=\"color: #008080;\">StackName<\/span> --template-body file:\/\/<span style=\"color: #008080;\">path\/to\/template.yaml<\/span> --parameters file:\/\/<span style=\"color: #008080;\">my-parameters.json<\/span> --profile <span style=\"color: #008080;\">profilename<\/span> --region <span style=\"color: #008080;\">us-east-2<\/span><\/pre>\n<div class=\"notice\">The C.F. Template and Parameters files should be in the same folder as your command\/execution script.<\/div>\n<p><a name=\"TropospherePythontoGenerateCFTemplates\"><\/a><\/p>\n<h2>Troposphere (Python) to Generate CF Templates<\/h2>\n<p><a href=\"https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8149192?start=0\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8149192?start=0<\/a><\/p>\n<p>Best understood by reading the example: <a href=\"http:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2018\/02\/1-troposphere-example.py_.txt\" target=\"_blank\" rel=\"noopener\">1-troposphere-example.py<\/a><\/p>\n<ul>\n<li>Troposphere allows you to leverage Python to write your CF templates: https:\/\/github.com\/cloudtools\/troposphere<\/li>\n<li>Advantages\n<ul>\n<li>You can start using types in your templates<\/li>\n<li>The generated CloudFormation will be valid<\/li>\n<li>You can dynamically generate CloudFormation (loops, conditions, etc.)<\/li>\n<li>You&#8217;re allowed to have complex conditions to generate exactly what you need.<\/li>\n<\/ul>\n<\/li>\n<li>Disadvantages\n<ul>\n<li>Two step process\n<ul>\n<li>Write Python to generate JSON<\/li>\n<li>Upload JSON<\/li>\n<\/ul>\n<\/li>\n<li>It requires an understanding of Python vs. plain YAML<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>Install Troposphere<\/h4>\n<p>*Requires Pythod, duh!<\/p>\n<pre>pip install troposphere<\/pre>\n<h4>Create the code<\/h4>\n<pre>python <span style=\"color: #008080;\">filename.py<\/span><\/pre>\n<p><a name=\"DeletionPolicy\"><\/a><\/p>\n<h2>DeletionPolicy<\/h2>\n<p><a name=\"CustomResourceswithAWSLambda\"><\/a><\/p>\n<h2>Custom Resources with AWS Lambda<\/h2>\n<p><a name=\"BestPracticesforCloudFormation\"><\/a><\/p>\n<h2>Best Practices for CloudFormation<\/h2>\n<p><a name=\"CostEstimateforYourTemplates\"><\/a><\/p>\n<h2>Cost Estimate for Your Templates<\/h2>\n<p><a name=\"NextSteps\"><\/a><\/p>\n<h2>Next Steps<\/h2>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Course Main Menu Section 10 Main Menu Knowledge Review Using the AWS CLI Troposphere (Python) to Generate CF Templates DeletionPolicy Custom Resources with AWS Lambda Best Practices for CloudFormation Cost Estimate for Your Templates Next Steps Knowledge Review https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8149166?start=0 Ready to Use CloudFormation templates from AWS https:\/\/github.com\/awslabs\/aws-cloudformation-templates https:\/\/github.com\/awslabs\/aws-cloudformation-templates\/blob\/master\/aws\/solutions\/WordPress_Single_Instance.yaml Easier to download it from here: WordPress_Single_Instance.yaml ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/?p=1215\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-1215","post","type-post","status-publish","format-standard","hentry","category-cloudformation"],"_links":{"self":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1215"}],"version-history":[{"count":17,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1215\/revisions"}],"predecessor-version":[{"id":1289,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1215\/revisions\/1289"}],"wp:attachment":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}