Skip to content

Commit

Permalink
update best practice doc
Browse files Browse the repository at this point in the history
  • Loading branch information
MacHu-GWU committed Jul 9, 2021
1 parent c3ee151 commit 434b78b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ Welcome to ``cottonformation`` Documentation
Getting Help
------------------------------------------------------------------------------

1. The easiest way to learn the best practice is to **learn by example**. You can start from `cottonformation by example <https://cottonformation.readthedocs.io/en/latest/01-cottonformation-by-example/index.html>`_

1. The easiest way to learn the best practice is to **learn by example**. You can start from `cottonformation by example <https://cottonformation.readthedocs.io/en/latest/01-cottonformation-by-example/index.html>`_. Then you can **learn best practice proved in production environment** in `cottonformation best practice <file:///Users/sanhehu/Documents/GitHub/cottonformation-project/docs/build/html/02-cottonformation-best-practice/index.html>`_.

2. Second method is to `submit an GitHub issue <https://github.com/MacHu-GWU/cottonformation-project/issues>`_. So other people may see the discussion and solution too. In addition there's a `cottonformation community <https://gitter.im/cottonformation/community>`_ **on gitter to directly ASK THE AUTHOR**.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,31 @@ Parameterization of the CloudFormation is awesome. Because the nature of CloudFo

.. literalinclude:: ../../../../examples/02-best-practice/e01_ctf_styled_parameter.py
:linenos:

Template json:

.. code-block:: javascript
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Demo: ctf styled parameter",
"Metadata": {
"cottonformation": {
"version": "0.0.3"
}
},
"Resources": {
"MyBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "ctf-styled-param-dev-my-bucket",
"Tags": [
{
"Key": "EnvName",
"Value": "ctf-styled-param-dev"
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. _resource-group:

Resource Group
Organize AWS Object using Resource Group
==============================================================================

When there are many resources in your template, it becomes difficult to manage and debug. You probably want to put resources into different logic "Resource Group", and you want to test them separately, even though in most of the case they depend on each other. For debugging, it is always better to deploy resources gradually rather than deploy all of them at once.
Expand Down
35 changes: 35 additions & 0 deletions examples/02-best-practice/e01_ctf_styled_parameter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

import attr
import cottonformation as ctf
from cottonformation.res import s3


@attr.s
class Param:
project_name: str = attr.ib()
stage: str = attr.ib()

@property
def env_name(self):
return f"{self.project_name}-{self.stage}"


def create_template(param: Param) -> ctf.Template:
tpl = ctf.Template(Description="Demo: ctf styled parameter")

bucket = s3.Bucket("MyBucket", p_BucketName=f"{param.env_name}-my-bucket")
tpl.add(bucket)

tpl.batch_tagging(EnvName=param.env_name)

return tpl


if __name__ == "__main__":
param = Param(
project_name="ctf-styled-param",
stage="dev"
)
tpl = create_template(param)
print(tpl.to_json())

0 comments on commit 434b78b

Please sign in to comment.